On 11/29/06 12:44 AM, "Tarek Nabil" <[EMAIL PROTECTED]> wrote:
> One of the problems with Struts was that if you had a page that requires > some setup and this page submits to an Action, then you would not be > able to set validate to true on that action because if validation > problems occur then Struts will take you directly to the input JSP > without performing the setup and your JSP wouldn't work. Yes, that can be an issue in Struts 1, as far as I know, but then again I never did serious Struts 1 development. As for S2 it's not an issue. With a reasonably configured interceptor stack and the use of the Preparable interface the issue doesn't exist. > A solution to that would be to specify the input of the action as the > setup action, which means you're doing action chaining and Struts is not > good at that (it will reset your form among other things). I haven't found a need for chaining yet in my S2 development. Using the prepare() method has sufficed for me. > The solution of choice for us so far was to call validate() ourselves in > the action and if a validation problem occurs then we call the setup > method (eventually you start using your action methods as an API which > still was not good). Agreed, it would be nice if it just happened. You can do this in S2. Basically I have my interceptor stack configured to apply parameters to my action, run prepare, apply parameters again, then validate, then execute. All very neat. > Another problematic scenario is the case when you're editing some > database record for example. When you go to your setup action for the > first time, you will populate drop down lists for example, and then load > the existing values from the database to your JSP fields. If the user > attempts to save and some problem occurs then in the setup action, you > will need to again populate the drop down lists, but you will NOT want > to overwrite the user's inputs with the existing data. This is very > similar to the first problem, but you would also need to pass some flag > to the setup method to tell it whether to copy the data from the > database to your ActionForm. Again I think the well configured interceptor stack has you covered. If you apply parameters after your prepare the users input will over write the values you've retrieved from the database, thereby preserving their input. Alternatively you could prepare the "model" once for the duration of the users interaction with a "process" by storing the data in the user's session, or in a conversation scope (cf. JIRA WW-1514 for an idea on how to do this, note this interceptor/interface is not done yet, nor is it official). > Does Struts 2 or even WW 2.2.4 solve that problem in an elegant way? I > remember coming across something about using Interceptors for that, but > that would mean creating an Interceptor for almost every action of that > type. I also noticed that there are some warnings in the documentation > against using action chaining in Struts 2 as well. Can't speak to the chaining issues. But as I've written I think you can solve the whole issue using the Prepareable interface and a well configured interceptor stack. Also, remember that you don't need to use the same stack for every action. You can apply interceptor stacks at the action and package level. That makes it pretty easy to manage. Take care, Mark --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]