Announcement Announcement Module
Collapse
No announcement yet.
Adding property that is not present on the form object to the form model ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding property that is not present on the form object to the form model ?

    Hello

    I'm trying to add a property that is not present on the form object to my form model object.

    The following code does work to some extend but the default commit button in my view does not get enabled when changes are made to the custom property through the UI binding where as changes to "real" object properties does enable the commit button.

    Code:
    	private JCheckBox createManualTrack;
    
    	private boolean createMan = false;
    
    	private ValueModel createManual = new ValueHolder(createMan);
    
    protected JComponent createFormControl() {
    ...
    		getFormModel().add(
    				"createManual",
    				createManual,
    				new DefaultFieldMetadata(getFormModel(),
    						new FormModelMediatingValueModel(createManual),
    						Boolean.class, false, null));
    		createManualTrack = (JCheckBox) formBuilder.add("createManual")[1];
    Any hints?

    I can not find any test cases for
    Code:
    ValueModel add(String propertyName, ValueModel valueModel, FieldMetadata fieldMetadata);
    Thanks
    carsten

  • #2
    Should have done a search. I guess this thread http://forum.springsource.org/showth...JTable-Binding got the answer.

    Comment


    • #3
      Do make it work I had to use reflection :-( like this

      Code:
      			FormModelMediatingValueModel mediatingValueModel = new FormModelMediatingValueModel(
      					createManual);
      			DefaultFieldMetadata metadata = new DefaultFieldMetadata(
      					getFormModel(), mediatingValueModel, Boolean.class, false,
      					null);
      			Class<AbstractFormModel> abstractFormModelClass = AbstractFormModel.class;
      			Field childStateChangeHandlerField = abstractFormModelClass
      					.getDeclaredField("childStateChangeHandler");
      			childStateChangeHandlerField.setAccessible(true);
      			PropertyChangeListener childStateChangeHandler = (PropertyChangeListener) childStateChangeHandlerField
      					.get(getFormModel());
      			metadata.addPropertyChangeListener(FieldMetadata.DIRTY_PROPERTY,
      					childStateChangeHandler);
      			getFormModel().add("createManual", mediatingValueModel, metadata);
      			createManualTrack = (JCheckBox) formBuilder.add("createManual")[1];

      Comment


      • #4
        Go get revert on the form model to work I had to add:

        Code:
        			Field mediatingValueModelsField = abstractFormModelClass
        					.getDeclaredField("mediatingValueModels");
        			mediatingValueModelsField.setAccessible(true);
        			Map mediatingValueModels = (Map) mediatingValueModelsField
        					.get(getFormModel());
        			mediatingValueModels.put("createManual", mediatingValueModel);

        Comment

        Working...
        X