Announcement

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

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

    Leave a comment:


  • gcstang
    replied
    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.

    Leave a comment:


  • kant003
    replied
    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.

    Leave a comment:


  • netname
    replied
    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.

    Leave a comment:


  • justinc
    replied
    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!

    Leave a comment:


  • ddumaresq
    replied
    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;
    	}
    }

    Leave a comment:


  • napalmDaz
    replied
    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.

    Leave a comment:


  • farmer
    replied
    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

    Leave a comment:


  • nabla52
    replied
    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.

    Leave a comment:


  • nabla52
    replied
    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

    Leave a comment:


  • nabla52
    replied
    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!!!

    Leave a comment:


  • nabla52
    replied
    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

    Leave a comment:


  • alius
    replied
    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

    Leave a comment:


  • nabla52
    replied
    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

    Leave a comment:


  • Phy6
    replied
    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.

    Leave a comment:

Working...
X