Announcement

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

    DynamicForm invalidateCache

    Dear Support,

    I would like to know how you recommend to do the following:
    - Have a DynamicForm initialized with initial data (autofetched from given criteria)
    - Have a simple way to refresh the data

    Here is a simple example which mimics what I tried... The initial data is correct, but the invalidateCache() call does not trigger a new fetch when I click the button (did check the dev console)...

    The datasource:
    Code:
    <DataSource
        ID="reg_decision"
    	serverType="sql"
    	tableName="REG_DECISION"
    	useAnsiJoins="true"
    >
        <fields>
        	<field name="ID" type="integer" hidden="true" primaryKey="true"/>
        	<field name="CUSTOMER_ID" type="integer" hidden="true" foreignKey="cif_customer.ID"/>
        	<field name="REGULATION_ID" type="integer" hidden="true" foreignKey="reg_regulation.ID" />
        	<field name="REGULATION" type="text" includeFrom="reg_regulation.NAME" />
        	<field name="ANSWER_ID" type="integer" hidden="true" foreignKey="reg_answer.ID" joinType="outer"/>
        	<field name="CLASSIFICATION" type="text" includeFrom="reg_answer.NAME" />
        	<field name="CLASSIFICATION_DATE" type="date" nativeName="CREATED" />
        </fields>
        
    </DataSource>
    The small example:

    Code:
    public class Test extends VLayout {
    	
    	public Test() {
    		final DynamicForm test = new DynamicForm();
    		test.setDataSource(DataSource.get("reg_decision"));
    		Criteria criteria = new Criteria("CUSTOMER_ID", "3");
    		criteria.addCriteria("REGULATION", "XXX");
    		test.setAutoFetchData(true);
    		test.setInitialCriteria(criteria);
    
    		this.addMember(test);
    		Button button = new Button("Update");
    		button.addClickHandler(new ClickHandler() {
    			
    			@Override
    			public void onClick(ClickEvent event) {
    				test.invalidateCache();
    			}
    		});
    		
    		this.addMember(test);
    		this.addMember(button);
    		
    	}
    }
    Thank you very much for your help,

    Thomas

    #2
    DynamicForm does not have a "cache" per se, just the current values, as possibly modified by the user.

    To get the latest values, just use DataSource.fetchData() and call editRecord() in the callback.

    Be sure to consider the case of the user having modified values, which can be detected with dynamicForm.valuesHaveChanged().

    Comment


      #3
      This all makes sense! Thank you very much for your quick help!

      Regards,
      Thomas

      Comment

      Working...
      X