This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How html:errors Functionality works

 
Ranch Hand
Posts: 221
  • 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
 
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"/>
 
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: 221
  • 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
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic