Announcement

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

    DynamicForm and RestDataSource

    Version of smartgwt: 2.4
    Browser : Firefox 3.6
    Hi, I have litle problem with integration of DynamicForm to server side.
    I try to implement my own implementation of RestDataSource, but when I submit my form, empty message(without data) is sent to server. Can I ask how to bind DynamicForm to datasource(generate full DSMessage)?

    My implementation of RestDataSource :
    Code:
    public class ContactDS extends RestDataSource {
    
    	public ContactDS() {
    setID("MessageDS");
    DataSourceTextField idField = new DataSourceTextField("contactId");
    idField.setPrimaryKey(true);
    idField.setCanEdit(false);
    DataSourceTextField firstNameField = new DataSourceTextField("name");
    DataSourceTextField lastNameField = new DataSourceTextField("surname");
    DataSourceTextField emailField = new DataSourceTextField("emailAdress"); DataSourceTextField telephoneNumberField = new DataSourceTextField("telephoneNumber");
    setFields(idField,firstNameField, lastNameField, emailField, telephoneNumberField);
            
            OperationBinding fetch = new OperationBinding();
            fetch.setOperationType(DSOperationType.FETCH);
            fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
            OperationBinding add = new OperationBinding();
            add.setOperationType(DSOperationType.ADD);
            add.setDataProtocol(DSProtocol.POSTMESSAGE);
            add.setDataFormat(DSDataFormat.XML);
            OperationBinding update = new OperationBinding();
            update.setOperationType(DSOperationType.UPDATE);
            update.setDataProtocol(DSProtocol.POSTMESSAGE);
            OperationBinding remove = new OperationBinding();
            remove.setOperationType(DSOperationType.REMOVE);
            remove.setDataProtocol(DSProtocol.POSTMESSAGE);
            setOperationBindings(add, fetch, update, remove);
            this.setDataFormat(DSDataFormat.XML);   
            setFetchDataURL("http://localhost:8888/rest/contacts/read");
            setAddDataURL("http://localhost:8888/rest/contacts/add");
            setUpdateDataURL("http://localhost:8888/rest/contacts/update");
            setRemoveDataURL("http://localhost:8888/rest/contacts/remove");
    	}
    }
    My UI:
    Code:
    public class HellerDynamicFormPane extends VLayout{
    
    	TextItem name;
    	TextItem surname;
    	TextItem telephoneNumber;
    	TextItem emailAdress;
    	DynamicForm form;
    	ContactDS contactDS;
    	
    	public HellerDynamicFormPane() {
    		super();
    		this.initLayout();
    		this.setWidth("50%");
    		this.setHeight("50%");
    	}
    	
    	public void initLayout() {
    		//this.setAutoHeight();
    		HeaderItem headerItem = new HeaderItem();
    		headerItem.setDefaultValue("New Contact form");
    		
    		form = new DynamicForm();
    		form.setWidth(400);
    		
    		this.name = new TextItem();
    		name.setName("name");
    		name.setTitle("Username");
    	
    		this.surname = new TextItem();
    		surname.setName("surname");
    		surname.setTitle("Surname");
    		
    		this.telephoneNumber = new TextItem();
    		telephoneNumber.setName("telephoneNumber");
    		telephoneNumber.setTitle("Telephone Number");
    		
    		this.emailAdress = new TextItem();
    		emailAdress.setName("emailAdress");
    		emailAdress.setTitle("Email Adress");
    		
    		final ButtonItem buttonItem = new ButtonItem();  
    		buttonItem.setTitle("Ok"); 
    
    		buttonItem.addClickHandler(new ClickHandler() {  
    		    
    			@Override
    public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
    			form.saveData();
    			}  
    		});  
    		
    		form.setDataSource(new ContactDS());
    		form.setFields(headerItem, name, surname, telephoneNumber,     emailAdress, buttonItem);
    		this.addMember(form);
    		//this.draw();
    	}
    }
    Thanks for help.

    #2
    DSProtocol.POSTMESSAGE means that the content is posted as content, not parameters, like this:
    Code:
    { "dataSource":"AT", "operationType":"add", "componentId":"isc_ValuesManager_5", "data":{ "type":"CONTAINER", "position":0, "parentId":null, "title":"test", "enumMap":{ }, "attributes":[ ] }, "oldValues":{ } }

    Use firebug and/or developer console to doublecheck what's going on when the request is fired. If you expect the parameters to be directly in the request, use DSProtocol.POSTPARAMS instead.

    regards,
    Andrius J.

    Comment

    Working...
    X