Announcement Announcement Module
No announcement yet.
PropertyEditor registered w. propertyPath not found by BeanWrapper.convertIfNecessary Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

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


    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
    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
      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:
      final class MaterialTypeSetPropertyEditor extends PropertyEditorSupport {
           * {@inheritDoc}
          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");
              } else {
      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, 06:56 AM. Reason: just formatted the code part


      • #4

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

        Thanks in advance!