Announcement Announcement Module
Collapse
No announcement yet.
Getting dirty values from form on commit? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting dirty values from form on commit?

    Hello

    How do I get the dirty values from a formmodel up on commit?

    Maybe RCP-560 fixes it ?

    But I can not figure how.

  • #2
    This seems to work but does it not feel good. Are there any other way of doing this?

    Code:
    @Override
    	public void commit() {
    try {
    	Field dirtyValueAndFormModelsField = AbstractFormModel.class
    			.getDeclaredField("dirtyValueAndFormModels");
    	dirtyValueAndFormModelsField.setAccessible(true);
    	HashSet dirtyValueAndFormModels = (HashSet) dirtyValueAndFormModelsField
    			.get(this.getFormModel());
    
    	ValidatingFormModel formModel = getFormModel();
    	for (Object o : dirtyValueAndFormModels) {
    		if (o instanceof FieldMetadata) {
    			Set<String> fNames = formModel.getFieldNames();
    			for (String s : fNames) {
    				if (o == formModel.getFieldMetadata(s)) {
    					System.out.println("Changed " + s + " to "
    							+ formModel.getValueModel(s).getValue());
    						}
    					}
    				}
    			}
    			super.commit();
    		} catch (Exception e) {
    			// log.error("",e);
    			e.printStackTrace();
    		}
    	}

    Comment


    • #3
      Ok, I did NOT see that. That's really nasty code...

      If you know which properties you need to monitor, you can add a listener on that property and monitor value changes.

      Can you give me a use case when you'd want to use this 'feature'.

      Comment


      • #4
        I did try:

        Code:
        	Set<String> fNames = formModel.getFieldNames();
        	for (String s : fNames) {
        	DirtyTrackingValueModel v = (DirtyTrackingValueModel) formModel
        				.getValueModel(s);
        	if (v.isDirty()) {
        		System.out.println("[Changed " + s + " to " + v.getValue()
        					+ "]");
        		}
        	}
        without luck. Teh cast to DirtyTrackingValueModel fails.

        Use Case:

        I'm trying to use spring rcp to produce a new front end to a legacy system that uses a protocol like this:

        xttp://.../update?name1=value1&name2=value2...

        the protocol requires/assumes that the client only sends values that has changed.

        Being lazy I'm trying to come up with a generic way of doing this for all the forms I have to build.

        Comment


        • #5
          Let's see... this might work...

          Code:
          Set<String> fNames = formModel.getFieldNames();
          for(String fName : fNames)
          {
              FieldMetaData fmd = formModel.getFieldMetaData(fName);
              if(fmd != null && fmd.isDirty())
              {
                   // do something
              }
          }

          Comment


          • #6
            Thanks, that did it.

            Comment

            Working...
            X