views:

83

answers:

1

I have a remote EJB with a method that validates an object (returning true or false). I want to be able to pass it an ArrayList object and have the EJB load it with the errors encountered during validation, while still receiving true/false as result.

How can I do this? So far, I can send it the list, and it's affected on server side, but the original list is not modified on client side.

+1  A: 

That's because when the list is sent over the wire to the bean, a copy must necessarily be made, because the list is moved from one JVM to another. Unlike with a normal method, it's not the same list. I don't know how it would work with local beans, but there's not other way with remote beans.

I suggest you have the bean return the list and if that's empty, the object is valid.

For example:

public List<String> methodWithValidation(Object input) {
    List<String> errors = new java.util.ArrayList<String>();
    //various validation tests, each adding a message on fail

    return errors;
}

And the calling method would do this:

List<String> errors = bean.methodWithValidation(object);
if(!errors.isEmpty()) {
    //error logic
} else {
   //continue
}
sblundy