Announcement

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

    DataSource + Collections

    I've been evaluating SmartClient Pro 7.0rc2 (not SmartGWT) and I can't find anywhere in the documentation or forums a clear example of mapping a Java POJO collection in a .ds.xml.

    An example is in order...

    Application.java
    Code:
    public class Application implements Serializable {
    
      List<Vehicle> vehicles;
    
      // getters & setters
    
    }
    Vehicle.java
    Code:
    public class Vehicle implements Serializable {
    
      private Integer year;
      private String make;
      private String model;
    
      // getters & setters
    
    }
    application.ds.xml
    Code:
    <DataSource ID="application">
    <serverObject ... />
    <fields>
      <!-- mgb: I'm not sure what to do here -->
      <field name="vehicles" multiple="true" />
      <field name="vehicle_year" type="integer" />
      <field name="vehicle_make" type="text" />
      <field name="vehicle_model" type="text" />
    </fields>
    Basically I need a DynamicForm where I can add 'n' tuples of (year,make,model) inputs which will get submitted in the 'saveData' operation once the form is submitted.

    Any help is appreciated!

    Thanks,
    mgbowman

    #2
    Right here.

    Comment


      #3
      Wow that was fast !!!

      So now I have this...

      application.ds.xml
      Code:
      <DataSource ID="application">
      <serverObject ... />
      <fields>
        <field name="vehicles" type="application_vehicle" title="Vehicles" multiple="true" />
      </fields>
      application_vehicle.ds.xml
      Code:
      <DataSource ID="application_vehicle">
      <fields>
        <field name="vehicle_year" type="integer" title="Year" />
        <field name="vehicle_make" type="text" title="Make" />
        <field name="vehicle_model" type="text" title="Model" />
      </fields>
      How do I define the DynamicForm such that I can display multiple tuples in the same form? Does it have to be separate forms?

      Example...
      Code:
      isc.DynamicForm.create({
        fields: [{
          name: "vehicles"
        }]
      });
      This give's me a form with
      Code:
      Vehicles
      
         Year : [__________]
         Make : [__________]
        Model : [__________]
      Note: I'm defining the form fields manually because my model is way more complex than this example and requires massive splitting.

      Thanks again!
      --mgbowman

      Comment


        #4
        In the example on the side, a ListGrid is used for editing multiple orderItems. This sample shows the pattern for adding new records.

        Otherwise, consider side-by-side grid and form editing, like this.

        Comment


          #5
          Thanks - I'm getting closer!

          If I use Collection<Vehicle> instead of List<Vehicle> I get a side-by-side Grid & Form automagically. I did not specify javaClass...

          DataSourceField.javaClass
          "When Java generics are used (for example the setter takes an argument is of type Collection<SomePOJO> or Map<KeyType,SomePOJO>, SmartClient will automatically attempt to convert inbound data to the type of the members of the Collection or values of the Map."

          This is a bit confusing since Collection is a super-interface of List - I think someone didn't do a type comparison correctly ;-) ... [shameful-plug]got an opening for a Java dev on the server-side components[/shameful-plug]. It should of recongnized List<Vehicle> as a Collection<Vehicle> and worked without having to change the property type from List to Collection.

          Now the last thing I need to integrate with this is the fact that year, make and model are dependent fields.

          The years available should come from a server-side RPC / DMI call. Once a year is selected, the models available for that year should be retrieved in the same fashion. Same goes for model but with the (year,make) as the query input.

          Any suggestions?

          Thanks again!!!
          --mgbowman

          Comment


            #6
            If that Collection vs List thing is real, it may already have been fixed - try the 8.0 beta now advertised at smartclient.com.

            As far as fetching make/model/year, see the Dependent Selects sample. This series of selects would all use application_vehicle as their optionDataSource, with different settings for valueField and displayField, and different getPickListCriteria() functions.

            Comment


              #7
              The Collection vs List is very real ;-)

              Regarding 8.0 beta, I'm rolling to production in the next few weeks and don't want to develop with a beta. As stated on the blog, I was also unhappy with the 7.0rc2 being considered final - please don't do that again!

              I'm 100% committed to purchasing the Pro version - I absolutely love SmartClient! If I purchase 7.0rc2 / 7.1 ... do I get 8.0 final for free? Do I have to purchase again? If so, what is the timeline for the 8.0 final release?

              I'm looking at the Dependant Selects now but I'm not sure how to customize the automagic form that was created. I believe it will have something to do with NestedEditorType / NestedListEditorType.

              Thanks again!
              --mgbowman

              Comment


                #8
                You can buy 8.0 licenses now, but to do so, call the sales line rather than using the shopping cart.

                Comment

                Working...
                X