Announcement

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

    Binding the values dynamically for an enum field type to a ListGrid/Form

    Hello, I'm evaluating smartgwt for server side integration using DMI. I have defined the datasource in ds.xml & ListGrid, DynamicForm are bound to this datasource for viewing & updating the schedules. I'm trying to display a drop down whose values are obtained during runtime. I have set the field type to "enum" in ds.xml & on the server side fetch method i'm populating the field values with the code below, but the drop down is empty in both the ListGrid & the form. Could you help me find the issue? Also, is there is an alternate way of doing this. Thanks.

    dsRequest.getDataSource().getField("room").put("x","X");
    dsRequest.getDataSource().getField("room").put("y","Y");

    Below is my ds.xml-

    <DataSource
    ID="schedules"
    servertype="generic"
    >
    <fields>
    <field name="title" type="text" title="Title" length="128" required="true"/>
    <field name="presenter" type="text" title="Presenter" length="128" required="true"/>
    <field name="startDate" type="date" title="StartDate">
    </field>
    <field name="endDate" type="date" title="EndDate">
    </field>
    <field name="startTime" type="text" title="StartTime"/>
    <field name="durationSeconds" type="int" title="Duration(in secs)">
    <validators>
    <validator type="integerRange" min="0" max="300000" errorMessage="Enter a positive number between 0 and 300000"/>
    </validators>
    </field>
    <field name="room" type="enum" title="Room"/>
    </fields>

    <serverObject lookupStyle="factory" className="com.smartgwt.sample.server.ScheduleStoreFactory"/>
    </DataSource>

    #2
    See DataSourceField.valueMap for a static enum and listGridField/formItem.optionDataSource for a dynamic enum.

    Comment


      #3
      Appreciate your quick response.

      I tried what you suggested by creating a SelectItem & setting the optionDataSource to the datasource defined in the ds.xml. Shown below is the client code-

      final DataSource dataSource = DataSource.get("schedules");

      SelectItem selectItem = new SelectItem();
      selectItem.setDefaultToFirstOption(true);
      selectItem.setTitle("room");
      selectItem.setDisplayField("room");
      selectItem.setValueField("default room");
      selectItem.setOptionDataSource(dataSource);
      selectItem.setShowOptionsFromDataSource(true);

      And in the server side fetch operation, i have the code below-

      schdRoom = new ValueMap();
      try {
      schdRoom.add("X");
      schdRoom.add("Y");
      } catch(Exception e) {

      e.printStackTrace();
      }

      But adding the string to ValueMap ie, code line - schdRoom.add("X"); is throwing the exception below. I tried changing the ValueMap to Map, but that is displaying [Object Object] i the drop down. Ideas? Thanks!

      === 2010-04-05 14:59:41,724 [80-5] DEBUG AppBase - [builtinApplication.null] No public zero-argument method named '_null' found, performing generic datasource operation
      java.lang.Exception: No public zero-argument method named '_null and request does not specify a DataSource to use for a default operation - unable to proceed.
      at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:660)
      at com.isomorphic.application.AppBase.execute(AppBase.java:498)
      at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1219)
      at com.isomorphic.datasource.DataSource.add(DataSource.java:1479)
      at com.smartgwt.sample.server.Schedules.<init>(Schedules.java:97)
      at com.smartgwt.sample.server.ScheduleStore.fetch(ScheduleStore.java:132)
      at $ScheduleStoreService_127cf574cf1.fetch($ScheduleStoreService_127cf574cf1.java)
      at $ScheduleStoreService_127cf574cf0.fetch($ScheduleStoreService_127cf574cf0.java)
      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.isomorphic.base.Reflection.adaptArgsAndInvoke(Reflection.java:867)
      at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:444)
      at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:62)
      at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1216)
      at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:155)
      at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:106)
      at com.isomorphic.servlet.IDACall.doPost(IDACall.java:54)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at com.isomorphic.servlet.CompressionFilter.doFilter(CompressionFilter.java:248)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      at java.lang.Thread.run(Thread.java:637)

      Comment


        #4
        The idea is that any DataSource can be used as an optionDataSource - you optionDataSource should return data in the same format as any other DataSource. See also the docs for valueField and displayField, and the samples showing optionDataSources.

        Comment


          #5
          After i changed the data type of the enum field from ValueItem to LinkedHashMap in the server code & disabled ShowOptionsFromDataSource on the SelectItem, the exception is gone. But the enum field is displayed as [object, Object] in the drop down.

          I have defined a single datasource in the ds.xml that has text, date & enum fields. I'm using the same datasource for optiondatasource as well. Is that ok or do i need to define an other datasource with just the enum field in it for optiondatasource? I'm setting the title & displayField on the SelectItem to the field name defined in datasource/ds.xml. And am not setting the valueField.
          Pls correct this, if anything wrong.

          Comment


            #6
            I can't find any samples on using OptionDataSource with ds.xml for server side integration. Any pointers to it would be great!

            Comment


              #7
              You're over-complicating this. Do *exactly* what you're doing for any existing DataSource. Don't do anything different, don't use any variants of Maps, just return the data exactly as you have already successfully done for your main DataSource. That's it.

              Comment


                #8
                Hello, I followed your suggestion & changed the room field in my ds.xml to type "text", editorType "select" & optionDataSource "schedules", which is the same datasource in which this select item is defined in the ds.xml

                <field name="room" title="Room" type="text" editorType="select" required="true" optionDataSource="schedules" canEdit="false" displayField="room"/>

                And i have added a getter & setter for the room in the server code that deals with a simple string. But this is populating the drop down with duplicates as well. Is there a way to avoid duplicates?

                I'm trying to solve a different issue at the same time, I'm retrieving batches of records using data paging & each schedule record has 3 to 4 rooms associated with it dynamically which needs to be displayed in a drop down & also user has to be able to select multiple rooms by drag & dropping from one list to other. How can i do this? For this purpose i started using an enum & had getter/setter in the server code that deals with a Map, but that didn't either.

                Comment


                  #9
                  Remove the duplicates server-side by whatever means works for your persistence engine, eg, " select distinct" in SQL.

                  Your new problem sounds similar to the Master Detail Batch Load and Save sample.

                  Comment

                  Working...
                  X