Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Struts2 wizard with scoped model driven  RSS feed

Vignesh MPN
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All

I am new to Struts2 and figuring out a sleek way to implement a 3 page wizard with 2 forms and 4 beans.

Before starting with questions, let me put forth my use case in a generic way without any details of entities involved, to keep it simple. Following is my use case:

1. JSP1 has Form1 with input fields.
2. Form1 submits to Action1.
3. Form1's field values are populated to Bean1 in Action1 via request parameter binding.
4. Action1 validates fields in Bean1 and if validation fails displays JSP1 with captured Bean1 values in Form1 fields and error messages.
5. If validation succeeds, Bean1 is used for retrieving Bean2 and result is directed to JSP2.
6. JSP2 displays the data in Bean2 and also other input fields in Form2.
7. Form2 submits to Action2
8. Form2's field values are populated to Bean3 in Action2 via request parameter binding.
9. Action2 validates fields in Bean3 and if validation fails displays JSP2 with captured Bean3 values in Form2 fields and error messages and also Beans2 data!
10. If validation succeeds, Bean3 is used to populate Bean4 and result is directed to JSP3.
11. JSP3 displays data in Bean4

Prior to this post I've read about this topic in books: Struts2 in Action and Practical Struts2 Web2.0 projects. I explored options of scope interceptor, scoped model driven actions and single action with Method Invocation using wildcards. I am not looking forward to add additional dependencies in the form of Spring WebFlow etc.

I am trying to implement the wizard using ScopedModelDriven actions with session scope. My design goal is to have well defined beans per action rather than having single bean for all actions.

Prior to questions regarding wizard, I have a basic question regarding bean scope in an action. Action1 should have Bean1 in the value stack for 2 reasons: 1. binding input values from Form1 on submit; 2. displays Form1 values if validation fails. Action1 should also have Bean2 in the value stack for displaying results in JSP2.

Should action always have fields (so that they are in ValueStack) for both the input page (Bean1) and result page(Bean2)? If implementing ScopedModelDriven which bean would be my Model?

Similarly, for Action2; Bean2, Bean3 and Bean4 needs to be in the ValueStack.

One brute force solution is to combine all fields in Bean1, Bean2, Bean3 and Bean4 and have just one Bean for the whole wizard! I don't want to do that because all these beans have a specific functionality.

I guess I am not getting the concept right. There should be a sleek way to implement this wizard with these atomic beans using the session scope.

Any help is much appreciated.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!