PDA

View Full Version : grid how to refresh



malen
21 Feb 2009, 5:50 PM
Hi! I have a problem updating the grid, I tried the other suggestions in other threads like getView().refresh() or reconfigure but it doesn't work. I have a grid and and an edit button (a toolbar item) which will display a dialog box. After editing, I want the grid (the selected row) to be updated, meaning if the file name was edited, I want the changes to be seen, but it doesn't do that. Attached is a screenshot.



public class View_Portfolio {
ListStore<WorkInfoBeanPost> workProducts;
Widget page = new Widget();
Grid<WorkInfoBeanPost> files;

TextToolItem edit = new TextToolItem("Edit");
final FormPanel form = new FormPanel();
@SuppressWarnings("unchecked")
public View_Portfolio(final int student_id, final int schoolId) {

form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);

form.addFormHandler(new FormHandler() {
public void onSubmit(FormSubmitEvent event) {
}
public void onSubmitComplete(FormSubmitCompleteEvent event) {
Window.alert(event.getResults());
}
});

final StudentServiceAsync service = (StudentServiceAsync)
GWT.create(StudentService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) service;
String moduleRelativeURL = GWT.getModuleBaseURL() + "/StudentService";
endpoint.setServiceEntryPoint(moduleRelativeURL);

RpcProxy proxy = new RpcProxy() {
@Override
public void load(Object loadConfig, AsyncCallback callback) {
service.getPosts(student_id, schoolId, (PagingLoadConfig) loadConfig,
callback);
}
};

final BasePagingLoader loader = new BasePagingLoader(proxy);
loader.setRemoteSort(true);
loader.load(0, 15);

workProducts = new ListStore<WorkInfoBeanPost>(loader);

final PagingToolBar toolBar = new PagingToolBar(15);
toolBar.bind(loader);

List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("fileName", "Filename", 150));
columns.add(new ColumnConfig("file_date_uploaded", "Date Uploaded", 150));
columns.add(new ColumnConfig("license_name", "License Name", 150));
final ColumnModel cm = new ColumnModel(columns);

files = new Grid<WorkInfoBeanPost>(workProducts,cm);
files.setLoadMask(true);
files.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

edit.addSelectionListener(new SelectionListener<ToolBarEvent> () {
public void componentSelected(ToolBarEvent ce){
final WorkInfoBeanPost temp =
files.getSelectionModel().getSelectedItem();


final DialogPanel cdb = new DialogPanel(temp.getId(),
student_id, schoolId, finalListOfTeachersWhoAssessed,
finalTheOtherTeachers);
final Dialog db = new Dialog();
db.setHeading("Edit "+temp.getFName());
db.add(cdb);
db.setButtons(Dialog.OKCANCEL);
db.okText = "Save";
db.setWidth(550);
db.setModal(true);
db.setBodyStyle("backgroundColor: white;");

db.getButtonBar().getButtonById(Dialog.OK).addListener(Events.Select,new SelectionListener<ButtonEvent>(){
public void componentSelected(ButtonEvent ce){
boolean isSuccess = false;

//values for saveWork are obtained here

saveWork(fileId, schoolId, fileNameStr, tagStr, rubricToolStr,
privacyStr, assessorStr, rubricTagStr);
files.getView().refresh(true);

db.hide();

}
});
db.show();
}
});

files.getSelectionModel().addListener(Events.SelectionChange, new
Listener<SelectionChangedEvent>() {
public void handleEvent(final SelectionChangedEvent be) {
edit.setEnabled(true);
//display file detail in a container on the right side

}
});

...
...
...
}

http://img15.imageshack.us/img15/2328/screenshotr.th.jpg (http://img15.imageshack.us/my.php?image=screenshotr.jpg)

jadrake75
22 Feb 2009, 9:34 AM
The getView().refresh(true); should be called after the store is updated. Your store is being loaded via RPC. When you call the "saveWork( )", you are modifying the bean in the store right? the refresh will not call the getPosts method to redraw, it will simple refresh to view from the current store models.

malen
22 Feb 2009, 9:50 AM
Hi jadrake 75! How will I update the store? What methods do I need to call for the store to be updated? Thank you for your reply.

malen
23 Feb 2009, 3:11 AM
The getView().refresh(true); should be called after the store is updated. Your store is being loaded via RPC. When you call the "saveWork( )", you are modifying the bean in the store right? the refresh will not call the getPosts method to redraw, it will simple refresh to view from the current store models.

when i call saveWork, i am updating the file chosen in the database. saveWork sends the changes to a servlet which will update the database.

malen
23 Feb 2009, 3:27 AM
The getView().refresh(true); should be called after the store is updated. Your store is being loaded via RPC. When you call the "saveWork( )", you are modifying the bean in the store right? the refresh will not call the getPosts method to redraw, it will simple refresh to view from the current store models.
i can't user FormBinding because the information that will be edited is on the DialogBox that pops up, not in a form panel.

malen
23 Feb 2009, 4:38 AM
here's the whole code of the class view_portfolio, minus other methods not directly affected the grid..



package com.ePasa2.client.student;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;

import com.ePasa2.client.interfaces.StudentService;
import com.ePasa2.client.interfaces.StudentServiceAsync;
import com.ePasa2.client.interfaces.ViewAssessmentService;
import com.ePasa2.client.interfaces.ViewAssessmentServiceAsync;
import com.ePasa2.client.beans.ViewAssessmentBean;
import com.ePasa2.client.beans.WorkInfoBeanPost;
import com.extjs.gxt.ui.client.Events;
import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.FormEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.event.ToolBarEvent;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.PagingToolBar;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.form.FormPanel.Encoding;
import com.extjs.gxt.ui.client.widget.form.FormPanel.Method;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.menu.Menu;
import com.extjs.gxt.ui.client.widget.menu.MenuItem;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class View_Portfolio {
ListStore<WorkInfoBeanPost> workProducts;
Widget page = new Widget();
Grid<WorkInfoBeanPost> files;
ContentPanel content = new ContentPanel();
ContentPanel fileDetails = new ContentPanel();
LayoutContainer container = new LayoutContainer();
ToolBar toolbar = new ToolBar();
TextToolItem edit = new TextToolItem("Edit");
TextToolItem download = new TextToolItem("Download");
TextToolItem assess = new TextToolItem("Assessments");
Menu menu = new Menu();
VerticalPanel assessmentPanel = new VerticalPanel();
final FormPanel form = new FormPanel();
boolean temp9 = false;
String tagStr = "";
String rubricToolStr = "";
String fileNameStr = "";
String privacyStr = "";
String assessorStr = "";
String assessorStrFin ="";
String theLastContent="";
String rubricTagStr = "";
String finalListOfTeachersWhoAssessed;
String finalTheOtherTeachers;
int fileId = 0;
Panel cdb;
Dialog db;

//FormBinding formBindings;
@SuppressWarnings("unchecked")
public View_Portfolio(final int student_id, final int schoolId) {
assessmentPanel.setStyleName("vFolioBorder");
assessmentPanel.setSize("620px", "200px");

toolbar.add(edit);
toolbar.add(new SeparatorToolItem());
toolbar.add(download);
toolbar.add(new SeparatorToolItem());
assess.setMenu(menu);
toolbar.add(assess);

form.setEncoding(Encoding.MULTIPART);
form.setMethod(Method.POST);
form.addListener(Events.Submit, new Listener() {
public void handleEvent(BaseEvent be) {
FormEvent fe = (FormEvent) be;
Window.alert("Edit complete.");
History.newItem("view_portfolio");
}
});

final StudentServiceAsync service = (StudentServiceAsync) GWT.create(StudentService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) service;
String moduleRelativeURL = GWT.getModuleBaseURL() + "/StudentService";
endpoint.setServiceEntryPoint(moduleRelativeURL);

RpcProxy proxy = new RpcProxy() {
@Override
public void load(Object loadConfig, AsyncCallback callback) {
service.getPosts(student_id, schoolId, (PagingLoadConfig) loadConfig, callback);
}
};
final BasePagingLoader loader = new BasePagingLoader(proxy);
loader.setRemoteSort(true);
loader.load(0, 15);

workProducts = new ListStore<WorkInfoBeanPost>(loader);

final PagingToolBar toolBar = new PagingToolBar(15);
toolBar.bind(loader);

List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("fileName", "Filename", 150));
columns.add(new ColumnConfig("file_date_uploaded", "Date Uploaded", 150));
columns.add(new ColumnConfig("license_name", "License Name", 150));
final ColumnModel cm = new ColumnModel(columns);

final LabelField fNameTitle = new LabelField();
fNameTitle.setStyleName("fontVerySmallBold");
final LabelField fName = new LabelField();
fName.setStyleName("fontVerySmall2");

final LabelField dateUploadedTitle = new LabelField();
dateUploadedTitle.setStyleName("fontVerySmallBold");
final LabelField dateUploaded = new LabelField();
dateUploaded.setStyleName("fontVerySmall2");

final LabelField licenseTitle = new LabelField();
licenseTitle.setStyleName("fontVerySmallBold");
final LabelField license = new LabelField();
license.setStyleName("fontVerySmall2");

final LabelField privacyTitle = new LabelField();
privacyTitle.setStyleName("fontVerySmallBold");
final LabelField privacy = new LabelField();
privacy.setStyleName("fontVerySmall2");

final LabelField tagTitle = new LabelField();
tagTitle.setStyleName("fontVerySmallBold");
final LabelField tag = new LabelField();
tag.setStyleName("fontVerySmall2");

final LabelField rubricTitle = new LabelField();
rubricTitle.setStyleName("fontVerySmallBold");
final LabelField rubric = new LabelField();
rubric.setStyleName("fontVerySmall2");

final LabelField rubricTagTitle = new LabelField();
rubricTagTitle.setStyleName("fontVerySmallBold");
final LabelField rubricTag = new LabelField();
rubricTag.setStyleName("fontVerySmall2");

fileDetails.add(fNameTitle);
fileDetails.add(fName);
fileDetails.add(dateUploadedTitle);
fileDetails.add(dateUploaded);
fileDetails.add(licenseTitle);
fileDetails.add(license);
fileDetails.add(privacyTitle);
fileDetails.add(privacy);
fileDetails.add(tagTitle);
fileDetails.add(tag);
fileDetails.add(rubricTitle);
fileDetails.add(rubric);
fileDetails.add(rubricTagTitle);
fileDetails.add(rubricTag);

files = new Grid<WorkInfoBeanPost>(workProducts,cm);
files.setLoadMask(true);

files.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

//formBindings = new FormBinding(cdb.mainPanel, true);
//formBindings.setStore(files.getStore());


edit.setEnabled(false);
download.setEnabled(false);
assess.setEnabled(false);
assess.addSelectionListener(new SelectionListener<ToolBarEvent>() {
@Override
public void componentSelected(ToolBarEvent ce) {
final WorkInfoBeanPost temp = files.getSelectionModel().getSelectedItem();
final List firstNameList = (List) temp.getFirstNameList();
final List lastNameList = (List) temp.getLastNameList();
final List assessmentIdList = (List) temp.getAssessmentId();
List<?> theUserNameList = (List<?>)temp.getTeachersWhoAssessed();
ListIterator<?> userIter = theUserNameList.listIterator();
edit.setEnabled(true);
download.setEnabled(true);
assess.setEnabled(true);

String theListOfTeachersWhoAssessed="";
String tempStr=temp.getAssessorName();
boolean first = true;
String newList = "";
menu.removeAll();
while (userIter.hasNext()) {
String oneTeacher = (String) userIter.next();
if (first) {
theListOfTeachersWhoAssessed = oneTeacher;
first = false;
if (!temp.equals("")) {
if (tempStr.indexOf(oneTeacher+",")!=-1) {
newList = tempStr.replaceFirst((oneTeacher+", "), "");
} else if ((tempStr.indexOf(oneTeacher)+oneTeacher.length()) == tempStr.length()) {
newList = tempStr.replaceFirst((", "+oneTeacher), "");
}
}
} else if (!first) {
theListOfTeachersWhoAssessed = theListOfTeachersWhoAssessed +", " + oneTeacher;
if (!tempStr.equals("")) {
if (tempStr.indexOf(oneTeacher+",")!=-1) {
newList = newList.replaceFirst((oneTeacher+", "), "");
} else if ((tempStr.indexOf(oneTeacher)+oneTeacher.length()) == tempStr.length()) {
newList = newList.replaceFirst((", "+oneTeacher), "");
}
}
}
}
finalListOfTeachersWhoAssessed = theListOfTeachersWhoAssessed;
finalTheOtherTeachers = newList;
if (temp.getAssessed()) {
final ListIterator firstIter = firstNameList.listIterator();
final ListIterator lastIter = lastNameList.listIterator();
final ListIterator idIter = assessmentIdList.listIterator();

while (firstIter.hasNext()) {
final String firstName = (String) firstIter.next();
final String lastName = (String) lastIter.next();
final int assessmentId = (Integer) idIter.next();

menu.add(new MenuItem(firstName + " " + lastName, new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
getAssess(assessmentId, schoolId, firstName, lastName, temp.getWorkName());
}
}));
}
} else {
menu.add(new MenuItem("No assessments"));
}

}
});


