Reputation: 3920
Problem with validation
I would have run the validation when the method "registered"
In webflow: ...
<transition on="registered" to="registeredAction" bind="true" validate="true" />
...
My model looks like this:
class User {
private String name;
private String surname;
...
private List <address> addresses;
...
public void validateRegistered (ValidationContext context) {
Context.getMessageContext MessageContext messages = ();
if (name == null) {
messages.addMessage (new MessageBuilder (.) error (). source ("name".) code (MessageCodes.Error.REQUIRED.) build ());
}
}
In Address class
Class Address {
private String street;
private String city;
public void validateRegistered (ValidationContext context) {
Context.getMessageContext MessageContext messages = ();
if (street == null) {
messages.addMessage (new MessageBuilder (.) error (). source ("street".) code (MessageCodes.Error.REQUIRED.) build ());
}
}
Executing the action and gets errors in the validator for the User class, but not for Class Address
Anyone knows why this is so?
Upvotes: 3
Views: 5546
Reputation: 1788
The other answer is correct about WebFlow only validating one model object, however you do not need to create another object. You can do nested validation. Just call the Address validator inside your User validator. Once you're inside your validator routine, you can bounce around and do pretty much whatever you need.
Upvotes: 0
Reputation: 11047
Spring will only call the validation on the bean set as the model for the view-state.
The following will only validate user
:
<view-state id="something" view="something.jsp" model="user">
<transition on="registered" to="registeredAction" bind="true" validate="true" />
</view-state>
You will need to create an object that encapsulates user and address and use it as as model (and call the validation method of User
and Address
in it's validation method).
Upvotes: 6