-------------- Original message -------------- 

> I believe the use case is not about going from A to B. It's about going to A 
> and 
> then submitting data from A. The design of Struts 1.x encourages us to use 
> one 
> mapping to display a form and another to submit a form. (There may or may not 
> be 
> more than Action class behind the mappings. I've written many application 
> that 
> use one Action class and lots and lots of mappings.) The design of JSF and 
> ASPX 
> encourage you to use one mapping for both display and submit. Those 
> frameworks 
> are designed around the notion of a "postback" state. If it's not a postback, 
> you can initialize the controls and skip to the response. If it is a 
> postback, 
> then the validation and update phases fire. Moreover, since the controls can 
> maintain their own state, you don't have to repopulate them yourself on a 
> postback where validation fails. As a result, there are fewer mappings to 
> write 
> (which leads to fewer mappings to debug). 
> 
> -T. 
> 

I suppose that if you preferred the action chaining method in struts you might 
consider something similar in JSF.  You might be able to use a servlet as a 
passthru action as long as it has been dispatched thru the faces servlet.  In 
this example I’m using a prefix mapping to the servlet, “/faces/*”.  From the 
A.jsp I have a submit button that forwards to the servlet via faces servlet.  
The servlet redirects to itself a few times using the navigation rules in the 
faces config and finally redirects back to the original page. 

I suppose that this is similar to how you might handle it struts.  Kind of 
similar?  The servlet and web deployment descriptor take the place of the 
struts action.  The navigation rules are still defined in a declarative nature. 
 The only catch is that a forward won’t work from the servlet.  

IMHO, I really dig JSF, but struts handle this situation better.

Gary

A.jsp
<h:commandButton value="Run" action="somethingFat"/>

faces-config.xml
 <navigation-rule>
    <from-view-id>/A.jsp</from-view-id>
    <navigation-case>
       <from-outcome>somethingFat</from-outcome>
       <to-view-id>/StageServlet</to-view-id>
    </navigation-case>
 </navigation-rule>
 
 <navigation-rule>
    <from-view-id>/StageServlet</from-view-id>
    <navigation-case>
       <from-outcome>next</from-outcome>
       <to-view-id>/A.jsp</to-view-id>
       <redirect/>
    </navigation-case>
    <navigation-case>
       <from-outcome>loop</from-outcome>
       <to-view-id>/StageServlet</to-view-id>
       <redirect/>
    </navigation-case>
 </navigation-rule>

Chained Action Servlet

public class StageServlet extends HttpServlet {
 public void doGet(HttpServletRequest req, HttpServletResponse resp)
  throws ServletException, IOException {
  Integer cntr = (Integer) req.getSession().getAttribute("cntr");
  if (cntr == null) {
   cntr = new Integer(1);
  } else {
   cntr = new Integer(cntr.intValue() + 1);
  }
  req.getSession().setAttribute("cntr", cntr);
  System.out.println("Hello " + cntr.intValue() + " times.");
  String forward = null;
  if (cntr.intValue() > 2)
   forward = "next";
  else
   forward = "loop";
  FacesContext context = FacesContext.getCurrentInstance();
  NavigationHandler handler =
   context.getApplication().getNavigationHandler();
  handler.handleNavigation(context, null, forward);
 }

Reply via email to