Hi, i'm using GWT2.4.0, and while populating a Combobox with data from our database via RPC, i use this datasource:
In the Widget i have:
And finally the DB POJO has:
While, this is suppose to work, as you can see in the image the values are not loading right, it only says [object Object]
Where are using the GenericGwtRpcDataSource as explained in http://forums.smartclient.com/showthread.php?t=10850
Any idea would be welcomed
Code:
@Override
public List<DataSourceField> getDataSourceFields() {
List<DataSourceField> fields = new ArrayList<DataSourceField>();
DataSourceSequenceField idField = new DataSourceSequenceField(ID_FIELD);
idField.setHidden(true);
idField.setPrimaryKey(true);
fields.add(idField);
DataSourceTextField nameField = new DataSourceTextField(ROL_NAME, "Name");
fields.add(nameField);
final DataSourceEnumField permissionList = new DataSourceEnumField(PERMISSIONS, "Permissions");
SelectItem selectItem = new SelectItem();
selectItem.setMultiple(Boolean.TRUE);
selectItem.setMultipleAppearance(MultipleAppearance.PICKLIST);
permissionList.setEditorType(selectItem);
RoleHelperAsync rolesService = (RoleHelperAsync) GWT.create(RoleHelper.class);
rolesService.getPermissionsMap(new AsyncCallback<Map<String, String>>() {
@Override
public void onFailure(Throwable caught) {
SC.say(messages.showException(caught.getMessage()));
}
@Override
public void onSuccess(Map<String, String> result) {
permissionList.setValueMap(result);
}
});
fields.add(permissionList);
}
@Override
public void copyValues(ListGridRecord from, Roles to) {
to.setRolId(from.getAttributeAsInt(ID_FIELD));
to.setRolName(from.getAttributeAsString(ROL_NAME));
to.setPermissionsMap(from.getAttributeAsMap(PERMISSIONS));
}
@Override
public void copyValues(Roles from, ListGridRecord to) {
to.setAttribute(ID_FIELD, from.getRolId());
to.setAttribute(ROL_NAME, from.getRolName());
to.setAttribute(PERMISSIONS, from.getPermissionsMap());
}
Code:
final ListGrid listGrid = new ListGrid();
final DynamicForm editForm = new DynamicForm();
DataSource dataSource = RoleDataSource.getInstance();
IButton btnRemove = new IButton("Remove");
IButton btnAdd = new IButton("Add row");
IButton saveButton = new IButton("Save");
listGrid.setWidth(600);
listGrid.setHeight(300);
listGrid.setDataSource(dataSource);
editForm.setDataSource(dataSource);
listGrid.setSelectionType(SelectionStyle.MULTIPLE);
listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
listGrid.setAutoFetchData(true);
listGrid.fetchData();
listGrid.addRecordClickHandler(new RecordClickHandler() {
@Override
public void onRecordClick(RecordClickEvent event) {
editForm.clearErrors(true);
listGrid.selectRecord(event.getRecord());
editForm.editRecord(event.getRecord());
}
});
//btnRemove ClickHandler
btnRemove.addClickHandler(new ClickHandler() {
@Override
public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
try {
//get the currently selected records
final ListGridRecord[] selectedRecords;
selectedRecords = listGrid.getSelectedRecords();
if (selectedRecords.length > 0) {
SC.ask(messages.confirmDelete(), new BooleanCallback() {
@Override
public void execute(Boolean value) {
if (value != null && value) {
listGrid.removeSelectedData();
SC.say(messages.recordDeleted());
}
}
});
} else {
SC.say(messages.recordNeeded());
}
} catch (Exception ex) {
SC.say(messages.showException(ex.getMessage()));
}
}
});
//newCompanyButton ClickHandler
btnAdd.addClickHandler(new ClickHandler() {
@Override
public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
try {
editForm.editNewRecord();
editForm.focusInItem("rol_name");
} catch (Exception ex) {
SC.say(messages.showException(ex.getMessage()));
}
}
});
//newCompanyButton ClickHandler
saveButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
try {
editForm.saveData();
listGrid.refreshFields();
SC.say(messages.recordUpdated());
} catch (Exception ex) {
SC.say(messages.showException(ex.getMessage()));
}
}
});
VLayout layoutMainRight = new VLayout();
layoutMainRight.addMember(listGrid);
HLayout toolLayout = new HLayout();
VLayout buttonsLayout = new VLayout();
toolLayout.addMember(editForm);
buttonsLayout.addMember(btnRemove);
buttonsLayout.addMember(btnAdd);
buttonsLayout.addMember(saveButton);
toolLayout.addMember(buttonsLayout);
layoutMainRight.addMember(toolLayout);
Code:
public Map<String, String> getPermissionsMap() {
Map<String, String> permMap = new HashMap<String, String>();
for(int i = 0; i < permissionsList.size(); i++) {
permMap.put(permissionsList.get(i).getPerId().toString(), permissionsList.get(i).getPerModule() + " - " + permissionsList.get(i).getPerName());
}
return permMap;
}
public void setPermissionsMap(Map<String, String> permissionsMap) {
if(permissionsList != null) {
permissionsList.clear();
}
for(Map.Entry<String,String> entry : permissionsMap.entrySet()) {
permissionsList.add(new Permissions(new Integer(entry.getKey())));
}
}
Where are using the GenericGwtRpcDataSource as explained in http://forums.smartclient.com/showthread.php?t=10850
Any idea would be welcomed
Comment