Action-validation.xml in struts2 (open different pages when validation fails on different fields in validation.xml file)
I am working at struts2.
I have two fields in mine action-validation.xml
. What I want is that when validating validation in the first field, it will go to some jsp page (say a.jsp
), and if the validation validation fails in the second field, then it will go to another jsp (say b.jsp
).
Since it always returns "enter" when validation fails, I can currently only configure one jsp page.
A rich solution is entirely possible if the logic is applied in the action called on dispatch ...
public String actionBeingCalledOnSubmit() {
if(!isFieldAValid()) {
return "DISPLAY_A";
}
if(!isFieldBValid()){
return "DISPLAY_B";
}
}
You will need to create your own validation method in your action, return a custom result:
public void validate() {
if(!isFieldAValid()) {
return "DISPLAY_A";
}
if(!isFieldBValid()){
return "DISPLAY_B";
}
}
Then in your struts.xml, you will need to add custom results:
<result name="DISPLAY_A">/a.jsp</result>
<result name="DISPLAY_B">/b.jsp</result>
source to share