File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes using a validation method other than 'validate' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "using a validation method other than Watch "using a validation method other than New topic
Author

using a validation method other than 'validate'

Skip Cole
Ranch Hand

Joined: Jan 05, 2001
Posts: 175

We can direct the action to a method other than 'execute' by using



as an attribute in the action tag in the struts.xml file.

Why can't we direct the validation to another method in a similar fashion?

It seems that the execute and validation methods work hand in hand together. So being able to change one without changing the other, well it just seems like a bit of a gap.

Thanks in Advance,
Skip


If you love me, you will visit docs.opensimplatform.org
(FYI, Getting it tattooed on is a bit much.)
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Hi,

No that is not a GAP. Action is extended by a DispatchAction to achieve the method name separation with the help of struts-config.xml.
this is done for writing a more executeXXX() method in single Action class.
e.g. You are having one page with add, delete, edit button then for each button you need to add a separate action, instead of that extend your class with a DispatchAction add a methods executeAdd(), executeDelete() etc.

for validate() method there is no need to have separate name, even if your project having that need then extend action class customise it by overriding a processValidate() method.

HTH.

-Shailesh


Thanks,
Shailesh
Skip Cole
Ranch Hand

Joined: Jan 05, 2001
Posts: 175

Thanks Shailesh for your reply.

It just seems to me that it would be far simpler, and simpler is much better, to do the redirect of the execute method and validate method all in one place. That way someone maintaining the code just has to look in one place to get the full picture: no need to go looking for some overridden processValidate method somewhere or anything else.

Personally, I place a great deal of value in being able to figure out things quickly from the code, and not requiring a lot of background knowledge on the part of the person doing the work. Frameworks are supposed to make our lives easier, right?

Let me ask this, What would be the harm in allowing someone to select a different validate method from inside of the struts.xml file? Would it violate any core coding principal?

Thanks,
Skip
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Hi,

There is no harm in allowing to select validate method name in struts-config.xml. no violation of any principle as far as I am thinking.
What I understand from your post is validate and execute method in action class, so developer can find that easily...hope I understand you correctly.
but action is not a place where you could do a validation, we are performing validation on form fields so we are having validate method in form. we can say a life cycle methods of any actionform is reset(), setter() of the form fields, validate() then go ahead and instantiate an action and call a execute() method on it.

this is the reason they are put a validate in form not in a action.

Skip Cole
Ranch Hand

Joined: Jan 05, 2001
Posts: 175
Hi Shailesh,

I just want to confirm I understand what you mean. When you say "validate method in form" do you mean client-side validation?

I agree a lot validation can be there can be done on the client side, but some things - such as verifying that a name entered is not already found in the database - are impractical to do so.

Thanks,
Skip
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Hi Skip,

exactly, validate method in struts is for a client side validation,for fields which are present on UI, either do them here in validate method or in java script.

Database validation is nothing but a service level validation, those should be handled in service level. so that if your UI will change then those validation should occur from service layer.



thanks,
Shailesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using a validation method other than 'validate'