Hi, I like to show error message near to form fields, instead of showing all error messages at the top of page, using STRUTS. Is this the proper way to get it done by using <html:errors property="propertyName"/> near form field?
That's what the docs say. It should be a simple enough thing for you to try out and see if you get the proper results. Keep in mind that error.heander and error.footer still print out I think.
I haven't used the html:errors tag like that but I assume that you would have to specify the filter properly (e.g. ActionErrors.GLOBAL_ERROR etc) otherwise your errors would probably all appear at the first instance of the errors tag. I think
I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
I would like to mention that we can display both global errors and field-specific errors in the same page in a mutually-exclusive fashion (well, it's working with Struts 1.1b2, anyway). Sometimes, it would be nice if we could display global errors at the top, and field-specific errors near the fields. Anyone who has tried using <html:errors /> at the top knows that all errors will be displayed, not just the global one like we want. To lock out the field-specific errors, do this:
Then, continue with each field:
This idiom does make the assumption that the Action classes are using ActionErrors.GLOBAL_ERROR.
The following is just a quick discussion of the code's "aesthetics", so feel free to skip this part. At first glance, the code for displaying the GLOBAL_ERROR might not look like it's the "Struts Way" (at least, it didn't to me), since the whole point of custom tags is to eliminate scriptlets. A week ago, I would have thought that it wouldn't even compile, being a JSP expression inside a custom tag. But it does, and that's always a good thing! Also, I don't consider the expression syntax <%= %> a scriptlet, which, from my impression of the Struts UserGuide, is in accord with the Struts folks. Also, in the UserGuide is the use of "(RT EXPR)", which I think means "Run Time Expression" which means JSP expressions can be used. Don't quote me on this, though. I hope this helps. Ted Schrader SCJ2P [ December 12, 2002: Message edited by: Ted Schrader ]