I am using Struts 1.2 for my application. I have a validate method for my form where I am doing some validation for the inputs provided by the user. Below is the code for the userName
provided by the user:
@Override
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
System.out.println("Validating the Form...");
ActionErrors errors = new ActionErrors();
if(userName != null && userName.length() <= 0)
errors.add("userName",new ActionError("Invalid UserName"));
return errors;
}
If the userName is not wntered by the user, then the above error message should be displayed in the UI. Below is the code I used in the jsp file for displaying the above error message:
<logic:messagesPresent property="userName">
<html:messages id="userName" property="userName">
<bean:write name="userName"/>
</html:messages>
</logic:messagesPresent>
But it did not displayed any error message.
I also tried this alternative but this also did not worked.:
<logic:messagesPresent property="userName">
<html:errors property="userName" /><html:errors/>
</logic:messagesPresent>
When I try debugging the code, the validate
method is getting executed in the form
and the execute
method is not triggered since there are validation errors. In the UI, no error message is getting displayed. Kindly let me know how to fix this.