First of all I use simple theme but even without it the same behaviour occurs (except page formatting). When I submit the form, name field gets empty and redirects to register.jsp without displaying the validation error. After checking the logs or with debugger, it seems that validation is working properly and server log messages are written as expected. I'll post generic code.
struts.properties
struts.ui.theme=simple
MyAction
private User user = new User() // getter and setter
@Inject
transient UserDAO userDAO;
@Override
public User getModel() {
return user;
}
public void validate(){
LOG.debug("NAME VALIDATION " + user.getName());
if("".equals(user.getName())){
addFieldError("user.name", "Name can't be empty");
LOG.debug("Validation Error on name");
}
}
Checked with debugger, validate method is working and logs are written.
struts.xml
<package name="users" extends="struts-default">
<action name="registerUser" method="prepareRegister" class="com.test.MyAction">
<result name="success">/register.jsp</result>
</action>
<action name="saveOrUpdateUser" method="saveOrUpdate" class="com.test.MyAction">
<result name="input" type="redirect">registerUser</result>
<result name="success" type="redirect">listUser</result>
</action>
</package>
register.jsp
<td>
<s:textfield id = "userName"
label = "User Name"
name = "user.name" />
</td>
<s:fielderror fieldName = "user.name" />
Feel free to ask me for clarifications. I am pretty new to struts 2, I tried the struts 2 documentation validation way, and checked other tutorials too. I don't know if I am missing something or I have some missconfiguration that I am not noticing, since the logic is working and the view part (jsp) is not. Thanks in advance.