Announcement Announcement Module
Collapse
No announcement yet.
Does setNestedPath() method works with a sub-object as a Collection type Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Does setNestedPath() method works with a sub-object as a Collection type

    Suppose I have Class A has a collection type referencing Class B, Class B class a List referencing Class C.

    In this case, how can I set the nested path, I am confused.

    e.g.

    aaa.bbb.ccc (does bbb needs to be concrete class object, how about collection type)?

    Thanks.

  • #2
    To be clear on this, following code is an example.

    A.class
    Code:
    ...
    Collection<B>   bbb;
    ...
    B.class
    Code:
    ...
    List<String>   ccc;
    ...
    Note that each bean has a corresponding custom validation class begins with V.

    Code:
    String oldPath = errors.getNestedPath();
    errors.setNestedPath(oldPath + "bbb"); // is this correct?
    
    // run the validation
    ...
     
    // reset the old path
    errors.setNestedPath(oldPath);
    Then whenever the validation is invoked, there is an error message shown on the console. I think this is because Spring Framework cannot correctly pass the "bbb.ccc" because bbb is a Collection type defined in A.class.

    Also note that if the bbb is not a collecton type, everything works fine.

    Need helps on this touch question.

    Thanks,
    Jiafan

    Comment


    • #3
      the error message is shown below.

      Mon Aug 27 14:18:17 BST 2007 - Ignoring item test_case, notReadablePropertyException: An unrecoverable error has occurred: Invalid property 'bbb.ccc' of bean class [A]: Bean property 'bbb.ccc' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? (ccc).

      I think this issue also reveals a bigger question on using the setNestedPath(String) method, when the subtree contains a collection type object, does a simple String like "bbb" be able to let Framework find the correct property for the Error message?
      Last edited by JiafanZhou; Aug 27th, 2007, 09:04 AM.

      Comment


      • #4
        It follows standard Java bean notation. aaa.bbb.ccc means aaa.getBbb().getCcc(). For collections the notation changes to aaa.bbb[index].ccc and is translated to aaa.getBbb().get(index).getCcc().

        Joerg

        Comment


        • #5
          Thanks for pulling for from my thinking's lair. After your suggestion that added those amazing square brackets, my code works perfect now.

          Thanks again.

          Regards,
          Jiafan

          Comment

          Working...
          X