• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Struts2 Input Validation using Annotations

 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new to Struts2. When I use Struts2 validator annotations, does the error message always get displayed next to the invalid field name? I want to display the error message only in the place where I specify the <s:fielderror>. I've tried to specify the fieldName attribute in the annotation, but that doesn't seem to work.

My Action class looks like this.


My JSP file looks like this


My UI theme is XHTML.

I know I can use perform the validation inside the validate() method and call addFieldError(), but I want to use annotations. Is it possible? Thanks.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "xhtml" theme has two options for field error message placement; see the tag documentation for the attribute name. If that doesn't work for you, the easiest thing to do is to create your own theme (I usually just copy the "xhtml" or "css_xhtml" theme and start from there).

Remember: the supplied, default theme is just a starting point for your own application's look-and-feel requirements. While it may work for many people, not every application will be laid out the same way.

The way things are being validated doesn't have anything to do with where the messages are put.
 
Let's get him boys! We'll make him read this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic