Results 1 to 2 of 2

Thread: BindException - Global error with nested path

  1. #1
    Join Date
    Apr 2011
    Posts
    2

    Question BindException - Global error with nested path

    Hi all,

    I'm using the BindException class to validate some POJO, and retrieve ObjectError/FieldError to do some user readable message.

    I'm encountering a situation where I get a result which is not what's I would expect. Let's me explain.

    Let's say you have three classes, with association:

    Code:
    class MyTestClass {
    private ParentClass parent;
    } class ParentClass {
    private String name; private ChildClass child;
    } class ChildClass {
    private String name;
    }
    Now, you create a dummy MytestClass for test purpose:

    Code:
    MyTestClass testObject = new MyTestClass();
    ParentClass parent = new ParentClass();
    parent.setName("Parent's name");
    testObject.setParent(parent);
    
    ChildClass child = new ChildClass();
    child.setName("Child's name");
    parent.setChild(child);
    Do the validation of the model, using nested path:

    Code:
    Errors errors = new BindException(testObject, "xxxxx");
    errors.pushNestedPath("parent");
    errors.pushNestedPath("child");
    errors.reject("dummy code", "dummy message");
    errors.popNestedPath();
    errors.popNestedPath();
    With this validation, we're validating the ChildClass object and reject it as a whole (= Global error).

    If I iterate over ObjectError of the errors object, I get a global ObjectError:
    Error in object 'xxxxx': codes [dummy code.xxxxx,dummy code]; arguments []; default message [dummy message]
    It's normal because we used the reject (instead of rejectValue) method, but what's going on with the nested path? Is it ignored? Is it only relevant with rejectValue ?

    What I would expect is an error object indicating that it's the ChildClass object which is invalid and not MyTestClass, because the nested path has been defined like this before the reject method was called.

    So, is it a problem in BindException? Or I expect something which is wrong?

    Ampton.

    PS: Sorry if I did not post in the correct forum but I did not find a general section.

  2. #2
    Join Date
    Apr 2011
    Posts
    2

    Default

    Still no answer to my question ?

    Someone could explain me is my expectation is right or not? please.

    Ampton.

Posting Permissions

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