• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2 and validation Framework

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have written a basic example for struts 2 with validation framework

JSP Page:- having a single field named 'name' and submit button
Action class :- com.package.HelloAction
struts.xml : the action tag has a result with type 'input' and 'success'

HelloAction-validation.xml :- having a requiredstring validation on the name field.

The question is:-
1) why i have to extend ActionSupport to make it working..Isn't that a question against POJO based programming?
2) why is HelloAction-validation.xml needs to be placed under com.package to make it working
Should it not be alnogside classes folder??? the whole concept of configuration files under src package is really confusing??

Thanks & Regards
Rishi.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rishi Chopra wrote:
1) why i have to extend ActionSupport to make it working..Isn't that a question against POJO based programming?



You don't. ActionSupport simply provides commonly used defaults.

Rishi Chopra wrote:
2) why is HelloAction-validation.xml needs to be placed under com.package to make it working
Should it not be alnogside classes folder??? the whole concept of configuration files under src package is really confusing??



My wild guess is that it is done that way to closely coordinate an action with its validation. It also utilizes the Java class structure to give a namespace to the XML files. If they didn't do it that way, you'd end up with a very crowded root class directory.
 
Rishi Chopra
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joe

1. Without extending ActionSupport it does not work or am i missing something?

2. But if you build your war using maven (mvn clean package) it places the HelloAction-validation.xml away from the .class files
It places it alongside classes folder. ( May be maven war plugin can be configured to do it as well) .

Thanks & Regards,
Rishi.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rishi Chopra wrote:Thanks Joe
1. Without extending ActionSupport it does not work or am i missing something?



It should work without extending ActionSupport. Note that ActionSupport implements several interfaces. If your functionality depends on those interfaces, you'll have to duplicate that implementation or your action will not work.

Rishi Chopra wrote:
2. But if you build your war using maven (mvn clean package)
.



Sorry, I use Ant to do my builds. I can't speak to Maven.
 
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

Rishi Chopra wrote:1. Without extending ActionSupport it does not work or am i missing something?


No, you're not missing something. If an action doesn't implement Validateable it won't be validated.

2. But if you build your war using maven (mvn clean package) it places the HelloAction-validation.xml away from the .class files
It places it alongside classes folder. ( May be maven war plugin can be configured to do it as well) .


Correct, but I'm not sure what the question is. Maven's directory structure puts resource files in src/main/resources, and under normal package hierarchy below that. You can put the *source* wherever you want, but it needs to be deployed on the classpath. Maven does this automatically when creating the webapp.

You could just as easily put all your messages in a package.properties at the root of the source tree (which is where messages used across the application should go), or define a global resources file. There are a variety of places Struts 2 will look for messages; see http://struts.apache.org/2.x/docs/localization.html. Wherever you put things, it still needs to be on the classpath.
 
reply
    Bookmark Topic Watch Topic
  • New Topic