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?
Spring will only call the validation on the bean set as the model for the view-state.
The following will only validate
user:You will need to create an object that encapsulates user and address and use it as as model (and call the validation method of
UserandAddressin it’s validation method).