Announcement

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

    Multiple field problem in ListGrid and DynamicForm - ManyToMany relation

    Hi,
    I'm using the SmartGWT version 2.4.

    I have this situation:

    There is a relation between to entities, Issue and User (the user are the watchers of the issues, like in the RedMine traker).

    In the client side I have a ListGrid to show all the issues with their fields. Also I have a DynamicForm to edit the Issues there. An issue can have several watchers, so for the field watchers is multiple=true and it is displayed as a MultiPickList in the form.

    The problem is that when I create/update a new issue I lose the watchers selected from the picklist and only gets the first one. Also in the ListGrid, the column "Watchers" only show one value. The data is stored in the DB, I mean all the watchers selected are stored, but It seems like only the first can gets to the UI in the listgrid or the form.

    The summary of the relevant code is:

    User.java
    Code:
    public class User  {
    
    	private Long id;
    	private String name;
    
    }
    Issue.java
    Code:
    public class Issue {
    
    	private Long id;
    	private String name;
    
    	@ManyToMany
    	private Set<User> watchers;
    
    }
    Fields of UserDS.java
    Code:
    		DataSourceIntegerField idField = new DataSourceIntegerField("id", "Id", 128, true);
    		idField.setHidden(true);
    		idField.setPrimaryKey(true);
    
    		DataSourceTextField nameField = new DataSourceTextField("name", "Name", 128, true);
    Fields of IssueDS.java
    Code:
    		DataSourceIntegerField idField = new DataSourceIntegerField("id", "Id", 128, true);
    		idField.setHidden(true);
    		idField.setPrimaryKey(true);
    
    		DataSourceTextField nameField = new DataSourceTextField("name", "Name", 128, true);
    
    		DataSourceTextField watchersIdField = new DataSourceTextField("watchersId", "Watchers ID");
    		watchersIdField.setForeignKey("UserDS.id");
    		watchersIdField.setMultiple(true);
    		watchersIdField.setValueXPath("watchers/user/id");
    		
    		DataSourceTextField watchersNameField = new DataSourceTextField("watchersName", "Watchers Name Hidden");
    		watchersNameField.setMultiple(true);
    		watchersNameField.setHidden(true);
    		watchersNameField.setValueXPath("watchers/user/name");
    Relevant ListGrid code:
    Code:
            grid = new IssueListGrid();  
            grid.setDataSource(IssueDS.getInstance());  
            grid.setAutoFetchData(true);
    
    // Redefine the watchers id field of the grid in order to use displayField and valueField
    ListGridField watchersGriField = new ListGridField("watchersId", "Watchers");
            watchersGriField.setDisplayField("watchersName");
            watchersGriField.setValueField("watchersId");
            
            grid.setFields(watchersGriField);
    Relevant DynamicForm code:
    Code:
            form = new DynamicForm(); 
            form.setDataSource(IssueDS.getInstance());
            form.setUseAllDataSourceFields(true);
    
    		SelectItem watchersSelectItem = new SelectItem("watchersId", "Seguidores");
    		watchersSelectItem.setOptionDataSource(UserDS.getInstance());
    		watchersSelectItem.setMultiple(true);
    		watchersSelectItem.setShowOptionsFromDataSource(true);
    		watchersSelectItem.setDisplayField("name");
    		watchersSelectItem.setValueField("id");
    
    
    
    form.setFields(watchersSelectItem);
    I guess that there is some problem in the way that I'm creating the my DataSources. Let me know if you need more info. I hope you can help me.

    Thanks,
    Viko
Working...
X