Announcement

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

    ComboBoxItem - item not selected if form's field contains record, not id

    Hello,



    I have two data sources - brand and car. Each car has field brand, that is of type brand. This maps well with my server side ORM data mapping.

    Code:
    <DataSource
        ID="brand"
        serverType="generic"
      >
    
      <fields>
        <field name="id" type="text" hidden="true" primaryKey="true"/>
        <field name="name" type="text" title="Name" />
      </fields>
      ...
    
    </DataSource>
    Code:
    <DataSource
        ID="car"
        serverType="generic"
      >
    
      <fields>
        <field name="id" type="text" hidden="true" primaryKey="true"/>
        <field name="name" type="text" title="Name" />
    
        <field name="brand" type="brand" title="Brand" />
        
      </fields>
      ...
    
    </DataSource>
    In UI I have a DynamicForm, that set with car DataSource. Inside I have a field of type ComboBoxItem with OptionDataSource: brand and value field = "id" and display field = "name".

    My problem is when I open an existing car within this form. I can't make ComboBoxItem to select specified brand.

    I'm using Smart GWT Pro 2.4.

    Any suggestions ?

    Best Regards,
    paco

    #2
    After some debuging I found out that this is a lack in SmartGWT's API. Very bad, because this is a common use case when ORM is used on the server.

    In order to proceed with the project I did an ugly patch, adding an alias to the brand.id in the car data source:

    Code:
    <DataSource
        ID="car"
        serverType="generic"
      >
    
      <fields>
        <field name="id" type="text" hidden="true" primaryKey="true"/>
        <field name="name" type="text" title="Name" />
    
        <field name="brand" type="brand" title="Brand" />
        <field name="brand.id" type="text" hidden="true" valueXPath="brand/id" />
      </fields>
      ...
    
    </DataSource>
    Now if I set the name of the ComboBoxItem to be brand.id, selection in brand ComboBoxItem is working fine.

    Still leaves the case, that before submit I should manually get the selected record from the combo box and set it in the car record's brand field. This patch breaks the data binding idea, but at least is something working for now ....

    Comment


      #3
      This is not a lack. What you want to deliver to the client may be either the id, entire subobject or both. SmartGWT supports both types of fields, and in this case you want to deliver the id but have specified that the field is the type of the entire subobject.

      For more information on handling for typical ORMs, see the JPA & Hibernate Relations overview in JavaDoc.

      Comment


        #4
        Hello,

        Thanks for the reply. I know how to deliver to the client id or subobject - this is NOT a problem. The problem is, that if I work with subobject (what is my backend domain object model) ComboBoxItem can't handle the case. When combo box is supposed to show selected subobject it issues a server request with following criteria:

        Code:
        criteria:{
          id: {
             id: 1,
             name: "bla, bla.."
          }
        }
        which of course is not correct. The correct criteria would be:

        Code:
        criteria:{
          id: 1
        }
        But this happens, only if I deliver id to the ComboBoxItem, not subobject.

        I was expecting, that there is some mechanism in ComboBoxItem to switch or auto detect what mode is used - id or subobject, but I can't find or make it work.

        That's why I processed with the patch, from my second post in this thread.

        Best Regards,
        paco

        Comment


          #5
          We don't know of a scenario where the ComboBox will generate criteria like you show, but then, you are using a very old version (you should upgrade as soon as possible).

          Also your fieldName is invalid (brand.id) - field names must be identifiers.

          Comment

          Working...
          X