Results 1 to 6 of 6

Thread: Getting dirty values from form on commit?

  1. #1

    Default 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. #2

    Default

    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();
    		}
    	}

  3. #3
    Join Date
    Mar 2007
    Location
    Oudenaarde
    Posts
    294

    Default

    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'.
    MSN: PM me please
    Skype: doclo_lieven

    Spring Rich Client Project Lead

  4. #4

    Default

    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.

  5. #5
    Join Date
    Mar 2007
    Location
    Oudenaarde
    Posts
    294

    Default

    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
        }
    }
    MSN: PM me please
    Skype: doclo_lieven

    Spring Rich Client Project Lead

  6. #6

    Default

    Thanks, that did it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •