Vignesh MPN

Greenhorn
+ Follow
since Dec 06, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vignesh MPN

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.
13 years ago
Apologize for not providing enough information.

I have missed some information in my original post too. I have updated the original post as well.

I have declared the collection as type java.util.Set, so I will need to typecast the collection to java.util.TreeSet or java.util.SortedSet before invoking the operation.



The exception:

Persistence Provider: JBoss Hibernate

I have an entity with a one-to-many association. For my business logic, I want the collection implementation type to be a TreeSet as I can sort it.


Let's say I persist the entity and so it becomes managed. When the entity becomes managed, the persistence provider replaces the collection implementation with its custom implementation org.hibernate.collection.PersistentSet. Now if I do any TreeSet operation on my collection, it does not work as the collection implementation type is not a TreeSet anymore.

But I do want my collection implementation to be a TreeSet even in a managed entity. I know I can not cast org.hibernate.collection.PersistentSet to java.util.TreeSet.

Why do we have such restriction in implementation? Why can't the persistence provider (Hibernate) use TreeSet as the implementation type?

I do not want my code to be dependent on vendor-specific implementation like PersistentSet or PersistentSortedSet. Is there a solution to this? Is there a way to use a java.util.* collection implementation in a managed entity?

I would appreciate any help.

Thanks
Vignesh