• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Struts Controller to Controller

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I generally use "Method 2".

- Brent
 
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic