Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Struts and the fly likes Struts2: bypass the prepare method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2: bypass the prepare method?" Watch "Struts2: bypass the prepare method?" New topic

Struts2: bypass the prepare method?

Raymond Holguin
Ranch Hand

Joined: Aug 11, 2009
Posts: 77
Ok here is my scenario....
My Action class does the input() method and a save() method. the class also implements the Prepareable, and the prepare method is what i use to load up the drop down lists (or whatever other populated data i need for my form). When i call the input method or if validation fails then the prepare method gets called like i want it do and directs back to the populated form. The problem is that upon successful validation before it goes to my save() method it still calls the prepare method...I DONT want this. Functionally the app works fine and it doesn't cause issues. but its a waste of resources to run through the population routines when they aren't even going to be used for anything.

I know the easy solution would be to put the save() in its own action and not implement Prepareable, but I dont want to go that route....i want to keep everything together. so my question is if there is a way to bypass the prepare method for certain situations? similar to maybe how the *_input will bypass validation schemes.
Raymond Holguin
Ranch Hand

Joined: Aug 11, 2009
Posts: 77
well it occurred to me to try to override the prepare interceptor to bypass the save() method similar to how the validator interceptor is setup to bypass the input() method....but then i found that will not solve the issue for another reason.

if the validation fails it does not redirect the action back to action_input even though the action_input jsp page is called. the current action is still action_save for failed validation so if i did overwrite the prepare interceptor the form would not get repopulated since the prepare would be skipped.

looks like i need a new approach somehow...
I agree. Here's the link:
subject: Struts2: bypass the prepare method?
Similar Threads
Struts 2 - Yet another combobox prepopulation using prepare method question
How to ByPass the validation framework
Struts Validator and Dynamically Populated Select Lists
Struts error message display
Validation Problem in struts2