Meaningless Drivel is fun!*
The moose likes Struts and the fly likes validate() for multiple actions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validate() for multiple actions" Watch "validate() for multiple actions" New topic
Author

validate() for multiple actions

Bala Krishna
Ranch Hand

Joined: Jan 26, 2001
Posts: 95
Hi,
I've recently started looking into Struts2 and am learning it by building a simple CRUD web application. Compared to Struts1.x, I like the improvements in Struts 2.x, where I can have the same Action class for all operations for my entity. What I mean is, Struts 1.x forced me to have one Action class for each of the CRUD operations of my entity - since execute() method was the only method in the action class, that'd be, well, executed. With Struts2, I can create just one Action class, and implement different methods, one for each of the CRUD operations. Based on how I map them in my struts.xml, the framework will call the specific method for the action I'm invoking. This, coupled with, wildcard action mapping allows to be very concise in struts.xml.




But, when I read about the validate() method in the Action class, I couldn't find a way to have a custom validate() method for each of the action. Needless to say, the inputs for each of the actions is going to be different, and thus the validation also will be different. But, I have only one validate() method. Does this mean that I have to do an if/else on the action name in the validate() method?
I've searched Struts FAQs and this forum but couldn't find any relevant information. I'd appreciate it someone can shed some light on this.
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 489
    
    5
Hi,
I don't have an answer regarding validation, but would just like to point out that even in Struts 1.x, it was possible to have single Action with method per operation, using DispatchAction
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validate() for multiple actions
 
Similar Threads
struts2 properties file reload
migration to Struts2
struts2: howto correctly deligate actions on the struts.xml's include files
Struts2-Spring annotation
working with hashmap using struts2