Reputation: 4713
Validation is working fine. On Add action loading the new form for the user to fill in. Once submitted the validation is done on processAdd(). All is fine.
Problem:
User fill in the form at http://localhost:8000/Struts2_Spring_Crud/student/add
.When submitted than processed & validated through http://localhost:8000/Struts2_Spring_Crud/student/processAdd
. If validation failed my url is /processAdd. I want to be at /add when validation fails. Is there any way to do this?
<s:form action="processAdd" method="POST">
<s:submit method="execute" value="#title"/>
</s:form>
public String execute() throws Exception {
System.out.println("execute() executed");
//Process form data
return SUCCESS;
}
public String input() throws Exception {
System.out.println("input() executed");
//Prepare form data
return INPUT;
}
<default-action-ref name="list"/>
<action name="list" class="com.myapp.actions.StudentAction" method="getAllStudents">
<result name="success" type="tiles">/student.list.tiles</result>
</action>
<action name="add" class="com.myapp.actions.StudentAction" method="input">
<result name="input" type="tiles">/student.edit.tiles</result>
<result name="failure" type="tiles">/student.edit.tiles</result>
</action>
<action name="processAdd" class="com.myapp.actions.StudentAction">
<result name="success" type="redirectAction">list</result>
<result name="input" type="tiles">/student.edit.tiles</result>
<result name="failure" type="redirectAction">add</result>
</action>
Upvotes: 0
Views: 163
Reputation: 10017
try this:
<action name="processAdd" class="com.myapp.actions.StudentAction">
<result name="success" type="redirectAction">list</result>
<result name="input" type="redirectAction">add</result>
<result name="failure" type="redirectAction">add</result>
</action>
Upvotes: 1