Hi all,
I have simplest example of usage listgrid.
My Env :
1. OS - Ubuntu 9.10 x86_64
2. Browser Version - Firefox 4.0.1
3. SmartGWT Version : SmartGWTEE 2.4 (Evaluation)
I have ListGrid and i want some operations without communicate to server. (I don't use any Datasources), also I have 3 buttons below ListGrid : add Record, Edit Record and Delete Records (I will attach all screenshots later)
Here is My Code Snippets :
1. Main Panel :
Here is my ListGrid
2. Popup Window for Adding/Editing records.
Adding new Records works fine, I've problem with update selected record.
Because I got an exception after saving edited record :
3. Error :
I don't know why I got this Exception :(
Any Idea will be appreciated.
Regards,
Paata Lominadze.
I have simplest example of usage listgrid.
My Env :
1. OS - Ubuntu 9.10 x86_64
2. Browser Version - Firefox 4.0.1
3. SmartGWT Version : SmartGWTEE 2.4 (Evaluation)
I have ListGrid and i want some operations without communicate to server. (I don't use any Datasources), also I have 3 buttons below ListGrid : add Record, Edit Record and Delete Records (I will attach all screenshots later)
Here is My Code Snippets :
1. Main Panel :
Code:
VLayout hLayout = new VLayout(5); hLayout.setWidth(750); hLayout.setHeight100(); final ListGrid listGridPhones = new ListGrid(); listGridPhones.setHeight(150); listGridPhones.setWidth100(); // phone number field ListGridField phoneNumberField = new ListGridField("phone", "ტელეფონის ნომერი", 140); // open/close field ListGridField opCloseField = new ListGridField("is_hide_descr", "ღია/დაფარული", 100); // is parallel or not field ListGridField parallelUsualField = new ListGridField( "is_parallel_descr", "პარალელური", 120); // phone status field ListGridField phoneStatusField = new ListGridField("phone_status", "სტატუსი", 100); // phone state field ListGridField phoneStateField = new ListGridField("phone_state", "მდგომარეობა", 100); // phone type field ListGridField phoneTypeField = new ListGridField("phone_type", "ტიპი", 119); listGridPhones.setFields(phoneNumberField, opCloseField, parallelUsualField, phoneStatusField, phoneStateField, phoneTypeField); HLayout buttons = new HLayout(5); IButton addPhone = new IButton("add"); addPhone.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { DlgAddEditAbPhone addEditAbPhone = new DlgAddEditAbPhone(null, listGridPhones, null); addEditAbPhone.show(); } }); IButton editPhone = new IButton("edit"); editPhone.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { ListGridRecord listGridRecord = listGridPhones .getSelectedRecord(); if (listGridRecord == null) { SC.say("მონიშნეთ ჩანაწერი ცხრილში!"); return; } DlgAddEditAbPhone addEditAbPhone = new DlgAddEditAbPhone( listGridRecord, listGridPhones, null); addEditAbPhone.show(); } }); IButton deletePhone = new IButton("Delete"); buttons.setMembers(addPhone, editPhone, deletePhone); hLayout.setMembers(listGridPhones,buttons); RootPanel.get().add(hLayout);
2. Popup Window for Adding/Editing records.
Code:
public class DlgAddEditAbPhone extends Window { private VLayout hLayout; private DynamicForm formPhone; private TextItem phoneItem; private ComboBoxItem isHideItem; private ComboBoxItem isParallelItem; private ComboBoxItem phoneStatusItem; private ComboBoxItem phoneStateItem; private ComboBoxItem phoneTypeItem; private ListGrid listGridPhones; private ListGridRecord listGridRecord; private DataSource phonesDS; public DlgAddEditAbPhone(ListGridRecord listGridRecord, ListGrid listGridPhones, DataSource phonesDS) { this.listGridPhones = listGridPhones; this.listGridRecord = listGridRecord; this.phonesDS = phonesDS; setWidth(750); setHeight(150); setTitle(listGridRecord == null ? "ახალი ნომრის დამატება" : "ნომრის შესწორება"); setShowMinimizeButton(false); setIsModal(true); setShowModalMask(true); setCanDrag(false); setCanDragReposition(false); setCanDragResize(false); setCanDragScroll(false); centerInPage(); hLayout = new VLayout(5); hLayout.setWidth100(); hLayout.setHeight100(); formPhone = new DynamicForm(); formPhone.setPadding(10); formPhone.setAutoFocus(true); formPhone.setWidth100(); formPhone.setTitleWidth(80); formPhone.setNumCols(7); formPhone.setTitleOrientation(TitleOrientation.TOP); phoneItem = new TextItem(); phoneItem.setTitle("ტელეფონი"); phoneItem.setName("phone"); phoneItem.setWidth(170); isHideItem = new ComboBoxItem(); isHideItem.setValueMap(MapUtil.getInstance().getMapOpClose()); isHideItem.setDefaultToFirstOption(true); isHideItem.setTitle("ღია/დაფარული"); isHideItem.setName("is_hide"); isHideItem.setWidth(112); isParallelItem = new ComboBoxItem(); isParallelItem.setValueMap(MapUtil.getInstance().getMapParall()); isParallelItem.setDefaultToFirstOption(true); isParallelItem.setTitle("პარალელური"); isParallelItem.setName("is_parallel"); isParallelItem.setWidth(120); phoneStatusItem = new ComboBoxItem(); phoneStatusItem.setValueMap(MapUtil.getInstance().getMapStatuses()); phoneStatusItem.setDefaultToFirstOption(true); phoneStatusItem.setTitle("სტატუსი"); phoneStatusItem.setName("phone_status_id"); phoneStatusItem.setWidth(100); phoneStateItem = new ComboBoxItem(); phoneStateItem.setValueMap(MapUtil.getInstance().getMapStates()); phoneStateItem.setDefaultToFirstOption(true); phoneStateItem.setTitle("მდგომარეობა"); phoneStateItem.setName("phone_state_id"); phoneStateItem.setWidth(100); phoneTypeItem = new ComboBoxItem(); phoneTypeItem.setValueMap(MapUtil.getInstance().getMapTypes()); phoneTypeItem.setDefaultToFirstOption(true); phoneTypeItem.setTitle("ტიპი"); phoneTypeItem.setName("phone_type_id"); phoneTypeItem.setWidth(119); if (listGridRecord != null) { phoneItem.setValue(listGridRecord.getAttribute("phone")); isHideItem.setValue(listGridRecord.getAttribute("is_hide")); isParallelItem.setValue(listGridRecord.getAttribute("is_parallel")); phoneStatusItem.setValue(listGridRecord .getAttribute("phone_status_id")); phoneStateItem.setValue(listGridRecord .getAttribute("phone_state_id")); phoneTypeItem .setValue(listGridRecord.getAttribute("phone_type_id")); } formPhone.setFields(phoneItem, isHideItem, isParallelItem, phoneStatusItem, phoneStateItem, phoneTypeItem); HLayout hLayoutItem = new HLayout(5); hLayoutItem.setWidth100(); hLayoutItem.setAlign(Alignment.RIGHT); hLayoutItem.setMargin(10); IButton saveItem = new IButton(); saveItem.setTitle("save"); saveItem.setWidth(100); IButton cancItem = new IButton(); cancItem.setTitle("close"); cancItem.setWidth(100); hLayoutItem.setMembers(saveItem, cancItem); hLayout.setMembers(formPhone, hLayoutItem); addItem(hLayout); cancItem.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { destroy(); } }); saveItem.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { addRecord(); } }); } private void addRecord() { try { Object oPhone = phoneItem.getValue(); if (oPhone == null || oPhone.toString().trim().equals("")) { SC.say("გთხოვთ შეიყვანოთ ტელეფონის ნომერი !"); return; } Integer phone = null; try { phone = Integer.parseInt(oPhone.toString()); } catch (Exception e) { SC.say("არასწორი ტელეფონის ნომერი " + oPhone.toString() + " !. ტელეფონის ნომერი შედგება მხოლოდ ციფრებისაგან. "); return; } Object opClose = isHideItem.getValue(); if (opClose == null) { SC.say("გთხოვთ აირჩიოთ ტელეფონის ნომერი ღიაა თუ დაფარული !"); return; } Integer iOpClose = null; try { iOpClose = Integer.parseInt(opClose.toString()); } catch (NumberFormatException e) { SC.say("გთხოვთ აირჩიოთ ტელეფონის ნომერი ღიაა თუ დაფარული !"); return; } Object paralelUsual = isParallelItem.getValue(); if (paralelUsual == null) { SC.say("გთხოვთ აირჩიოთ ტელეფონის ნომერი პარალელურია თუ ჩვეულებრივი !"); return; } Integer iParalelUsual = null; try { iParalelUsual = Integer.parseInt(paralelUsual.toString()); } catch (NumberFormatException e) { SC.say("გთხოვთ აირჩიოთ ტელეფონის ნომერი პარალელურია თუ ჩვეულებრივი !"); return; } Object phoneStatus = phoneStatusItem.getValue(); if (phoneStatus == null) { SC.say("გთხოვთ აირჩიოთ ტელეფონის სტატუსი !"); return; } Integer iPhoneStatus = null; try { iPhoneStatus = Integer.parseInt(phoneStatus.toString()); } catch (NumberFormatException e) { SC.say("გთხოვთ აირჩიოთ ტელეფონის სტატუსი !"); return; } Object phoneState = phoneStateItem.getValue(); if (phoneState == null) { SC.say("გთხოვთ აირჩიოთ ტელეფონის მდგომარეობა !"); return; } Integer iPhoneState = null; try { iPhoneState = Integer.parseInt(phoneState.toString()); } catch (NumberFormatException e) { SC.say("გთხოვთ აირჩიოთ ტელეფონის მდგომარეობა !"); return; } Object phoneType = phoneTypeItem.getValue(); if (phoneType == null) { SC.say("გთხოვთ აირჩიოთ ტელეფონის ტიპი !"); return; } Integer iPhoneType = null; try { iPhoneType = Integer.parseInt(phoneType.toString()); } catch (NumberFormatException e) { SC.say("გთხოვთ აირჩიოთ ტელეფონის ტიპი !"); return; } boolean isAdd = false; if (listGridRecord == null) { listGridRecord = new ListGridRecord(); isAdd = true; } ListGridRecord records[] = listGridPhones.getRecords(); if (records != null && records.length > 0) { for (ListGridRecord record : records) { if (listGridRecord.equals(record)) { continue; } String rPhone = record.getAttribute("phoneNumber"); if (rPhone == null) { continue; } if (rPhone.equals(phone.toString())) { SC.say("ასეთი ნომერი უკვე მინიჭებულია ამ აბონენტისათვის"); return; } } } // TODO DB Check listGridRecord.setAttribute("phone", phone.toString()); listGridRecord.setAttribute("is_hide", iOpClose); listGridRecord.setAttribute("is_parallel", iParalelUsual); listGridRecord.setAttribute("phone_status_id", iPhoneStatus); listGridRecord.setAttribute("phone_state_id", iPhoneState); listGridRecord.setAttribute("phone_type_id", iPhoneType); listGridRecord.setAttribute("is_hide_descr", MapUtil.getInstance() .getMapOpClose().get(iOpClose.toString())); listGridRecord .setAttribute("is_parallel_descr", MapUtil.getInstance() .getMapParall().get(iParalelUsual.toString())); listGridRecord.setAttribute("phone_status", MapUtil.getInstance() .getMapStatuses().get(iPhoneStatus.toString())); listGridRecord.setAttribute("phone_state", MapUtil.getInstance() .getMapStates().get(iPhoneState.toString())); listGridRecord.setAttribute("phone_type", MapUtil.getInstance() .getMapTypes().get(iPhoneType.toString())); if (isAdd) { listGridPhones.addData(listGridRecord); } else { listGridPhones.updateData(listGridRecord); } } catch (Exception e) { e.printStackTrace(); SC.say(e.toString()); } } }
Adding new Records works fine, I've problem with update selected record.
Because I got an exception after saving edited record :
3. Error :
Code:
[ERROR] [callcenter] - 18:50:58.422:MUP1:WARN:Log:Update by primary key cannot be performed without a DataSource.Modify the record directly instead com.smartgwt.client.core.JsObject$SGWT_WARN: 18:50:58.422:MUP1:WARN:Log:Update by primary key cannot be performed without a DataSource.Modify the record directly instead at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326) at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:129) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107) at com.smartgwt.client.widgets.grid.ListGrid.updateData(ListGrid.java) at com.info08.billing.callcenter.client.dialogs.correction.DlgAddEditAbPhone.addRecord(DlgAddEditAbPhone.java:313) at com.info08.billing.callcenter.client.dialogs.correction.DlgAddEditAbPhone.access$0(DlgAddEditAbPhone.java:158) at com.info08.billing.callcenter.client.dialogs.correction.DlgAddEditAbPhone$2.onClick(DlgAddEditAbPhone.java:153) at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:98) at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:1) at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.fireEvent(HandlerManager.java:65) at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.access$1(HandlerManager.java:53) at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:178) at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:66) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326) at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:129) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) at com.google.gwt.core.client.impl.Impl.apply(Impl.java) at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214) at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352) at java.lang.Thread.run(Thread.java:662)
I don't know why I got this Exception :(
Any Idea will be appreciated.
Regards,
Paata Lominadze.