IntelliJ Java IDE
The moose likes Struts and the fly likes Struts 2 and validation Framework Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Struts
Reply Bookmark "Struts 2 and validation Framework" Watch "Struts 2 and validation Framework" New topic
Author

Struts 2 and validation Framework

Rishi Chopra
Ranch Hand

Joined: Mar 07, 2004
Posts: 108
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.


Life is Beautiful Learn to See it.........
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 7921

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Rishi Chopra
Ranch Hand

Joined: Mar 07, 2004
Posts: 108
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

Joined: Oct 29, 2001
Posts: 7921

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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612
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.
 
 
subject: Struts 2 and validation Framework
 
Threads others viewed
Struts2 Validation
Multiple field validation in Struts2 Validation using validation.xml file
Validation Framework in struts2
Struts2 Validations problem
Help with simple validation problem in Struts
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture