Announcement

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

    SelectItem in list grid showing ID on change instead of value

    Hi All,
    I am facing of problem of ID being displayed instead of value.

    Code:
    grid.setEditorCustomizer(customizer -> {
                if (customizer.getEditField().getName().equals("desc")) {
                    Record record = customizer.getEditedRecord();
                    final DataSource myDS = DataSource.get("myDS");
                    final SelectItem selectItem = new SelectItem();
                    selectItem.setOptionDataSource(myDS);
                    selectItem.setSortField("desc");
                    selectItem.setDisplayField("desc");
                    selectItem.setValueField("id");
    
                    selectItem.setWidth("100%");
                    selectItem.setAutoFetchData(false);
                    selectItem.setAllowEmptyValue(false);
                    selectItem.setAddUnknownValues(false);
                    return selectItem;
                }
    
                return customizer.getDefaultProperties();
            });
    Datasource:
    Code:
    <DataSource ID="myDS" serverType="hibernate"
        beanClassName="com.xyz.MyClass" lookupStyle="spring"
        beanFactory="org.springframework.beans.factory.BeanFactory"
        autoDeriveSchema="true" configBean="sessionFactory">
        <fields>
            <field name="id" type="long" align="left" hidden="true"
                primaryKey="true" />
            <field name="desc" type="text" align="left"/>
        </fields>
    
        <operationBindings>
            <binding operationType="fetch" outputs="id,desc" />
        </operationBindings>
    </DataSource>
    In edit mode I get the list in selectitem and on change works fine and displays desc. But as soon as I click outside the grid(Edit complete). The selectitem starts displaying ID. Any suggestions?
    Thanks in advance

    #2
    Do you have a displayField with includeFron set in the ID Field in your .ds.xml?

    Comment


      #3
      Thanks Blama ,

      No. My ID field is like below:
      Code:
       
         <field name="id" type="long" align="left" hidden="true"             primaryKey="true" />
      The desc field is String field in the java entity. I tried the below:

      Code:
       
         <field name="id" type="long" align="left" hidden="true"             primaryKey="true" displayField="desc" includeFrom="myDS.desc"/>   ​​​​​​​<field name="desc" type="text" align="left"/>
      And

      Code:
       
       <field name="id" type="long" align="left" primaryKey="true" displayField="name"/> <field name="name" includeFrom="desc" hidden="true"/>  <field name="desc" type="text" align="left"/>
      The above is throwing error and not populating the grid.

      From documentation the way is :

      Code:
       
       <field name="managerId" foreignKey="employee.id" displayField="managerName" />    <field name="managerName" includeFrom="employee.name" hidden="true"/>
      But I dont have any association here to include from another DS. Kindly suggest.

      Comment


        #4
        Hi,

        hard to read. Should be sth like this, see employees.ds.xml in BuiltInDS:
        Code:
        <field name="id" type="integer" hidden="true" primaryKey="true" />  ​​​​
        <field name="othertable_id" type="integer" foreignKey="othertable.id" displayField="othertable_desc" />  ​​​​
        <field name="othertable_desc" includeFrom="othertable.desc" />
        It's VERY unlikely that your PK field is also a FK field, like in your code. Again, see employees.ds.xml.

        Best regards
        Blama

        Comment


          #5
          Also, the othertable_id should most likely either be required="true" OR joinType="outer".

          Comment


            #6
            Thank Blama ,
            I don't know why and how should I use othertable.id and foreignKey. I dont have any foreign key association here. My class is like this :

            Code:
            class MyClass{
            Long id;
            
            String desc;
            
            //getter and setters
            
            }

            Comment


              #7
              Hi Blama ,

              The similar issue was faced by another person which was solved here.
              I am using smartGWT version 6.1-p20180801.
              I tried all the possible ways but still same issue.

              Can you please guide me to some solution.


              Thanks

              Comment


                #8
                Hi preeti_kanyal,

                sorry I can't. For me, using .ds.xml it just works. I don't have an idea what you are actually doing, so you'll have to wait for Isomorphic.

                Best regards
                Blama

                Comment


                  #9
                  We don't really add anything to add - Blama pointed out some ways in which your code appears to be nonsense. Right now, we can only recommend that you read up on DataSourceField.displayField and DataSourceField.includeFrom, as those topics fully explain how to manage ID and display values. In the unlikely case you think you've discovered a bug, let us know with runnable code that demonstrates the issue.

                  Note also: the thread you linked to is 7 years old, and even then, it was a very obscure bug that was found. This isn't an area where people are finding new bugs.

                  Comment


                    #10
                    preeti_kanyal I had the same issue when working with filters on a listGrid.

                    I found using
                    Code:
                    setForeignDisplayField(DISPLAY_FIELD)
                    was what I needed to display the displayField and avoid the ID being presented when working with an includeFrom listGridField .

                    NOTE: I used setFilterEditorProperties() on the listGridField with a SelectItem using setForeignDisplayField().

                    Hope this helps anyone else running into the same issue

                    Comment

                    Working...
                    X