Results 1 to 5 of 5

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

  1. #1
    Join Date
    Aug 2006
    Posts
    9

    Default 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. #2
    Join Date
    Aug 2006
    Posts
    9

    Default

    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

  3. #3
    Join Date
    Aug 2006
    Posts
    9

    Default 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 at 09:04 AM.

  4. #4
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    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
    This post can contain insufficient information.

  5. #5
    Join Date
    Aug 2006
    Posts
    9

    Default

    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

Posting Permissions

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