This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts Controller to Controller Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Controller to Controller" Watch "Struts Controller to Controller" New topic
Author

Struts Controller to Controller

Suresh Kumar Ramasamy
Greenhorn

Joined: Mar 18, 2008
Posts: 7
Constraint:

Design one action servlet for each jsp - All actions emanating from a JSP should be handled by the corresponding servlet.

Scenario:

Assume that one.jsp on click of a button has to go to two.jsp. This two.jsp needs some values (say for populating a combo) before loading.

Possible Solution without considering the Constraint:

Invoke two.jsp from one.jsp (View to View). Call a function in the header of two.jsp which will submit the form to two.java for retrieval of the values (Hope this will work).

What I have done:

one.jsp submits the form to one.java.

one.java has the following code:
return new two().execute(mapping,form,request,response);

two.java has nothing special. After retrieving the required values, the execute method issues mapping.findForward(forwardName);

The struts config file has an entry for one.java for the forward name set by two.java to navigate to two.jsp.

Question:

Is this a standard way? If not, what are the better ways?

Thanks & Regards.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Suresh Kumar Ramasamy:

Is this a standard way?

No, it's not. There are several problems with it. The main one is that the execute method in two.java is expecting the mapping and form objects to be those defined for the two action. Instead, in this case they are the mapping and form for the one action.

Originally posted by Suresh Kumar Ramasamy:
If not, what are the better ways?

Yes, there are better ways. Here are two possibilities:

Method 1: Refactor the code that prepares for two into a method in a Controller Helper or Controller Utility class. Example: ControllerUtils.prepareTwo(). You can then call this method from either the one or two actions.

Method 2: Create both a preparatory and an execution action for each page. Then create a forward for the page one execution action that forwards to the preparatory action for page two. Example:

[ March 18, 2008: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I generally use "Method 2".

- Brent
 
 
subject: Struts Controller to Controller