Results 1 to 4 of 4

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

  1. #1

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

    Default

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

  3. #3

    Default

    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];

  4. #4

    Default

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

Posting Permissions

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