download.addSelectionListener(new SelectionListener<ToolBarEvent>() {
@Override
public void componentSelected(ToolBarEvent ce) {
final WorkInfoBeanPost temp = files.getSelectionModel().getSelectedItem();
form.setAction(GWT.getModuleBaseURL() + "/StudentFileService?id=" + temp.getId()+"&schoolId="+schoolId+"&stud_num="+student_id);
form.submit();
}
});
edit.addSelectionListener(new SelectionListener<ToolBarEvent> () {
public void componentSelected(ToolBarEvent ce){
final WorkInfoBeanPost temp = files.getSelectionModel().getSelectedItem();

cdb = new Panel(temp.getId(), student_id, schoolId, finalListOfTeachersWhoAssessed, finalTheOtherTeachers);
db = new Dialog();
db.setHeading("Edit "+temp.getFName());
db.add(cdb);
db.setButtons(Dialog.OKCANCEL);
db.okText = "Save";
db.setWidth(550);
db.setModal(true);
db.setBodyStyle("backgroundColor: white;");
db.getButtonBar().getButtonById(Dialog.CANCEL).addListener(Events.Select,new SelectionListener<ButtonEvent>(){
public void componentSelected(ButtonEvent ce){
db.hide();
}
});
db.getButtonBar().getButtonById(Dialog.OK).addListener(Events.Select,new SelectionListener<ButtonEvent>(){
public void componentSelected(ButtonEvent ce){
files.getStore().commitChanges();
boolean isSuccess = false;
fileId = temp.getId();
fileNameStr = (String) cdb.file.getValue();
tagStr = (String) cdb.fileTags.getValue();
String[] tagsArray = checkDoubleTags(tagStr);
for (int index = 0; index < tagsArray.length; index++) {
if (index == 0) tagStr = tagsArray[index];
else tagStr = tagStr +", " + tagsArray[index];
}
rubricToolStr = (String) cdb.rubricTool.getValue();
if (cdb.radio1.getValue()== true) {
privacyStr = "private";
} else if (cdb.radio2.getValue() == true) {
privacyStr = "public";
} else if (cdb.radio3.getValue() == true) {
privacyStr = "global";
if (cdb.radio2.isEnabled()) {
insertFileG(fileId, student_id, schoolId);
}
}

if (cdb.userDefinedButton.isChecked()) assessorStr = (String) cdb.teacherTag.getValue();
else if (cdb.searchDefinedButton.isChecked()) assessorStr = (String) cdb.teacherTag3.getValue();
if (cdb.teacherTagFin.getValue() != null) assessorStrFin = (String) cdb.teacherTagFin.getValue();
if (!assessorStrFin.equalsIgnoreCase("No teachers have assessed yet.")) {
if (assessorStr.length() != 0 && !(assessorStrFin.length()==0) ) {
assessorStr = assessorStrFin + ", " + assessorStr;
} else if (assessorStr.length() == 0) {
assessorStr = assessorStrFin;
}
}
rubricTagStr = (String) cdb.rubricTag.getValue();
saveWork(fileId, schoolId, fileNameStr, tagStr, rubricToolStr, privacyStr, assessorStr, rubricTagStr);

db.hide();

//System.out.println("list is "+workProducts.getModifiedRecords());
//files.getStore().getLoader().load();
//files.getStore().getModifiedRecords();
//files.getStore().update(files.getSelectionModel().getSelectedItem());
//files.getView().refresh(true);
//files.getStore().getModifiedRecords();
//files.getSelectionModel().refresh();
//loader.load();
//files.reconfigure(workProducts,cm);
//workProducts = new ListStore<WorkInfoBeanPost>( loader);
//workProducts.getLoader().load();
//files.getStore().removeAll();
//files = new Grid<WorkInfoBeanPost>(workProducts,cm);
//workProducts.getLoader().load();
//files.getStore().getLoader().load();
files.getView().refresh(false);
//files.getStore().getModifiedRecords();
//files.getStore().commitChanges();
}
});
db.show();
}
});

files.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent>() {
public void handleEvent(final SelectionChangedEvent be) {
edit.setEnabled(true);
download.setEnabled(true);
assess.setEnabled(true);
/*
if (be.getSelection().size() > 0) {
formBindings.bind((ModelData) be.getSelection().get(0));
} else {
formBindings.unbind();
}
*/

final WorkInfoBeanPost temp = files.getSelectionModel().getSelectedItem();
fNameTitle.setText("File Name:");
fName.setText(""+ be.getSelectedItem().get("fileName"));
dateUploadedTitle.setText("Date Uploaded:");
dateUploaded.setText(""+ DateTimeFormat.getMediumDateTimeFormat().format(temp.getDateUploaded()));
licenseTitle.setText("License:");
license.setText("" + temp.getLicenseName());
privacyTitle.setText("Privacy:");
privacy.setText("" + temp.getFilePrivacy());
tagTitle.setText("Work Product Tags:");
tag.setText("" + temp.getFileTags());
rubricTitle.setText("Rubric Tool:");
rubric.setText("" + temp.getRubricName());
rubricTagTitle.setText("Rubric Tool Tags:");
if (temp.getRubricTags() != "" && temp.getRubricTags() != null) rubricTag.setText("" + temp.getRubricTags());
else rubricTag.setText("No rubric tags");

}
});

BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
centerData.setMargins(new Margins(5));
BorderLayoutData eastData = new BorderLayoutData(LayoutRegion.EAST);
eastData.setMargins(new Margins(5, 5, 5, 0));
eastData.setSplit(true);

content.setHeading("Work Products");
content.setSize(515, 400);
content.setLayout(new FitLayout());
content.add(files);
content.setBottomComponent(toolBar);
fileDetails.setTopComponent(toolbar);
fileDetails.setHeading("Details");
fileDetails.setScrollMode(Style.Scroll.AUTO);
container.setSize(775, 400);
container.setBorders(true);
container.setLayout(new BorderLayout());
container.add(content, centerData);
container.add(fileDetails, eastData);
fileDetails.add(form);
page = container;
}

public void saveWork(int fileId, int schoolId, String fileNameStr, String tagStr, String rubricToolStr, String privacyStr, String assessorStr, String rubricTagStr) {
StudentServiceAsync studentService = (StudentServiceAsync) GWT.create( StudentService.class );
ServiceDefTarget endpoint = (ServiceDefTarget) studentService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "/StudentService";
endpoint.setServiceEntryPoint(moduleRelativeURL);

studentService.saveWorkInfo(fileId, schoolId, fileNameStr, tagStr, rubricToolStr, privacyStr, assessorStr, rubricTagStr, new AsyncCallback<Object>(){
public void onSuccess(Object result) {


Window.alert("File information changes saved.");
files.getStore().commitChanges();

}
public void onFailure(Throwable caught) {
Window.alert("Unable to get data from server: " +caught.toString());
}
});

}

