It's not a secret anymore!*
The moose likes Struts and the fly likes In-line Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "In-line Validation" Watch "In-line Validation" New topic
Author

In-line Validation

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Can someone point me in the right direction for putting validation error message beside or below the appropriate validating field? I can only find examples where they just list all the errors at the top of the page, and that is just not very eye pleasing.
Thanks.


GenRocket - Experts at Building Test Data
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
Gregg,
You can pull the actionerrors object out of the pageContext on the jsp page and then pull use the action errors api to pull out the individual error messages. What the html:errors tag does is the same thing just that it pulls out all the action error messages but u cud pull them out one by one.
HTH


Adios
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
<html:errors property="userId"/>
will retrieve only the action error named 'userId'. You can place this anywhere on your page.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Thought I would drudge this old post of mine because I am having a problem with putting the validation in-line with the correct field on the form.
When I do <html:errors property="name" /> it also pulls the error.header property and of course that just looks horrible.
First, why does it pull that header automatically and Second, if I just remove that property from the application.properties, will it still work? Or does <html:errors/> need that all the time to function?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4445
    
    5

AFAIK, the header and footer keys are optional: the tag uses them if it finds them, otherwise it just renders the error messages. Of course, if you strip out the header and footer from the resource bundle and you have pages where you do want the header and footer, those will be now be F'd up. Alternatively, you could leave the header and footer and use html:messages for your field-specific errors.


Junilu - [How to Ask Questions] [How to Answer Questions]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I could really care less about the header and footer tags. I always like to just display messages where I want them. Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: In-line Validation
 
Similar Threads
error messages for array of radiobuttons
If JavaScript is disabled, how to listen events?
i am validating email on server side
where to put validation?
Validation in LazyDynaBean