Announcement Announcement Module
Collapse
No announcement yet.
BindException - Global error with nested path Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Still no answer to my question ?

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

    Ampton.

    Comment

    Working...
    X