Announcement

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

    Strange bug in DynamicForm

    Hi,

    I encountered the following problem (bug?) when using DynamicForms:

    Here is my class:

    Code:
    class NewOperatorForm extends DynamicForm {
    		
    		NewOperatorForm() {
    			TextItem			loginItem = new TextItem(DSOperator.LOGIN, "Login");
    			TextItem		nameItem = new TextItem(DSOperator.NAME, "Name");
    			TextItem			departmentItem = new TextItem(DSOperator.DEPARTMENT, "Department");
    			TextItem			emailItem = new TextItem(DSOperator.EMAIL, "Email");
    			SelectItem			bunitItem = new SelectItem(DSOperator.BUNIT_ID, "Business Unit");
    			
    			bunitItem.setOptionDataSource(DataSource.get(DSBusinessUnit.DS_NAME));
    			bunitItem.setAutoFetchData(true);
    			bunitItem.setDefaultToFirstOption(true);
    			
    			this.setDataSource(DataSource.get(DSOperator.DS_NAME));
    			this.setItems(bunitItem, loginItem, nameItem, departmentItem, emailItem);
    			
    			Record r = new Record();
    			this.editNewRecord(r);
    		}		
    	}
    You can notice that the SelectItem gets the data from another datasource and that setDefaultToFirstOption(true) is called.

    The first time I create and show an instance of this dynamicform. Everything is ok: the SelectItem fetches all the data and the first item is selected by default (ID: 1).

    The second time (though it's an other instance), very surprisingly, the SelectItem does contain all the items but the first one is not selected (it's blank)... but the value is instead set into the second item of the form (I've got the "1" value in my text field). This seems very odd but I did not add any code which could lead to such a behaviour...

    Thanks a lot for your help!

    Thomas

    #2
    Thanks for the notification. We'll check this out.
    In the meantime - we'd hazard a guess that the problem is to do with the logic which reuses pickLists across multiple form items. If you set cachePickListResults to false, this will likely work around the issue.

    Regards
    Isomorphic Software

    Comment


      #3
      A follow up on this: We realize we're not seeing an obvious way to reproduce the problem on our end.
      Can you put together a standalone test case which demonstrates the problem? Ideally this should be an EntryPoint class which we can drop into an existing project and run on our end without modification.
      You'd probably want to have this class contain
      - your custom subclass (with any dependencies on external resources removed) as an inner class
      - a client-only DataSource [or you could use one of the shipped samples' dataSources]
      - code in the onModuleLoad class to actually create and display a couple of instances of your DynamicForm subclass.

      Regards
      Isomorphic Software

      Comment


        #4
        Well, first, I confirm that if I set cachePickListResults to false, the problem is gone... but I suppose you'll understand that I would prefer to cache this data. Anyway, if it helps you to track the problem ^^

        Regarding a stand-alone example, here is what I could do (the datasource is the SupplyItem.data.xml I found in your showcase. I could only reproduce the problem with a ComboBoxItem instead :-/

        Here is the dynamic form:

        Code:
        public class SelectItemDebug extends DynamicForm {
        
        	public SelectItemDebug() {
        		DataSource supplyItemDS = ItemSupplyXmlDS.getInstance();  
        		  
                ComboBoxItem itemName = new ComboBoxItem("itemName");  
                itemName.setTitle("Item Name");  
                itemName.setPickListWidth(250);  
                
                itemName.setOptionDataSource(supplyItemDS);
        
                itemName.setAutoFetchData(true);
                itemName.setDefaultToFirstOption(true);
                itemName.setCachePickListResults(true);
        
                FormItem textItem  = new FormItem("test");
                ButtonItem closeItem = new ButtonItem("close");
                closeItem.addClickHandler(new ClickHandler() {
        			
        			@Override
        			public void onClick(ClickEvent event) {
        				hide();
        				destroy();
        			}
        		});
                this.setPadding(50);
                this.setItems(itemName, textItem, closeItem);  
                
                editNewRecord();
        	}
        }
        Here is the app entry point code:

        Code:
        VLayout panel = new VLayout();
        				Button showButton = new Button("Show Form");
        				showButton.addClickHandler(new ClickHandler() {
        					
        					@Override
        					public void onClick(ClickEvent event) {
        						new SelectItemDebug().show();
        					}
        				});
        				panel.addMember(showButton);
        				panel.setWidth100();
        				panel.setHeight100();
        				panel.draw();
        If you click on the button, the form opens, the first option is selected. (OK). Close the form.
        If you click on the button again, the first option is not selected at all.. (KO). However, the value is not copied to the second text item.

        If I set the option datasource to my SQL one (Simple ID/Value), the same problem happens + value of the first item (ID) copied to the text item (with a SelectItem this time).

        The modified dynamic form:

        Code:
        public class SelectItemDebug extends DynamicForm {
        
        	public SelectItemDebug() {
        		DataSource supplyItemDS = ItemSupplyXmlDS.getInstance();  
        		  
                SelectItem itemName = new SelectItem("itemName");  
                itemName.setTitle("Item Name");  
                itemName.setPickListWidth(250);  
                
                //itemName.setOptionDataSource(supplyItemDS);
                itemName.setOptionDataSource(DataSource.get("test"));
                itemName.setValueField("ID");
        
                itemName.setAutoFetchData(true);
                itemName.setDefaultToFirstOption(true);
                itemName.setCachePickListResults(true);
        
                FormItem textItem  = new FormItem("test");
                ButtonItem closeItem = new ButtonItem("close");
                closeItem.addClickHandler(new ClickHandler() {
        			
        			@Override
        			public void onClick(ClickEvent event) {
        				hide();
        				destroy();
        			}
        		});
                this.setPadding(50);
                this.setItems(itemName, textItem, closeItem);  
                
                editNewRecord();
        	}
        }
        The "Test" datasource (loaded, of course)

        Code:
        <DataSource
            ID="test"
        	serverType="sql"
        	tableName="SEC_BUSINESS_UNIT"
        >
            <fields>
           		<field name="ID" type="integer"	hidden="true" primaryKey="true" />
                <field name="NAME" type="text" title="Name"/>
            </fields>
            
        </DataSource>


        Hoping it helps...
        Thomas

        Comment


          #5
          Hi there,

          are there any news about this test case ?
          Thanks,

          Thomas

          Comment


            #6
            We aren't seeing the first issue (the problem where the first option is never selected) in our testing, but we did see the second problem (where the TextItem would pick up the value from the first item - ComboBox or Select)

            We've made a change to both the 4.0p and 4.1d branches which we believe resolves this problem. Please try the next nightly build, dated Jan 28 or above and let us know if you still see bad behavior here

            Thanks
            Isomorphic Software

            Comment

            Working...
            X