No announcement yet.
  • 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.


    Below is my ds.xml-

    <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 name="endDate" type="date" title="EndDate">
    <field name="startTime" type="text" title="StartTime"/>
    <field name="durationSeconds" type="int" title="Duration(in secs)">
    <validator type="integerRange" min="0" max="300000" errorMessage="Enter a positive number between 0 and 300000"/>
    <field name="room" type="enum" title="Room"/>

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

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


    • #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.setValueField("default room");

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

      schdRoom = new ValueMap();
      try {
      } catch(Exception e) {


      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(
      at com.isomorphic.application.AppBase.execute(
      at com.isomorphic.datasource.DSRequest.execute(
      at com.isomorphic.datasource.DataSource.add(
      at com.smartgwt.sample.server.Schedules.<init>(
      at com.smartgwt.sample.server.ScheduleStore.fetch(
      at $ScheduleStoreService_127cf574cf1.fetch($
      at $ScheduleStoreService_127cf574cf0.fetch($
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(
      at java.lang.reflect.Method.invoke(
      at com.isomorphic.base.Reflection.adaptArgsAndInvoke(
      at com.isomorphic.datasource.DataSourceDMI.execute(
      at com.isomorphic.datasource.DataSourceDMI.execute(
      at com.isomorphic.datasource.DSRequest.execute(
      at com.isomorphic.servlet.IDACall.handleDSRequest(
      at com.isomorphic.servlet.IDACall.processRequest(
      at com.isomorphic.servlet.IDACall.doPost(
      at javax.servlet.http.HttpServlet.service(
      at com.isomorphic.servlet.BaseServlet.service(
      at javax.servlet.http.HttpServlet.service(
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(
      at com.isomorphic.servlet.CompressionFilter.doFilter(
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(
      at org.apache.catalina.core.StandardWrapperValve.invoke(
      at org.apache.catalina.core.StandardContextValve.invoke(
      at org.apache.catalina.core.StandardHostValve.invoke(
      at org.apache.catalina.valves.ErrorReportValve.invoke(
      at org.apache.catalina.core.StandardEngineValve.invoke(
      at org.apache.catalina.connector.CoyoteAdapter.service(
      at org.apache.coyote.http11.Http11Processor.process(
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(


      • #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.


        • #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.


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


            • #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.


              • #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.


                • #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.