Hey together,
sorry to bother you, but I am kind of new to all this and a bit confused. I do not know how to get my modified DataSource and its records (those which were modified) to send them back to my server via GWT-RPC.
I managed to receive data via GWT-RPC. This works fine. I realized it using this thread: http://forums.smartclient.com/showthread.php?t=3538
I used this Master Detail example (http://www.smartclient.com/smartgwt/..._master_detail) and show my received data in the grid. A click on a record shows the data in the form.
Now, what steps do I have to take if the user has modified the data in the form and hits the Save button? How to I get my modified DataSource and its records? I put notes in the code below to show where I am stuck.
This is my class PersonPanel (its like the Master Detail example):
My class PersonDS which extends DataSource
My class PersonLGR which extend ListGridRecord
Thanks in advance for your help.
Syd
sorry to bother you, but I am kind of new to all this and a bit confused. I do not know how to get my modified DataSource and its records (those which were modified) to send them back to my server via GWT-RPC.
I managed to receive data via GWT-RPC. This works fine. I realized it using this thread: http://forums.smartclient.com/showthread.php?t=3538
I used this Master Detail example (http://www.smartclient.com/smartgwt/..._master_detail) and show my received data in the grid. A click on a record shows the data in the form.
Now, what steps do I have to take if the user has modified the data in the form and hits the Save button? How to I get my modified DataSource and its records? I put notes in the code below to show where I am stuck.
This is my class PersonPanel (its like the Master Detail example):
Code:
public class PersonPanel extends Canvas
{
public PersonPanel()
{
VLayout layout = new VLayout(15);
Label label = new Label();
label.setHeight(10);
label.setWidth100();
label.setContents("Persons");
layout.addMember(label);
final DataSource dataSource = PersonDS.getInstance();
final DynamicForm form = new DynamicForm();
form.setIsGroup(true);
form.setGroupTitle("Update");
form.setNumCols(3);
form.setDataSource(dataSource);
final ListGrid listGrid = new ListGrid();
listGrid.setWidth(200);
listGrid.setHeight(200);
listGrid.setDataSource(dataSource);
listGrid.setAutoFetchData(true);
listGrid.addRecordClickHandler(new RecordClickHandler() {
public void onRecordClick(RecordClickEvent event)
{
form.reset();
form.editSelectedData(listGrid);
}
});
layout.addMember(listGrid);
layout.addMember(form);
IButton button = new IButton("Save");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event)
{
form.saveData();
// - - - - - This is where I don not know what to do - - - - - -
// Do I have to call a method in my DataSource object (PersonDS)
// If yes, how do I get my DataSource records?
// How do I know which record has changed / was modified?
}
});
layout.addMember(button);
layout.draw();
}
}
Code:
public class PersonDS extends DataSource
{
private PersonServiceAsync personService;
private static PersonDS instance = null;
public static PersonDS getInstance()
{
if (instance == null) {
instance = new PersonDS("personeDS");
}
return instance;
}
public PersonDS(String identifier)
{
setID(identifier);
setClientOnly(true);
DataSourceIntegerField id = new DataSourceIntegerField("id", "Id");
DataSourceTextField firstName = new DataSourceTextField("firstName",
"First Name");
DataSourceTextField lastName = new DataSourceTextField("lastName",
"Last Name");
setFields(id, firstName, lastName);
loadData();
}
private void loadData()
{
if (personService == null) {
personService = (PersonServiceAsync) GWT
.create(PersonService.class);
}
personService.getData(new AsyncCallback<List<Person>>() {
public void onFailure(Throwable caught)
{
System.out.println("Problem getting data from server");
caught.printStackTrace();
}
public void onSuccess(List<Person> result)
{
// Map Part-Entities to ListGridRecords
for (Person person : result) {
addData(new PersonLGR(person.getId(),
person.getFirstName(),
person.getLastName()));
}
// Print received data
System.out.println("Persons received from remote.....");
System.out.println("Number of received persons: " + result
.size());
for (Person p : result) {
System.out.println(p.getId() + "/"
+ p.getFirstName()
+ "/"
+ p.getLastName());
}
}
});
}
// - - - - - This is where I don not know what to do - - - - - -
public void sendModifiedDataToServer()
{
// ???????
// I think I have to do something like this
// ListGridRecords[] modifiedRecords = this.getRecords(); <-- getRecords does not exist.
// for(ListGridRecords lgr : modifiedRecords) {
// PersonLGR personLGR = (PersonLGR) lgr;
// .....
}
}
Code:
public class PersonLGR extends ListGridRecord
{
public PersonLGR() {
}
public PersonLGR(int id, String firstName, String lastName){
setAttribute("id", id);
setAttribute("firstName", firstName);
setAttribute("lastName", lastName);
}
public int getId() {
return getAttributeAsInt("id");
}
public String getFirstName() {
return getAttributeAsString("firstName");
}
public String getLastName() {
return getAttributeAsString("lastName");
}
}
Thanks in advance for your help.
Syd
Comment