Announcement

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

    Possible to show combobox editor in ListGrid fields?

    Hi everyone,

    Is it possible to have a ListGrid connected to a JPA datasource to show for some of its fields a combobox from a linked table instead of a text box?

    For example, my Customer datasource includes a “CustomerTypeID” which is a foreign key into the “CustomerTypes” table. The idea would be to show a combobox to choose from one entry in CustomerTypes instead of showing the CustomerTypeID in the list grid. (an extremely common technique in database front-end GUIs)

    The “Large Value Map” SmartGWT EE example at http://www.smartclient.com/smartgwtee/showcase/#large_valuemap_sql does exactly what I need, but it is unfortunately for the DataSource.serverType=”sql”, while in my case the server datasource handler has serverConstructor="com.isomorphic.jpa.JPADataSource" in order to get JPA persistence working.

    What is the best way to accomplish this commonly-used GUI technique under SmartGWT-EE & JPA? Would it be better to insert a correctly configured selectItem into the grid using the “createRecordComponent()” technique?

    Many thanks for any hint you can offer... and *fantastic* work with SmartGWT!!

    Jean-Pierre

    #2
    The JPA equivalent of a join is to declare a standard JPA relation and configure eager fetching for it.

    Then in your DataSource, declare a <field> for the name/title you want to show for CustomerTypes objects, and use field.valueXPath to reach into the related object and retrieve it.

    Comment


      #3
      Hi Administrator,

      Many thanks for taking the time for this useful hint. I was about to begin approach via createRecordComponent() technique.

      I'm studying the technique and have located cases in SmartGWT EE showcase sample using valueXPath...

      I understand this would show in the ListGrid the textual value of my CustomerTypes.CustomerTypeName instead of CustomerTypeID... but would it present an editable combobox so the user can choose from an entry in CustomerTypes during editing?

      Thanks again!

      Jean-Pierre

      Comment


        #4
        That piece is data-provider agnostic and is just a matter of specifying foreignKey on a field. There's some good sample code in this thread including the right JPA annotations.

        Comment


          #5
          Hi Administrator, thanks again.

          To clarify, you mentioned the use of both foreignKey and valueXPath. Just to make sure I'm on the right track as this is complicated and error-prone, is the following technique with two fields the recommended way to get the combo-box editing to work in the grid?

          1. the value to display for the related object. This uses valueXPath and is hidden.

          2. the id of the related object. This is declared as a foreignKey and sets displayField to the name of the field containing the display value. This will automatically become a SelectItem when you bind to a form, and use the optionDataSource functionality to retrieve values from the related DataSource.

          (In other words, it would work equally between a ListGrid and a DynamicForm to give the user experience I expect?)

          Jean-Pierre

          Comment


            #6
            Right.

            Not sure which part of this is complicated and error prone. True, we can't make JPA as simple as SQL since they require you to write a bean and annotate it for persistence. But the binding to JPA ends up as two lines.

            Comment


              #7
              Hi, I have studied this for hours and have tried dozens of permutations, but still cannot make this work correctly. The closest I get is from the ds.xml code below.

              <field name="personEmail" type="text" hidden="true" valueXPath="person/email"/>
              <field name="personId" title="User Email" displayField="personEmail" foreignKey="personId"/>

              (This is from a ListGrid displaying "Conference" items, with the combo box field I want to choose from a list of persons from the Persons table linked in the above.)

              The above gets nearly the perfect behavior one would expect from a combo box in a grid field linked to another table BUT when I expand I only get the same number of choices in the expanded combo box than there are unique in the ListGrid. (Meaning, if there are fifty entries in the "Persons" table but only 6 Persons are show in the Conference list grid, when I expand the combo box I only get the 6 persons, not the 50 I'd expect)

              When I set as below, I do get the 50 entry combo box expanding, but the combo box is completely blank!

              <field name="personEmail" type="text" hidden="true" valueXPath="person/email"/>
              <field name="personId" title="User Email" displayField="personEmail" foreignKey="person.personId"/>

              I have pored over the forums, the links you sent, the documentation and the samples. The JPA server side works fine and I can travers the object tree well and the database records appear fine.

              Can someone hint to me toward a sample that has this really important ListGrid technique working?

              Grasping at staws!

              Jean-Pierre

              Comment


                #8
                Hi Jean,

                Please understand, the ComboBoxItem has no idea that your server uses JPA. It is communicating purely through the DataSource protocol. So you already have an example of this working properly because the SQL example works properly - you just need to return equivalent data.

                Your first set of declarations would be expected to behave exactly as it does because the foreignKey does not specify a related DataSource, just a field name (personId). So this returns unique personId values in the current DataSource.

                The second declaration looks correct, but what do you mean by "I do get the 50 entry combo box expanding, but the combo box is completely blank!"? What's blank, the drop down list of values? If so, this means the data being returned by the server doesn't have values for the personEmail field. You can see this in the RPC tab of the Developer Console.

                Comment


                  #9
                  Hi Administrator,

                  It works! Thanks for taking the time!

                  For those following this thead, the working solution is:

                  <field name="email" type="text" hidden="true" valueXPath="person/email"/>
                  <field name="personId" title="Person" displayField="email" foreignKey="person.personId"/>

                  Where 'email' is the property from my foreign table "Person" and personId the foreign key into that table. All getters & setters are defined, so in this case to display the emails from the remote table via 'valueXPath', Conference.getPerson().getEmail() is called.

                  Now I have a problem of editing showing only the previous edit instead of the last one... I'm tracing it through but it's because JPA & Hibernate are not updating my "Person" object fast enough when setPersonId() is called... so when the client requests getPerson() it still gets the previous version of the Person object, and not the new one as expected. (This work fine if I show another recordset and show that one back)

                  Thanks again! You guys rock! :)

                  Jean-Pierre

                  Comment

                  Working...
                  X