Announcement

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

    ComboBox custom display value formatter

    Hi,

    can you advise me how to achive a custom display value for a combobox?

    I have a persistent entity(hibernate) Branches with a reference to another entity Employees.

    I'd like to have an option to put a ComboboxItem to a dynamic form which would select appropriate user. The display field should be "name surname".

    The entity user has of course name and surname stored separately.

    My DS is a follow
    Code:
    <field name="regionalManager" length="80" unknownType="true" type="cz.bcom.server.persistence.hibernate.Employees" hidden="true"></field>
    
    <field name="regionalManagerFirstName" type="text" valueXPath="regionalManager/firstName" hidden="true"></field>
    <field name="regionalManagerSurname" type="text" valueXPath="regionalManager/surname" hidden="true"></field>
    in the java there is
    Code:
    regionalManagerItem = new ComboBoxItem("regionalManager", i18nConstants.settingsTree_branchManagement_addEditWindow_dynamicForm_regionalManager());
    regionalManagerItem.setOptionDataSource(DataSource.get("employeesDS"));
    regionalManagerItem.setValueField("employeeId");
    regionalManagerItem.setDisplayField(????);
    I can take the name and surname from the record but don't know what to do with it

    Code:
    String employeesByChangedBySurname = record.getAttribute("employeesByChangedBySurname");
    String employeesByChangedByFirstName = record.getAttribute("employeesByChangedByFirstName");

    Secondly,

    I have a ComboboxItem with optionalDataSource set. I'd like to display another disabled text field with a different attribete from the chosen object above.

    So I set the same OptionalDataSource to the textField like the one from ComboBoxItem. and whenewer the combobox changes I set textItem.setValue to it.

    It works but there are 2 RPC call to server which is quite unnecessary.

    Code:
    		branchItem.setOptionDataSource(DataSource.get("branchesDS"));
    branchItem.setValueField("branchId");
    branchItem.setDisplayField("name");
    branchItem.addChangedHandler(new ChangedHandler() {
    	@Override
    	public void onChanged(ChangedEvent event) {
    		branchPrimaryCodeItem.setValue(branchItem.getValue());
    	}
    });
    
    
    branchPrimaryCodeItem = new TextItem("primaryCode", i18nConstants.settingsTree_employeeManagement_addEditWindow_dynamicForm_branchPrimaryCode());
    branchPrimaryCodeItem.setDisabled(true);
    branchPrimaryCodeItem.setShouldSaveValue(false);
    branchPrimaryCodeItem.setOptionDataSource(DataSource.get("branchesDS"));
    branchPrimaryCodeItem.setValueField("branchId");
    branchPrimaryCodeItem.setDisplayField("primaryCode");
    Is there a better way hot to achieve this?

    Cheers,
    Martin

    #2
    Add a ValueFormatter that uses getSelectedRecord() to get to values in the related record.

    Note that if getSelectedRecord() is null, that means the related record isn't available (field is empty, user has not chosen a record, or selectedRecord is being fetched via fetchMissingValues) so just show the current value.

    As far as the second question, why are you setting optionDataSource on the disabled TextItem? There doesn't appear to be a need for that, and that's why the extra fetch is coming from (via fetchMissingValues).

    Comment


      #3
      The second problem was solved by using getSelectedRecord().
      I put there the optional data source because I didn't know how to fetch the whole record.
      Thanks


      As far as the ValueFormatter is concerned I cannot make it work. It gets never called.
      I replaced setDisplayValue with setValueFormatter but all I can see is the employee primary id.

      Code:
      regionalManagerItem = new ComboBoxItem("regionalManagerId", i18nConstants.settingsTree_branchManagement_addEditWindow_dynamicForm_regionalManager());
      regionalManagerItem.setWidth(300);
      regionalManagerItem.setOptionDataSource(DataSource.get("employeesDS"));
      regionalManagerItem.setValueField("employeeId");
      regionalManagerItem.setValueFormatter(new FormItemValueFormatter() {
      	@Override
      	public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
      				
      		System.out.println("formatValue="+value);
      		String surname = record.getAttribute("surname");
      		String firstName = record.getAttribute("firstName");
      		if (surname == null || firstName == null)
      			return "TODO null name";
      		return i18nMessages.settingsTree_branchManagement_addEditWindow_dynamicForm_regionalManager_displayName(firstName, surname);
      	}
      });

      Cheers,
      Martin

      Comment


        #4
        Well, you're not calling getSelectedRecord() in the ValueFormatter at all, so that would be the problem.

        The "record" you're passed is the Record being edited by the form, not the related Record from the optionDataSource.

        Comment


          #5
          yes,
          I didn't get that far because the whole method doesn't get called.

          I put there a system out print which never occurs.
          If the method got called it should at least return string "TODO null name" instead of database ID number.

          I need to convince that ComboBoxItem to start using ValueFormatter.

          Cheers,
          Martin

          Comment


            #6
            Originally posted by zdary
            yes,
            I didn't get that far because the whole method doesn't get called.

            I put there a system out print which never occurs.
            If the method got called it should at least return string "TODO null name" instead of database ID number.

            I need to convince that ComboBoxItem to start using ValueFormatter.

            Cheers,
            Martin
            I'm having the same problem here. It seems that ValueFormatter is never called (some bug?) but I could work around it by doing the following:

            1. In the backend, make a derived property available such as "getFullName()" which concatenates the firstName and surname.
            2. In the frontend add the following:

            Code:
                ListGrid pickListProperties = new ListGrid();
                pickListProperties.setDataSource(DataSource.get("employeesDS"));
                regionalManagerItem.setPickListProperties(pickListProperties);
                regionalManagerItem.setOptionDataSource(DataSource.get("employeesDS"));
                regionalManagerItem.setDisplayField("fullName");
                regionalManagerItem.setValueField("employeeId");
            I don't fully understand how the magic happens but this should work for you. The idea of using pickupList is taken from the example at:

            http://www.smartclient.com/smartgwt/showcase/#styled_combobox_category

            Even though this works, you might still have problem to show the "fullName" when the same field is used in a Grid, which doesn't fetch the missing value for you. I've started the thread below, still waiting for answers:

            http://forums.smartclient.com/showthread.php?t=16441

            Comment


              #7
              I've copied your comment in my other thread at http://forums.isomorphic.com/showthread.php?t=16441:

              Originally posted by zdary
              Hi,

              I've just found out the ValueFormater works fine for SelectItem but not for ComboBoxItem.

              Martin
              You are right, but there is still a problem as per Isomorphic:

              Code:
              The "record" you're passed is the Record being edited by the form, not the related Record from the optionDataSource.
              This means that you can't do something like this:

              Code:
                  regionalManagerItem.setValueFormatter(new FormItemValueFormatter() {
                    
                    @Override
                    public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
                      String firstName = record.getAttribute("firstName");
                      String lastName = record.getAttribute("lastName");
                      
                      return firstName + " " + lastName;
                    }
                  });
              So that's why I've worked around it by adding a server side derived attribute "fullName". I wish there's a better way to do this... any thoughts?

              Comment


                #8
                Have you tried this?

                Code:
                SelectItem regionalManagerItem = new SelectItem("regionalManagerId", i18nConstants.settingsTree_branchManagement_addEditWindow_dynamicForm_regionalManager());
                regionalManagerItem.setWidth(300);
                regionalManagerItem.setOptionDataSource(DataSource.get("employeesDS"));
                regionalManagerItem.setValueField("employeeId");
                regionalManagerItem.setValueFormatter(new FormItemValueFormatter() {
                	@Override
                	public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
                		optionalRecord = getSelectedRecord();
                		if (optionalRecord != null) {
                			String surname = record.getAttribute("surname");
                			String firstName = record.getAttribute("firstName");
                			return firstName + " " + surname;		
                		 else {
                			return "loading...";
                		}
                	}
                });
                I believe that the only problem is the ComboBoxItem doesn't call ValueFormatter whereas SelectItem does.

                Cheers,
                Martin

                Comment


                  #9
                  @zdary: just tried your tip on "regionalManagerItem.getSelectedRecord()" but I get this stacktrace and nothing is rendered:

                  Code:
                  00:06:59.704  [ERROR] 2011-04-24 14:15:31,876 [FATAL] Uncaught Exception:
                  
                  com.google.gwt.core.client.JavaScriptException: (TypeError): self.getSelectedRecord is not a function
                   fileName: http://127.0.0.1:8888
                   lineNumber: 172
                   stack: ()@http://127.0.0.1:8888:172
                  @:0
                  ([object GWTJavaObject],6619138,null,[object GWTJavaObject],[object GWTJavaObject],[object GWTJavaObject])@http://127.0.0.1:8888/mybanners/hosted.html?mybanners:56
                  ((void 0),[object Object],[object Object],[object Object])@http://127.0.0.1:8888:938
                  ((function (value, record, form, item) {var valueJ = $wnd.SmartGWT.convertToJavaType(value);var formJ = __gwt_makeJavaInvoke(1)(null, 2687845, form);var itemJ = __gwt_makeJavaInvoke(1)(null, 5046668, item);var recordJ = __gwt_makeJavaInvoke(1)(null, 6553796, record);return __gwt_makeJavaInvoke(4)(formatter, 6619138, valueJ, recordJ, formJ, itemJ);}),[object Object],[object Object])@http://127.0.0.1:8888:6
                  @:0
                  (null,65642,(function (value, record, form, item) {var valueJ = $wnd.SmartGWT.convertToJavaType(value);var formJ = __gwt_makeJavaInvoke(1)(null, 2687845, form);var itemJ = __gwt_makeJavaInvoke(1)(null, 5046668, item);var recordJ = __gwt_makeJavaInvoke(1)(null, 6553796, record);return __gwt_makeJavaInvoke(4)(formatter, 6619138, valueJ, recordJ, formJ, itemJ);}),[object Object],[object Object])@http://127.0.0.1:8888/mybanners/hosted.html?mybanners:56
                  ((void 0),[object Object],[object Object],[object Object])@http://127.0.0.1:8888:65
                  ((void 0),[object Object],[object Object],[object Object])@http://127.0.0.1:8888:13
                  isc_FormItem__formatDataType((void 0))@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Forms.js:1176
                  isc_FormItem_mapValueToDisplay((void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0))@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Forms.js:1175
                  isc_c_Class_invokeSuper([object Object],"mapValueToDisplay",(void 0),(void 0),(void 0),(void 0))@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:279
                  isc_SelectItem_mapValueToDisplay((void 0))@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Forms.js:2052
                  isc_FormItem_setValue((void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0))@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Forms.js:1222
                  isc_c_Class_invokeSuper([object Object],"setValue",(void 0),(void 0),(void 0),(void 0))@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:279
                  isc_SelectItem_setValue()@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Forms.js:2037
                  isc_FormItem_clearValue()@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Forms.js:1238
                  isc_DynamicForm_setItemValues([object Object],null,(void 0))@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Forms.js:440
                  isc_DynamicForm_setValues([object Object])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Forms.js:326
                  isc_DynamicForm_setData([object Object])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Forms.js:328
                  isc_Canvas_setDataSource([object Object])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:3348
                  isc_c_Class_invokeSuper(null,"setDataSource")@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:279
                  isc_c_Class_Super("setDataSource",[object Object])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:271
                  isc_DynamicForm_setDataSource([object Object])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Forms.js:329
                  isc_Class_setProperties([object Object])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:362
                  isc_Class_setProperty("dataSource",[object Object])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:360
                  ("dataSource",[object Object])@http://127.0.0.1:8888:143
                  @:0
                  ([object GWTJavaObject],4915346,[object GWTJavaObject])@http://127.0.0.1:8888/mybanners/hosted.html?mybanners:56
                  ([object Object],[object Object],3,[object Object],0,"<table cellpadding=0 cellspacing=0 class='treeCellSelectedOver' style='margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;'><tr><td style='margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;' class='treeCellSelectedOver'></td><td style=';margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;' class='treeCellSelectedOver'><img src='http://127.0.0.1:8888/mybanners/sc/skins/Enterprise/images/TreeGrid/connector_middle.gif' width='22' height='22' align='absmiddle' name='isc_3open_icon_3'  border='0' suppress='TRUE'/><img src='http://127.0.0.1:8888/mybanners/sc/skins/Enterprise/images/TreeGrid/file.png' width='16' height='16' align='absmiddle' name='isc_3icon_3'  border='0' suppress='TRUE'/></td><td style=';margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;padding-left:3px;' class='treeCellSelectedOver'><NOBR>Trip</td></tr></table>",(void 0))@http://127.0.0.1:8888:233
                  ((function () {var param = {viewer: arguments[0], record: arguments[1], recordNum: arguments[2], field: arguments[3], fieldNum: arguments[4], value: arguments[5], rawValue: arguments[6]};var event = __gwt_makeJavaInvoke(1)(null, 11141215, param);__gwt_makeJavaInvoke(1)(selfJ, 4915346, event);var ret = __gwt_makeJavaInvoke(0)(event, 1179654);return !ret;}),[object Object],[object Object])@http://127.0.0.1:8888:6
                  @:0
                  (null,65642,(function () {var param = {viewer: arguments[0], record: arguments[1], recordNum: arguments[2], field: arguments[3], fieldNum: arguments[4], value: arguments[5], rawValue: arguments[6]};var event = __gwt_makeJavaInvoke(1)(null, 11141215, param);__gwt_makeJavaInvoke(1)(selfJ, 4915346, event);var ret = __gwt_makeJavaInvoke(0)(event, 1179654);return !ret;}),[object Object],[object Object])@http://127.0.0.1:8888/mybanners/hosted.html?mybanners:56
                  ([object Object],[object Object],3,[object Object],0,"<table cellpadding=0 cellspacing=0 class='treeCellSelectedOver' style='margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;'><tr><td style='margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;' class='treeCellSelectedOver'></td><td style=';margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;' class='treeCellSelectedOver'><img src='http://127.0.0.1:8888/mybanners/sc/skins/Enterprise/images/TreeGrid/connector_middle.gif' width='22' height='22' align='absmiddle' name='isc_3open_icon_3'  border='0' suppress='TRUE'/><img src='http://127.0.0.1:8888/mybanners/sc/skins/Enterprise/images/TreeGrid/file.png' width='16' height='16' align='absmiddle' name='isc_3icon_3'  border='0' suppress='TRUE'/></td><td style=';margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;padding-left:3px;' class='treeCellSelectedOver'><NOBR>Trip</td></tr></table>",(void 0))@http://127.0.0.1:8888:65
                  ([object Object],[object Object],3,[object Object],0,"<table cellpadding=0 cellspacing=0 class='treeCellSelectedOver' style='margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;'><tr><td style='margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;' class='treeCellSelectedOver'></td><td style=';margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;' class='treeCellSelectedOver'><img src='http://127.0.0.1:8888/mybanners/sc/skins/Enterprise/images/TreeGrid/connector_middle.gif' width='22' height='22' align='absmiddle' name='isc_3open_icon_3'  border='0' suppress='TRUE'/><img src='http://127.0.0.1:8888/mybanners/sc/skins/Enterprise/images/TreeGrid/file.png' width='16' height='16' align='absmiddle' name='isc_3icon_3'  border='0' suppress='TRUE'/></td><td style=';margin:0px;border:0px;padding:0px;background-image:none;background-color:transparent;padding-left:3px;' class='treeCellSelectedOver'><NOBR>Trip</td></tr></table>",(void 0))@http://127.0.0.1:8888:13
                  isc_ListGrid_rowClick([object Object],3,0)@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Grids.js:1532
                  isc_c_Class_invokeSuper(null,"rowClick")@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:279
                  isc_c_Class_Super("rowClick",[object Object])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:271
                  isc_TreeGrid_rowClick([object Object],3,0)@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Grids.js:2798
                  anonymous([object Object],3,0)@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Grids.js:927
                  isc_GridRenderer__rowClick(3,0)@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Grids.js:750
                  isc_GridRenderer_click([object Object],(void 0))@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Grids.js:747
                  isc_c_Class_invokeSuper(null,"click")@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:279
                  isc_c_Class_Super("click",[object Object])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:271
                  isc_TreeGridBody_click([object Object],(void 0))@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Grids.js:2740
                  isc_Canvas_handleClick([object Object],(void 0))@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:3030
                  isc_c_EventHandler_bubbleEvent([object Object],"click")@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:1497
                  isc_c_EventHandler_handleClick([object Object])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:1345
                  isc_c_EventHandler__handleMouseUp([object MouseEvent],(void 0))@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:1332
                  isc_c_EventHandler_handleMouseUp([object MouseEvent])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:1323
                  isc_c_EventHandler_dispatch(isc_c_EventHandler_handleMouseUp,[object MouseEvent])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:1560
                  anonymous([object MouseEvent])@http://127.0.0.1:8888/mybanners/sc/modules/ISC_Core.js:38
                  
                  	at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
                  	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.GeneratedMethodAccessor72.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.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.BaseWidget.setProperty(BaseWidget.java)
                  	at com.smartgwt.client.widgets.BaseWidget.setAttribute(BaseWidget.java:759)
                  	at com.smartgwt.client.widgets.form.DynamicForm.setDataSource(DynamicForm.java:3658)
                  	at com.googlecode.mybanners.client.MyBanners.switchDataSource(MyBanners.java:215)
                  	at com.googlecode.mybanners.client.MyBanners$7.onRecordClick(MyBanners.java:199)
                  	at com.smartgwt.client.widgets.grid.events.RecordClickEvent.dispatch(RecordClickEvent.java:98)
                  	at com.smartgwt.client.widgets.grid.events.RecordClickEvent.dispatch(RecordClickEvent.java:1)
                  	at com.google.gwt.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:204)
                  	at com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:103)
                  	at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:101)
                  	at com.smartgwt.client.core.DataClass.fireEvent(DataClass.java:237)
                  	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.GeneratedMethodAccessor72.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)
                  So it seems that SelectItem.getSelectedRecord is not defined... weird. I'm using SmartGWT 2.4. Has it worked for you? which version are you using?

                  Regards,

                  Cheng

                  Comment


                    #10
                    I'm using the latest night build SmartGWTEE 2.5 2011-04-22

                    There is the getSelectedRecord() defined alright but always returns the same value. The one which is really selected.

                    I put a debug into formatValue()
                    Code:
                    System.out.println(" value="+value+" select="+selectedRecord.getAttribute("surname"));
                    And it prints out to system out
                    Code:
                    value=1 select=Depa
                    value=2 select=Depa

                    see the screenshot. The SelectItems show all option with the same text.

                    I believe that you can call
                    Code:
                    regionalManagerItem.fetchData(new DSCallback() {
                    			@Override
                    			public void execute(DSResponse response, Object rawData, DSRequest request) {
                    				
                    			}
                    		});
                    and in the response you can save all data for later.
                    In the valueFormat you can get the record from the data based on Object value.
                    Attached Files

                    Comment


                      #11
                      Originally posted by zdary

                      There is the getSelectedRecord() defined alright but always returns the same value. The one which is really selected.
                      So it's not working? also, is getSelectedRecord() a member method of regionalManagerItem? I can't tell from your code

                      Originally posted by zdary
                      I believe that you can call
                      Code:
                      regionalManagerItem.fetchData(new DSCallback() {
                      			@Override
                      			public void execute(DSResponse response, Object rawData, DSRequest request) {
                      				
                      			}
                      		});
                      and in the response you can save all data for later.
                      In the valueFormat you can get the record from the data based on Object value.
                      This shouldn't be necessary since it's called automatically once you've called regionalManagerItem.setOptionDatasource()

                      Comment


                        #12
                        1) yes, SelectItem.getSelectedRecord() defined and returns selected record so that you can render full name for chosen record ONLY.

                        It cannot be done for the rest of options in a pickup list.

                        2) I agree, it shouldn't be necessary but you cannot access the data from OptionDatasource directly from SelectItem object so you need to fetch the data again separately and match it against ID then render the full name.

                        Comment


                          #13
                          2) not true, the DataArrived event gives you access to what has been loaded

                          1) use DataSource.fetchData() to retrieve a single record by passing the ID of the record as the only criteria (if it's not already loaded).

                          Comment


                            #14
                            Hi,

                            1) this doesn't make sense. it will trigger as many server calls as there are items in the SelectItem.

                            All we need to achieve is to have a SelectItem which would give us a choise of choosing user (firstName+surname).

                            If I call DataSource.fetchData inside a ValueFormat then by the time it return data the method will have been finished.

                            Code:
                            regionalManagerItem.setValueFormatter(new FormItemValueFormatter() {
                            	@Override
                            	public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
                            		Criteria criteria = new Criteria();
                            		Integer employeeID = (Integer) value;  
                                            criteria.addCriteria("employeeID", employeeID);
                            		DataSource.get("employeesDS").fetchData(criteria, new DSCallback() {
                            			@Override
                            			public void execute(DSResponse response, Object rawData, DSRequest request) {
                            				Record[] records = response.getData();
                            				for (Record pojo: records) {
                            					// FAR TOO LATE
                            				}
                            			}
                            		});
                            
                            return ???;
                            Surely, there must be a better way of achieveving this...

                            Comment


                              #15
                              getSelectedRecord() returns the selected record. This is what you are expected to use in your ValueFormatter if you want to show fields from the record that the user has selected.

                              If you, for some reason, need information from other records (presumably this is not related to ValueFormatter), then DataSource.fetchData() can get them for you.

                              Comment

                              Working...
                              X