This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Ranch Hand
Posts: 193
Mac OS X Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jiafan Zhou
Ranch Hand
Posts: 193
Mac OS X Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jiafan Zhou
Ranch Hand
Posts: 193
Mac OS X Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Jiafan Zhou
Ranch Hand
Posts: 193
Mac OS X Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a solution myself now. 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().

After those amazing square brackets, my code works perfectly.

Regards,
Jiafan
 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic