Results 1 to 4 of 4

Thread: PropertyEditor registered w. propertyPath not found by BeanWrapper.convertIfNecessary

  1. #1
    Join Date
    Sep 2008
    Posts
    4

    Default PropertyEditor registered w. propertyPath not found by BeanWrapper.convertIfNecessary

    Hello,

    I'm trying to convert the value of a Collection property manually using BeanWrapperImpl.convertIfNecessary(Object value, Class requiredType).
    The value is a comma-delimited String, so I registered a PropertyEditor registry.registerCustomEditor(Set.class, "materialTypes", materialTypeSetEditor)
    to convert it into a Set of material types (Enum). But using the method mentioned above (no parameter for the property name available)
    the custom editor cannot be found and the default editor is used. Is there a way around the problem? Is this the right way to the conversion at all?

    Some background information:
    Until now we used DataBinder.bind() to apply all changes. Now, we have to create history entries including
    old and new value for each changed property. To decide if the value changed, I need to compare old and
    new value before I create a history entry and to do this I have to convert the new value before.

    Again: is this the right way to this at all?


    Thanks in advance!

  2. #2

    Default

    Your binding error sounds like there is a typo or something. Do the values on the form make the .equals() method on your object (Enum?) return true? Pls post your property editor code and also validate that the form field has the correct name.

    As far as making history entries, I'm sure you can cache a copy of your original form object and compare the properties to discover differences and therefore 'history' entries.

  3. #3
    Join Date
    Sep 2008
    Posts
    4

    Default

    Everything worked properly with the DataBinder and the PropertyEditor wasn't changed, so I don't think it can be a typo. The problem occurs since we are using the BeanWrapperImpl to convert the value manually.

    The PropertyEditor code:
    Code:
    final class MaterialTypeSetPropertyEditor extends PropertyEditorSupport {
    
        /**
         * {@inheritDoc}
         */
        @Override
        public void setAsText(String text) {
            if (StringUtils.isNotEmpty(text)) {
                String[] materialTypes = TokenizerUtil.split(text);
                Set<MaterialType> result = new HashSet<MaterialType>();
                for (String matType : materialTypes) {
                    MaterialType materialType = MaterialType.valueOf(matType);
                    if (materialType == null) {
                        throw new IllegalArgumentException("Material type ["
                                + materialType + "] not found");
                    }
                    result.add(materialType);
                }
                setValue(result);
            } else {
                setValue(null);
            }
        }
    }
    Yes, we think about cloning the original entity before applying the changes, but we hoped that there might be another/a better solution to this problem.
    Last edited by marlov; Sep 5th, 2008 at 06:56 AM. Reason: just formatted the code part

  4. #4
    Join Date
    Sep 2008
    Posts
    4

    Default

    Hello,

    does anyone have another solution to my problem? I really would prefer not to create a deep-copy of each entity!

    Thanks in advance!

Tags for this Thread

Posting Permissions

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