• 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

using a validation method other than 'validate'

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

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
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Skip Cole
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic