Announcement

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

    Add GWT-RPC Datasource to official build

    This is to support justinc proposal to get a "standard" solution for the RPC Datasource. As a matter of fact, in one of the posts, sanjiv asked for this to be posted in the issues at google code so it could be prioritized for inclusion on the official source code.

    I have open issue 303 to that effect http://code.google.com/p/smartgwt/issues/detail?id=303

    Please "star" this issue to help its prioritization.

    Comment


      bug in TestAdvDataSource.zip

      Hello bitblaster. Thanks for your perfect work.
      I find a bug in your code: TestAdvDataSource.zip
      TestDataSource.java

      Code:
      private void copyValues(ListGridRecord from, TestRecord to) {
      to.setId(from.getAttributeAsInt(idField.getName()));
      
      to.setName(from.getAttributeAsString(nameField.getName()));
      
      // TODO: at the moment getAttributeAsDate is not working here,
      // we simply get it as an object and compare its runtime class against java.util.Date (thanks Alius!)
      Object data=from.getAttributeAsObject(dateField.getName());
      if(data instanceof Date)
      	to.setDate((Date) data);
      }
      }
      If you use the DataSource for remove data, this throws an exception...
      This is my code fixed.

      Code:
      protected void copyValues(ListGridRecord from, ObservacionesRecord to) {
      String i = from.getAttributeAsString(idField.getName());
      if(i==null){
      	to.setId(null);
      }else{
      	to.setId(Integer.valueOf(from.getAttributeAsString(idField.getName())));	
      }
      				
      to.setName(from.getAttributeAsString(nameField.getName()));
      
      // TODO: at the moment getAttributeAsDate is not working here,
      // we simply get it as an object and compare its runtime class against java.util.Date (thanks Alius!)
      Object data=from.getAttributeAsObject(dateField.getName());
      if(data instanceof Date)
      	to.setDate((Date) data);
      }
      }
      Thanks.

      Comment


        Examples in smartgwt-extensions latest?

        Originally posted by alius
        Hi Nikolas,

        Thank you.
        Could you please replace SimpleGwtRPCDS.java with the latest one ?

        Latest one has:
        - correction to work with any component (suggestion by Isomorphic)
        - added paging functionality example.

        Aleksandras.
        Is the code in smartgwt-extensions the latest version? I don't see any generics in that code is there a reason it's not used?
        or
        Is it just out of date?

        Thank you for this implementation it works great, just want to make sure I'm current on any changes that have been made or implemented.

        Comment


          Did someone use smart gwt + gwt rpc to manage related data with foreign keys?

          Comment


            I've mapped FK's through the datasource....

            Originally posted by mnenchev
            Did someone use smart gwt + gwt rpc to manage related data with foreign keys?
            I've done this using a ListGrid and a SelectItem, it works quite well.

            The visual supplies the ListGrid and a drop down table with the FK's available for selection.

            Comment


              Hi all,

              I see Sanjiv tagged netname's 303 issue for v2.0, excellent (Thanks for raising this netname, btw).

              Which brings the question, when is 2.0 expected ;)

              Thanks if you know the answer,
              Justin

              Comment


                SmartGWT 2.0 updates?

                Originally posted by justinc
                Hi all,

                I see Sanjiv tagged netname's 303 issue for v2.0, excellent (Thanks for raising this netname, btw).

                Which brings the question, when is 2.0 expected ;)

                Thanks if you know the answer,
                Justin
                Will 2.0 support GWT 2.0 or is it a bug fix and feature release only?

                Thank you,

                Comment


                  Originally posted by gcstang
                  I've done this using a ListGrid and a SelectItem, it works quite well.

                  The visual supplies the ListGrid and a drop down table with the FK's available for selection.
                  Post a snippet of code pls.

                  Comment


                    FK Example

                    Originally posted by mnenchev
                    Post a snippet of code pls.
                    In this example the Datasource is used in a ListGrid.

                    Primary Datasource Code:
                    Code:
                    public class MemberListGridDS extends GWTRPCDataSource<MemberRecord> {
                    
                    	public MemberListGridDS() {
                    		//Replace with actual RPC Service
                    		super(SGWTMemberService.Impl.getInstance());
                    
                    		DataSourceIntegerField intField = new DataSourceIntegerField("mbrid");
                    		intField.setPrimaryKey(true);
                    		intField.setCanEdit(false);
                    		addField(intField);
                    		
                    		intField = new DataSourceIntegerField("websid");
                    		intField.setCanEdit(true);
                    		intField.setEditorType(new WebSelectItem());
                    		intField.setForeignKey("weblgds.websid");
                    		addField(intField);
                    SelectItem Code (This uses another Datasource):
                    Code:
                    public class WebSelectItem extends SelectItem {
                    
                    	public WebSelectItem() {
                    		WebListGridDS ds = new WebListGridDS();
                    		ds.setID("weblgds");
                    		setValueField("websid");
                    		setDisplayField("dsc");
                    		setEmptyPickListMessage("No data in table");
                    		setPickListWidth(450);
                    		
                    		ListGridField websidField = new ListGridField("websid");
                    		ListGridField dscField = new ListGridField("dsc");
                    		setPickListFields(websidField, dscField);
                    		
                    		setOptionDataSource(ds);
                    		setAutoFetchData(true);
                    	}
                    }

                    Comment


                      Originally posted by gcstang
                      In this example the Datasource is used in a ListGrid.

                      Primary Datasource Code:
                      Code:
                      public class MemberListGridDS extends GWTRPCDataSource<MemberRecord> {
                      
                      	public MemberListGridDS() {
                      		//Replace with actual RPC Service
                      		super(SGWTMemberService.Impl.getInstance());
                      
                      		DataSourceIntegerField intField = new DataSourceIntegerField("mbrid");
                      		intField.setPrimaryKey(true);
                      		intField.setCanEdit(false);
                      		addField(intField);
                      		
                      		intField = new DataSourceIntegerField("websid");
                      		intField.setCanEdit(true);
                      		intField.setEditorType(new WebSelectItem());
                      		intField.setForeignKey("weblgds.websid");
                      		addField(intField);
                      SelectItem Code (This uses another Datasource):
                      Code:
                      public class WebSelectItem extends SelectItem {
                      
                      	public WebSelectItem() {
                      		WebListGridDS ds = new WebListGridDS();
                      		ds.setID("weblgds");
                      		setValueField("websid");
                      		setDisplayField("dsc");
                      		setEmptyPickListMessage("No data in table");
                      		setPickListWidth(450);
                      		
                      		ListGridField websidField = new ListGridField("websid");
                      		ListGridField dscField = new ListGridField("dsc");
                      		setPickListFields(websidField, dscField);
                      		
                      		setOptionDataSource(ds);
                      		setAutoFetchData(true);
                      	}
                      }
                      Hi, thanks for the help, it is working with one exception. If i set foreign key intField.setForeignKey("weblgds.websid"); the id is shown, but i want to show the displayValue and map it to the id.

                      Comment


                        SmartGWT Version

                        Originally posted by mnenchev
                        Hi, thanks for the help, it is working with one exception. If i set foreign key intField.setForeignKey("weblgds.websid"); the id is shown, but i want to show the displayValue and map it to the id.
                        What SmartGWT version and GWT version are you using...this only started working with 1.2 SmartGWT it was a bug before that.

                        Comment


                          Originally posted by gcstang
                          What SmartGWT version and GWT version are you using...this only started working with 1.2 SmartGWT it was a bug before that.
                          Hi, I updated my smartgwt jar to version 1.2-SNAPSHOT and my gwt to 1.7.0, but the problem remains.
                          Last edited by mnenchev; 10 Sep 2009, 02:10.

                          Comment


                            Post a sample application ...

                            Originally posted by mnenchev
                            Hi, I updated my smartgwt jar to version 1.2-SNAPSHOT and my gwt to 1.7.0, but the problem remains.
                            Please post your sample application.

                            Comment


                              Originally posted by gcstang
                              Please post your sample application.
                              I do not have deployable sample at the moment but here is the code connected with the problem:
                              I have asset:newsDays one to many relationship
                              Code:
                              //view
                              	
                              		final DynamicForm newsDayForm = new DynamicForm();
                              		newsDayForm.setDataSource(NewsDaysDataSource.getInstance());
                              
                              // newsDaysDS
                              	public NewsDaysDataSource() {
                              		setClientOnly(true);
                              
                              		pk = new DataSourceIntegerField("id", "News Day Id");
                              		pk.setPrimaryKey(true);
                              		pk.setHidden(true);
                              		addField(pk);
                              
                              		assetField = new DataSourceIntegerField("assetId");
                              		assetField.setCanEdit(true);
                              		assetField.setEditorType(new WebSelectItem(AssetJsonDataSource.getInstance()));
                              		assetField.setForeignKey("assetsDS.key");
                              		assetField.setRequired(true);
                              		addField(assetField);
                              		dateField = new DataSourceDateField("date", "Date");
                              		final DateRangeValidator validator = new DateRangeValidator();
                              		validator.setMin(new Date());
                              		dateField.setRequired(true);
                              		dateField.setValidators(validator);
                              		addField(dateField);
                              		intervalField = new DataSourceIntegerField("interval", "Interval");
                              		final IntegerRangeValidator integerValidator = new IntegerRangeValidator();
                              		integerValidator.setMin(0);
                              		intervalField.setValidators(integerValidator);
                              		intervalField.setRequired(true);
                              		addField(intervalField);
                              	}
                              
                              // AssetDS
                              protected DataSourceIntegerField key;
                              	protected DataSourceField value;
                              	
                              	public AssetJsonDataSource() {
                              		key = new DataSourceIntegerField("key");
                              		key.setHidden(true);
                              		key.setPrimaryKey(true);
                              		addField(key);
                              		value = new DataSourceTextField("value");
                              		addField(value);
                              		setClientOnly(true);
                              		this.setID("assetsDS");
                              	}
                              	
                              	@Override
                              	protected void executeAdd(String requestId, DSRequest request, DSResponse response) {
                              		
                              	}
                              
                              	@Override
                              	protected void executeFetch(final String requestId, DSRequest request, final DSResponse response) {
                              		final AssetServiceAsync service = ServiceUtils.getAssetServiceAsync();
                              		service.getAssetsMap(new KeyValueJsonAsyncCallback() {
                              			@Override
                              			public void responseFailure(Throwable e) {
                              				SC.warn("ERROR : " + e.getMessage(), null);
                              				response.setStatus(RPCResponse.STATUS_FAILURE);
                              				processResponse(requestId, response);
                              			}
                              			@Override
                              			public void responseSuccess(Record[] records) {
                              				response.setData(records);
                              				processResponse(requestId, response);				
                              			}
                              
                              		});
                              	}
                              
                              	@Override
                              	protected void executeRemove(String requestId, DSRequest request, DSResponse response) {
                              		// TODO Auto-generated method stub
                              		
                              	}
                              
                              	@Override
                              	protected void executeUpdate(String requestId, DSRequest request, DSResponse response) {
                              		// TODO Auto-generated method stub
                              		
                              	}
                              	
                              	@Override
                              	protected Object getValueOf(String from, String fieldName) {
                              		return null;
                              	}
                              KeyValueJsonAsyncCallback just transforms json key:value to Record
                              My AssetJsonDataSource is tested and working with SelectItems.

                              Comment


                                Reparenting a node in a tree grid using GWT-RPC datasource doesn't work

                                Hello everyone,

                                I am using a GWT-RPC datasource with a tree grid. The problem I have is that reparenting a node doesn't actually move the node to its new location in the tree. It does work when the node is dragged and dropped, though.

                                Here are the details.

                                To reparent the node, I assign the primary key field (ID) of the new parent to the node being moved's foreign key field (PARENT_ID), which, in a tree, points to the parent:

                                [CODE]
                                // New parent
                                ListGridRecord newParent = treeGrid.getSelectedRecord();

                                // Set the record's PARENT_ID attribute equal to the parent ID
                                record.setAttribute(PARENT_ID, newParent.getAttribute(ID));

                                // Update the record
                                treeGrid.updateData(record);
                                [\CODE]

                                This results in a call to my datasource's executeUpdate method, where I call my server-side service and call response.setData, and processResponse with the response:

                                Code:
                                	protected void executeUpdate(final String requestId, final DSRequest request, final DSResponse response) {
                                
                                		// Retrieve record to be updated.
                                		final ListGridRecord record = new ListGridRecord(request.getData());
                                		final GroupDto group = new GroupDto();
                                		copyValues(record, group);
                                
                                		// Ask the server to update the group's properties corresponding to the specified module record.
                                		adminService.updateGroupProperties(group, new AsyncCallback<GroupDto>() {
                                
                                			public void onFailure(Throwable caught) {
                                				// The server returned an error status; inform the module.
                                				response.setStatus(RPCResponse.STATUS_FAILURE);
                                				processResponse(requestId, response);
                                			}
                                
                                			public void onSuccess(GroupDto updatedNode) {
                                				// The group's properties were successfully updated on the server so finish updating the record.
                                				copyValues(updatedNode, record);
                                				ListGridRecord[] responseData = new ListGridRecord[1];
                                				responseData[0] = record;
                                				response.setData(responseData);
                                				processResponse(requestId, response);
                                			}
                                
                                		});
                                	}
                                I can see that the server comes back with the updated record, which has the ID of the new parent. I can also see that the record in the tree is updated and, likewise, has the ID of the parent, however, it stays in its original location, not under the new parent.

                                I verified that executeUpdate(...) is called with the same parameters (i.e., operationType = UPDATE and updated record) when the user drags and drops the node, but, in that case, the node *does* move to its new location under the new parent.

                                Using the Developer Console I found that dragging and dropping passes two extra request parameters to the update operation versus invoking updateData explicitly, namely '_parent_isc_ResultTree_4: Obj{ID:305746317786}' and '_selection_2: false':

                                Code:
                                10:19:37.232:INFO:ResultTree:isc_ResultTree_4 (created by: isc_OID_1):Updating cache: operationType 'update', 1 rows update data:
                                [
                                {__ref: com.smartgwt.client.widgets.tree.TreeNode@10a250a,
                                id: "305829641916",
                                title: "Brasing Meats",
                                parentId: "305833462635",
                                _parent_isc_ResultTree_4: Obj{ID:305746317786},
                                isFolder: undef,
                                _selection_2: false}
                                ]
                                My question is, how should I call treeGrid.updateData(...) to have the node move to its new location, as when dragging and dropping?

                                Thanks so much for your insights.

                                Luis

                                Comment

                                Working...
                                X