Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Using DynamicForm with a RestDatasource results in 404

    I have the following DynamicForm which I am using as a login screen.

    Code:
    	public class LoginForm extends DynamicForm {
    
    		public LoginForm() {
    			TextItem user = new TextItem("name", "Username");
    			PasswordItem password = new PasswordItem("password", "Password");
    			SubmitItem submit = new SubmitItem("login", "Login");	
    			
    			
    			setFields(user, password, submit);
    			setDataSource(UserDatasource.getInstance());
    			
    			setSaveOnEnter(false);
    			setCanSubmit(false);		
    		}
    		
    		@Override
    		public void saveData() {
    			Criteria criteria = new Criteria();
    			criteria.addCriteria("name", getValueAsString("name"));
    			criteria.addCriteria("password", getValueAsString("password"));
                            //this json is static data for test purpose
    			((RestDataSource) getDataSource()).setFetchDataURL("webtools/data/login.data.json");
    			((RestDataSource) getDataSource()).fetchData(criteria, new DSCallback() {
    				
    				@Override
    				public void execute(DSResponse response, Object rawData, DSRequest request) {
                                         // do something 
    					
    				}
    			});
    		}
    	}
    Here is the datasource
    Code:
    public class UserDatasource extends RestDataSource {
        private static UserDatasource instance = null;
        public static UserDatasource getInstance() {
            if (instance == null) {
                instance = new UserDatasource("usersDS");
            }
            return instance;
        }
    
        public UserDatasource(String id) {
            setID(id);
            setDataFormat(DSDataFormat.JSON); 
            setTitleField("name");
            setDataProtocol(DSProtocol.POSTPARAMS);
            setCacheAllData(false);
            
             //several fields are defined and added
             
        }
        
    }
    And here is the sample json

    Code:
     {    
        response:{
        status:0,
        startRow:0,
        endRow:1,
        totalRows:1,
        data:[
           {
            userId: 999,
            name: "admin",
            password: "admin",
            reportsTo: 1,
            role: "System Administrator",
            phone: "900000000000"
           }
          ]
        }
     }
    When I click the submit button on the form, I see this in FF
    http://127.0.0.1:8888/webtools/sc/IDACall "404 Not Found"

    On the GWT console I see an error
    [ERROR] [webtools] - 12:25:11.912:XRP0:WARN:RPCManager:Server returned TRANSPORT_ERROR with no error message., response: {status: -90,
    data: Obj,
    httpResponseCode: 404,
    transactionNum: 1,
    clientContext: Obj,
    context: Obj,
    startRow: 0,
    endRow: 0,
    totalRows: 0}

    #2
    I don't think I can override DynamicForm.saveData().

    In Firebug, I see that the operationType is "ADD" which means my code isn't executed at all where I had explicitly added the "fetch" operation.

    The question is how do I use a DynamicForm for a query i.e. under what circumstances is DynamicForm.fetchData() called when I have added a SubmitItem to it.

    Comment


      #3
      I don't think you should call fetch data during save. You should call save on DynamicForm and if protocol is set for datasource this will cause a request with proper json message with values from dynamic form fields. In return you have to send proper answer with added record (answer which is proper for rest data source protocol)

      Comment

      Working...
      X