Announcement

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

    Dude, if u=you set cansort = false, how can you expect to sort something :)? In order to force server sorting only, always invalidate the cache.

    Originally posted by ynaik
    I was able to obtain the Request.getSortBy() value after commenting the following line

    listGrid.setCanSort(false);

    If I comment it //listGrid.setCanSort(false); ,
    then I get the column value using Request.getSortBy() & both the client & server side sorting are enabled.

    When i uncomment it then Request.getSortBy() is always null & unable to do server side sorting.

    How can i disable client side sorting & retain just the server side sorting ?

    Thanks in advance.

    Comment


      Originally posted by mnenchev
      Dude, if u=you set cansort = false, how can you expect to sort something :)? In order to force server sorting only, always invalidate the cache.

      1) is it possible to disable the Client Side Sorting (Right click on Column Header, I don;t want see Sortng options)

      2) is it possible to add custom Filter builder option on right click of Column Header ? The default options are Sort Asc,Sort Desc ,Columns,Group By & Freeze Id.

      Comment


        Did the HeaderClickEvent work? The event doesn't seem to invoke the handler code, in my case. My grid is not bound to a datasource. I am populating the values through setData() method, another approach for pagination grid. I am struck in Sorting behavior. Can someone help.


        Originally posted by ynaik
        Thanks a lot mnenchev for your prompt reply ,

        Do I have invalidateCache on HeaderClickEvent

        listGrid.addHeaderClickHandler(new HeaderClickHandler() {

        public void onHeaderClick(HeaderClickEvent event) {

        listGrid.invalidateCache();
        listGrid.setSortField(event.getFieldNum());

        }
        });

        How can i set the Request.getSortBy() value in executeFetch Method ? Please Help

        Comment


          Originally posted by katrays
          Did the HeaderClickEvent work? The event doesn't seem to invoke the handler code, in my case. My grid is not bound to a datasource. I am populating the values through setData() method, another approach for pagination grid. I am struck in Sorting behavior. Can someone help.
          Yes, HeaderClickEvent worked for me.


          listGrid.addHeaderClickHandler(new HeaderClickHandler() {

          public void onHeaderClick(HeaderClickEvent event) {

          listGrid.invalidateCache();
          listGrid.setSortField(event.getFieldNum());




          }
          });

          Comment


            Generic version

            Regarding the Generic based implementation from page 7, this seem to work in hosted mode, but when you do a GWT compile I get this error:

            [ERROR] Line 57: Only class literals may be used as arguments to GWT.create()
            [ERROR] Cannot proceed due to previous errors


            Where line 57 is this:

            service = (GenericDataServiceAsync<M>) GWT.create(serviceClass);

            This seems like a legit error and it's known to be a quirk between hosted mode and the actual compile. At compile time, the GWT.create() needs to know the specific class.

            This is still happening with GWT 1.7, but this has been known for a couple years it seems.

            Here are the changes I made to make it work in hosted mode AND during a GWT compile:


            Changes to SmartGWTDataSource.class
            Code:
            ...
            private GenericDataServiceAsync<M> service;
            
            ...
            public SmartGWTDataSource(HasSmartGWTResources<M> bridge,
            			GenericDataServiceAsync<M> serviceInstance) {
            		super();
            		GWT.log("Beginning DS init", null);
            		setDataProtocol(DSProtocol.CLIENTCUSTOM);
            		setDataFormat(DSDataFormat.CUSTOM);
            		setClientOnly(false);
            		this.resource = bridge;
            		service = serviceInstance;
            		GWT.log("Adding fields", null);
            		for (DataSourceField field : bridge.getDataSourceFields()) {
            			GWT.log("adding field " + field.getName(), null);
            			addField(field);
            		}
            		GWT.log("SmartGWTDataSource() initialized.", null);
            	}

            Changes to how it's instantiated:

            Code:
            ....
            		Canvas canvas = new Canvas();
            
            		SmartGWTDataSource<Database, DatabaseBridge, DatabaseService> theDatasource = new SmartGWTDataSource<Database, DatabaseBridge, DatabaseService>(
            				DatabaseBridge.Util.getInstance(), DatabaseServiceAsync.Util.getInstance());
            ....
            Where DatabaseServiceAsync is something like this:

            Code:
            public interface DatabaseServiceAsync extends GenericDataServiceAsync<Database> {
            	public static class Util {
            		private static DatabaseServiceAsync instance;
            
            		public static DatabaseServiceAsync getInstance() {
            			if (instance == null) {
            				instance = GWT.create(DatabaseService.class);
            			}
            			return instance;
            		}
            	}
            }
            Last edited by Phy6; 28 Jul 2009, 12:03.

            Comment


              ListGrid validation error message not displayed (via DSResponse)

              Hi

              Isomorphic told me to post my query in this thread, so here it:

              When a validation error occurs from my (GWT) server, I do the following (as an example):

              <code>
              final Map<String, String> fieldErrors = new HashMap<String, String>();
              fieldErrors.put("name", "This should be my error message");
              final DSResponse response = new DSResponse();
              response.setAttribute("clientContext", request.getAttributeAsObject("clientContext"));
              response.setStatus(DSResponse.STATUS_VALIDATION_ERROR);
              response.setErrors(fieldErrors);
              processResponse(request.getRequestId(), response);
              </code>

              This works with a DynamicForm i.e. the field "name" gets an error icon and you can hover over it and the message is shown. However when using a ListGrid the error message shown against the column (named 'name' and which gets an error icon) is always "undefined" !!! Why? If I explicitely use ListGrid.setFieldError(row, "name", "This should be my error message") the ListGrid displays the right message! It seems that DSResponse does not hand back the error message to the ListGrid (but it does to the DynamicForm)!

              Can you help. Many thanks

              Comment


                Hi,

                Same DataSource works well for DynamicForm but does not work for ListGrid - is it correct?

                If yes - I would guess that DataSource still passes error list but ListGrid dos not pick up it (maybe it uses different format for error messages? - just a guess).


                Another guess - in addition to your code try to pass back the same data which you were trying to update :
                Code:
                response.setData (request.getData ());
                Alius

                Comment


                  Thanks Alius but your trick did not work. By the way it should have read:

                  <code>
                  response.setData(Record.convertToRecordArray(request.getData()));
                  </code>

                  I must not be the only one, is it? Everything works well with DynamicForms but not with ListGrid. Am I the only one to use GwtRpcDataSource with a ListGrid and returning validation errors? The doc specifies to format the errors as a map "where each property name is a field name from the record and each property value is an error message to be shown to the user". That's what I do. Why would a ListGrid be different than a DynamicForm? The code in my DataSource I use is the same regardless of the ui being a DynamicForm or a ListGrid.
                  Moreover I cannot figure out where this "undefined" text is coming from. I've 'grep'ed the source code of SmartClient and I cannot find this text! It's not coming from my code either.
                  As a note I'm using SmartGWT 1.1

                  Comment


                    Ok I've read more source code and found a problem in ListGrid.parseServerErrors() function.

                    <code>
                    for (var fieldName in errors) {
                    var fieldErrors = errors[fieldName];
                    if (isc.isAn.Array(fieldErrors)) {
                    for (var i = 0; i < fieldErrors.length; i++) {
                    fieldErrors[i] = fieldErrors[i].errorMessage;
                    }
                    } else {
                    errors[fieldName] = [fieldErrors.errorMessage];
                    }
                    }
                    </code>

                    My error message is a string and does not have "errorMessage" attributes!!!

                    Comment


                      Ok I've cracked that one. Here is the "untidy" solution.

                      <code>
                      final Record error = new Record();
                      error.setAttribute("errorMessage", "Toto was here");
                      JavaScriptObject valueJS = JSOHelper.createObject();
                      JSOHelper.setAttribute(valueJS, "name", error.getJsObj());
                      final DSResponse response = new DSResponse();
                      response.setAttribute("clientContext", request.getAttributeAsObject("clientContext"));
                      response.setStatus(DSResponse.STATUS_VALIDATION_ERROR);
                      response.setErrors(valueJS);
                      processResponse(request.getRequestId(), response);
                      </code>

                      Need now to test this solution with DynamicForms

                      Comment


                        For those interested, this solution also works with DynamicForm!

                        I thus conclude that the documentation should read: when passing validation errors you should give a map of records where each record has an attribute "errorMessage" which value is your actual error message.

                        Comment


                          I'm messing around with a datasource using generics and a generator to auto-create record objects for my ValueObjects. That way i can bind a rpc Ifc to a datasource without any further mapping stuff.

                          It works so far except the criteria...
                          Did anyone use the code posted here with smartgwt 1.1?

                          because the code
                          Code:
                          JavaScriptObject jsObj = request.getData();
                          String[] properties = JSOHelper.getProperties(jsObj);
                          if (properties != null && properties.length > 0) {
                          ...
                          does not work, getData is always null.
                          Also, there is a Method getCriteria
                          Code:
                          Criteria crit = request.getCriteria();
                          
                          			Map critMap = crit.getValues();
                          			for (Object key : critMap.keySet()) {
                          				Object val = critMap.get(key);
                          				System.out.println("Criteria key " + key + " with value " + val);
                          			}
                          it actually puts out fieldname=filtertext for a simple criteria, don't know what's inside for a advanced one

                          I'll post a sample as soon as it's working

                          Comment


                            Client Date Validation

                            Has anyone managed to get client side Date formatting to work, on a databound DynamicForm, with GWT-RPC?

                            When using setUseTextField(true), the date doesn't get formatted as 01/03/2005 but rather as Tue Mar 01 00:00:00 GMT 2005. When Save is clicked, this field then fails validation.

                            I'd like for the Date field to always display in DD/MM/YYYY format, not just during editing.

                            The rest of the code is using the GwtRpcDataSource code from this thread.

                            This is the override on the form:

                            Code:
                                    // Override date field
                                    DateItem openedItem = new DateItem();
                                    openedItem.setName("accountOpened");
                                    openedItem.setTitle("Account Opened");
                                    openedItem.setUseTextField(true);
                                    openedItem.setDisplayFormat(DateDisplayFormat.TOEUROPEANSHORTDATE);
                                    openedItem.setInputFormat("DMY");
                                    boundForm.setFields(openedItem);
                            This is the field in the data source:

                            Code:
                            	dateField = new DataSourceDateField("accountOpened", "Account Opened");
                            	dateField.setRequired(false);
                            	dateField.setCanSave(false);
                            		
                            	addField(dateField);
                            Thanks

                            EDIT: I have also tried using DateUtil methods but to no avail.
                            Last edited by napalmDaz; 31 Jul 2009, 02:46.

                            Comment


                              Help adapting GwtRpcDataSource for TreeNode

                              I'm having a hard time making GwtRpcDataSource work with TreeNode. ATM I'd just like to fetch, but I can't figure out how
                              to set the primaryKey and foreign key. Currently, my data comes back as two nodes at the same level, but both nodes reference
                              the two original nodes, so nodes unfold recursively.

                              An example using static data looks like this:
                              Code:
                              public class MMCClient implements EntryPoint {
                              	private ServiceNodesTreeGrid serviceNodesCanvas;
                              	
                              	public void onModuleLoad() {
                                      VLayout containerLayout = new VLayout();
                                      HLayout topPane = new HLayout();        
                                      serviceNodesCanvas = new ServiceNodesTreeGrid();
                                      topPane.addMember(serviceNodesCanvas);
                              		containerLayout.addMember(topPane);
                              		RootPanel.get("mmcclient").add(containerLayout);
                              }
                              	
                              public class ServiceNodesServiceImpl 
                              		extends RemoteServiceServlet 
                              		implements ServiceNodesService, Serializable, IsSerializable {
                              	static List<ServiceNodeRecord> staticList = new ArrayList<ServiceNodeRecord>();
                              	static ServiceNodeRecord record = null;		
                              	// load static data for testing
                              	static {	
                              		record = new ServiceNodeRecord();
                              		record.setConnectsTo("0");
                              		record.setNodeId("1");
                              		record.setInstitutionId("220");
                              		record.setServiceName("hub-dev");
                              		record.setNodeType("HUB");
                              
                              		staticList.add(record);
                              
                              		record = new ServiceNodeRecord();		
                              		
                              		record.setConnectsTo("1");		
                              		record.setNodeId("6");
                              		record.setInstitutionId("220");
                              		record.setServiceName("mmc");
                              		record.setNodeType("MMC");	
                              				
                              	}
                              	
                              	public List<ServiceNodeRecord> fetch() {
                              		return staticList;		
                              	}
                              }
                              
                              public class ServiceNodeDataSource
                                  extends GwtRpcDataSource {
                              
                                  public ServiceNodeDataSource () {
                                      DataSourceField field;
                              
                                      field = new DataSourceIntegerField ("nodeId", "nodeId");
                              //        field.setPrimaryKey (true);  	
                                      field.setRequired (true);		
                                      addField (field);
                              
                                      field = new DataSourceTextField ("institutionId", "Id");        
                                      field.setRequired (true);		
                                      addField (field);
                              
                                      field = new DataSourceTextField ("connectsTo", "Connects");
                              //        field.setForeignKey("connectsTo"); 
                                      field.setRequired (true);		
                                      addField (field);
                                      
                                      field = new DataSourceTextField ("serviceName", "Service");
                                      field.setRequired (true);
                                      addField (field);
                                              
                                      field = new DataSourceTextField ("nodeType", "Type");
                                      field.setRequired (true);
                                      addField (field);
                                      
                                  @Override
                                  protected void executeFetch (final String requestId, final DSRequest request, final DSResponse response) {
                                  	SC.logWarn ("in executeFetch");
                                  	
                                      ServiceNodesServiceAsync service = GWT.create (ServiceNodesService.class);
                                      service.fetch (new AsyncCallback<List<ServiceNodeRecord>> () {
                                          public void onFailure (Throwable caught) {
                                              response.setStatus (RPCResponse.STATUS_FAILURE);
                                              processResponse (requestId, response);
                                          }
                                          public void onSuccess (List<ServiceNodeRecord> result) {            	
                                              TreeNode[] list = new TreeNode[result.size ()];
                                              for (int i = 0; i < list.length; i++) {
                                              	TreeNode record = new TreeNode();
                                                  copyValues (result.get (i), record);
                                                  list[i] = record;
                                              }
                                              
                                              response.setData (list);
                                              processResponse (requestId, response);
                                          }
                                      });
                                  }        
                                  
                                      // fetch from, to
                                  private static void copyValues (ServiceNodeRecord from, TreeNode to) {
                                  	to.setParentID(from.getNodeId());
                                  	System.out.println("setParentID = " + from.getNodeId());
                                  	
                                      to.setAttribute("nodeId", from.getNodeId());        
                                      to.setAttribute("connectsTo", from.getConnectsTo());
                                      to.setAttribute("serviceName", from.getServiceName ());
                                      to.setAttribute("institutionId", from.getInstitutionId ());
                                      to.setAttribute("nodeType", from.getNodeType());
                                  }
                               }
                               
                               public class ServiceNodesTreeGrid extends TreeGrid {
                              	public ServiceNodesTreeGrid() {
                              		TreeGridField institutionId = new TreeGridField("institutionId", "Node");	
                                      TreeGridField serviceNameField = new TreeGridField("serviceName", "Service");
                                      TreeGridField nodeTypeField = new TreeGridField("nodeType", "Type");
                                              
                                      setFields(institutionId, serviceNameField, nodeTypeField);
                              
                                      ServiceNodeDataSource dataSource = new ServiceNodeDataSource();
                                      setDataSource(dataSource);
                                      this.invalidateCache();
                                      this.fetchData();        
                              	}
                              }
                              
                              public class ServiceNodeRecord 
                              	implements Serializable { 
                              
                              	private static final long serialVersionUID = 1L;
                              	private String nodeId;	
                              	private String serviceName;
                              	private String institutionCode;
                              	private String nodeType;
                              	private String connectsTo;
                              
                              	public String getNodeId() {
                              		return nodeId;
                              	}
                              	public void setNodeId(String nodeId) {
                              		this.nodeId = nodeId;
                              	}
                              	public String getConnectsTo() {
                              		return connectsTo;
                              	}
                              	public void setConnectsTo(String connectsTo) {
                              		this.connectsTo = connectsTo;
                              	}	
                              	public String getNodeType() {
                              		return nodeType;
                              	}
                              	public void setNodeType(String nodeType) {
                              		this.nodeType = nodeType;
                              	}
                              	public String getServiceName() {
                              		return serviceName;
                              	}
                              	public void setServiceName(String serviceName) {
                              		this.serviceName = serviceName;
                              	}	
                              	public String getInstitutionId() {
                              		return institutionId;
                              	}
                              	public void setInstitutionId(String institutionId) {
                              		this.institutionId = institutionId;
                              	}
                              }

                              Comment


                                Definitive working example?

                                Hi,

                                I wonder if anyone can post a definitive working example of the RPC pattern, that embodies pagination and lanceweber's abstraction using generics?

                                Just to have a centralised location for it, because there's a few versions on this thread, and if someone new picked up the wrong one, they'd just be encountering fixed issues. Maybe even on google code perhaps?

                                Plus I don't think we did see the full genericised version, I would love to see that, so this is also to bump that idea.

                                Thanks!

                                Comment

                                Working...
                                X