• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How html:errors Functionality works

 
Karthik Rajendiran
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
I have a JSP page with fields username and password.i have corresponding formbean with fields same as input field in jsp

In one site they mentioned
To specify that this message is for the "username" property, we would code this instead:
errors.add(
"username", new ActionError("error.username.required"));
If we specify a property, we can use the <html:errors/> tag (or any of the alternatives) like this:
The "username" errors print next to the username field, and any "password" errors print next to the password field


I TRIED THE same but it is not working. I tried with actionmessage too, i am getting the error queued up in the top of the page.

How to make it visible corresponding to the field it fails
 
Christian Nash
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Perhaps this will work:

<P>Username: <html:text property="username"/></P> <html:errors property="username"/>
<P>Password: <html assword property="password"/></P> <html:errors property="password"/>
 
prasanth jalasutram
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Make sure your action class extends validationForm class and implement validate method.

For example:

a)
public class ActionForm extends ValidatorForm{
......
/*
setters and getters are defined here
*/
......
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (userName == null || userName.trim().equals("")) {
errors.add("userName", new ActionError ("error.login.username.null"));
}

return errors;
}

}

b)
add this line in your properties file
error.login.username.null=User name required

c) then in jsp
<form action="login">
.....
<td>Username</td>
<td><html:text property="userName" size="16" maxlength="16"/></td>
<td><html:errors property="userName"/></td>
.......
</form>

Hope this helps.

Thanks
Prasanth
 
Karthik Rajendiran
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks christian and Prashanth
As per your suggestions, i included <html:error property="user"/>
property should have the value that was set in string within
errors.add("user",....);
Now the Error is displayed next to the field.
Usually we take pains to make program work. nowadays for getting error we have to take pains
THANKS FOR THE TIMELY HELP


Thanks
Karthik
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic