aspose file tools*
The moose likes Struts and the fly likes How html:errors Functionality works Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How html:errors Functionality works" Watch "How html:errors Functionality works" New topic
Author

How html:errors Functionality works

Karthik Rajendiran
Ranch Hand

Joined: Aug 13, 2004
Posts: 211
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


SCJP 1.4 SCWCD 1.4 SCDJWS 1.4
Christian Nash
Ranch Hand

Joined: Jan 17, 2006
Posts: 107
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"/>


- Christian
prasanth jalasutram
Greenhorn

Joined: Dec 15, 2004
Posts: 6
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

Joined: Aug 13, 2004
Posts: 211
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How html:errors Functionality works