public Widget getWidget() {
return page;
}
}



here's the server side code

public WorkInfoBean saveWorkInfo(int fileId, int schoolId, String fileNameStr, String tagStr, String toolStr, String privacyStr, String assessorStr, String rubricTagStr){

Connection con = null;
String query = "";
WorkInfoBean wib = new WorkInfoBean();

//query = "UPDATE " +Integer.toString(schoolId)+"deliverable SET file_name='"+fileNameStr +"', file_license_name='"+licenseStr +"', file_privacy='"+privacyStr +"', " +
query = "UPDATE " +Integer.toString(schoolId)+"deliverable SET file_name='"+fileNameStr +"', file_privacy='"+privacyStr +"', " +
"file_assessor_name='" +assessorStr +"', rubric_tags='"+rubricTagStr +"', file_tags='" +tagStr +"', file_rubric_id= ( SELECT rubric.rubric_id FROM " +Integer.toString(schoolId)+"rubric rubric" +
" WHERE rubric.rubric_name='"+toolStr +"') WHERE file_id='" +fileId +"'";

try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(cs.getConnectionName(),cs.getUserName(),cs.getPassword());
Statement st = con.createStatement();

st.executeUpdate(query);

}catch(Exception e) {
e.printStackTrace();
System.out.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}
return wib;
}

jadrake75
23 Feb 2009, 4:03 PM
Correct me if I am wrong, but your saveWorkInfo is returning a WorkInfoBean, but you are not populating the WorkfInfoBean with the data which you updated from your JDBC call. As well in your "onSuccess()" you are commiting changes, but because you are modifying the bean outside of the table (via the dialog - with your call to your service) I am not sure if it would be monitoring the changes. ie. if you are using a CellEditor to edit it in place in a grid, the CellEditor will send the events to the store that the value has been updated and upon committing them will "keep" the changes (note I do not say store - since you need to do that separately as you are doing). I think part of the issue then, is when you click the "ok/save" action, you need to ensure the proper events are raised to the store so that it knows the records is updated (and thus you can commit the change later) - to see if this is happening I noticed you had a commented out "getModifiedRecords( )" call on your store. If the store is getting updates to your model, this will be non-empty when making changes to the underlying bean.

Your other option, is to take the outcome of your WorkInfoBean from the save call (lets say the server side inserts a MODIFICATION timestamp (reflecting the server timestamp))in the onSuccess( ) method, and find the record in the store representing that bean and modify it there (or for a new/insert - create a record and add it to the store).

From the sounds of it, as you have written it, the only way to get a "refreshed" table would be to reinvoke the getPosts( ) call, but that wouldn't be very WEB 2.0 would it? (ie. reloading the entire table). Ideally you should be able to update that portion which is modified.

I have done both of the above in my code. Where I have a wizard, I get the response from the server and if successful, add the bean to the store (no commit/reject needed here). If doing inline editing (such as an editable table) I will track the changes made from the CellEditors and upon the user clicking "Save" post the changes to the server, and if all are valid, commit the changes on the store. In this case I am modifying the model directly from the grid.

malen
23 Feb 2009, 4:21 PM
As well in your "onSuccess()" you are commiting changes, but because you are modifying the bean outside of the table (via the dialog - with your call to your service) I am not sure if it would be monitoring the changes. ie. if you are using a CellEditor to edit it in place in a grid, the CellEditor will send the events to the store that the value has been updated and upon committing them will "keep" the changes (note I do not say store - since you need to do that separately as you are doing). I think part of the issue then, is when you click the "ok/save" action, you need to ensure the proper events are raised to the store so that it knows the records is updated (and thus you can commit the change later) - to see if this is happening I noticed you had a commented out "getModifiedRecords( )" call on your store. If the store is getting updates to your model, this will be non-empty when making changes to the underlying bean.


Oh, I noticed too that I wasn't putting in the changes in the bean I'm returning from the servlet. Thanks for that. I'm now starting to "see light" on this. Another question, what are the events that i need to code for the store (and files, as the grid) to listen and be updated, was it Events.Change? Events.Submit?

malen
23 Feb 2009, 6:09 PM
weeeee. i was able to do it by directly replacing the selected item with the edited bean. thanks so much jadrake75! you're a big help! ;)

malen
24 Feb 2009, 12:32 AM
hmm.. i realized that it reverts to the old data when i try to refresh the page or go to other pages and go back to it. how do i "commit the changes" or how do i notify the store that it has been changed? another bug that results from this is that when i log in as a different user, i see the same files (not are not the current user's files) of the previous/first account i used in that session to logged in.

I tried to print an information from the workProduct (the store), I got a null pointer exception. Why is that? But if its null, then why does it load in files (the grid)?

malen
24 Feb 2009, 5:41 PM
here's the changes I've made in saveWork...
public void saveWork(int fileId, int schoolId, String fileNameStr, String tagStr, String rubricToolStr, String privacyStr, String assessorStr, String rubricTagStr) {
StudentServiceAsync studentService = (StudentServiceAsync) GWT.create( StudentService.class );
ServiceDefTarget endpoint = (ServiceDefTarget) studentService;
String moduleRelativeURL = GWT.getModuleBaseURL() + "/StudentService";
endpoint.setServiceEntryPoint(moduleRelativeURL);

studentService.saveWorkInfo(fileId, schoolId, fileNameStr, tagStr, rubricToolStr, privacyStr, assessorStr, rubricTagStr, new AsyncCallback<Object>(){
public void onSuccess(Object result) {
Window.alert("File information changes saved.");

final WorkInfoBeanPost x = (WorkInfoBeanPost) result;

System.out.println("file is "+x.getFName());
files.getSelectionModel().getSelectedItem().setRubricTags(x.getRubricTags());
files.getView().refresh(false);

fName.setText(""+ x.getFName());
dateUploaded.setText(""+ DateTimeFormat.getMediumDateTimeFormat().format(x.getDateUploaded()));
license.setText("" + x.getLicenseName());
privacy.setText("" + x.getFilePrivacy());
tag.setText("" + x.getFileTags());
rubric.setText("" + x.getRubricName());

if (x.getRubricTags() != "" && x.getRubricTags() != null) rubricTag.setText("" + x.getRubricTags());
else rubricTag.setText("No rubric tags");

files.getStore().commitChanges(); //this doesn't do anything

System.out.println("get modifed records "+files.getStore().getModifiedRecords());
}
public void onFailure(Throwable caught) {
Window.alert("Unable to get data from server: " +caught.toString());
}
});
}


from the server side, i also queried for the update and am returning it here. I'm able to the updated bean from the object result. but if try to refresh, it gets lost or if i move out this module, say click another link to another page, and go back, it reverts to the old bean.

malen
25 Feb 2009, 5:05 PM
was able to fixed it. thanks. ;)