Action Chanining, Help


Web tier: servlets, JSP, Web frameworks: Action Chanining, Help

  1. Action Chanining, Help (3 messages)

    Hi all,

    I have the following situation any help will be appreciated.
    the user supplys two values a1 and a2, based on the value of a1 I show him a different form where one of the fields is populated. the user then edits it along with the rest of the form and hits submit.
    i have successufully achieved to display the second form but with blank fields. Only when the submit button is pressed I see one of them populated. I am not sure where the problem is. Here's the relevant code of the two actions

    A.jsp {
           field a1;
           field a2;
              prop a1;
              prop a2;
              } {
      ActionForward execute(..., ActionForm form){
            Aform af = (Aform) form;
            string a1 = ar.getA1();
            string id = someotherclass(a1);
            if (id == null) {
                session.setAttribute("A1", a1);
                request.setAttribute("A1", a1);
                return (mapping.findforward("success");--> B.jsp
            } else { do somthing else }

    B.jsp {
     b1<html:text property="b1">
     b2<html:text property="b2">
          } {
               prop b1, prop b2
               } {
       ActionForward execute(...form) {
          Object obj = session.get("A1");
          String var = (String)obj;
          String val = someclass(var);
          Bform bf = (Bform)form;
      return (success/failure)

    Threaded Messages (3)

  2. Redirecting to jsp[ Go to top ]

    You say your mapping is to B.jsp?

    >>return (mapping.findforward("success");--> B.jsp

    If you are mapping to B.jsp, the execute method in your will not be called until you submit B.jsp. If you want to trigger a call to the execute method in, you will need to set your mapping to do so. One way is to modify "success" in your struts config - change it from B.jsp to (or whatever is associated with your action.)
  3. Redirecting to jsp[ Go to top ]


    thank you again for your help.

    well, if the mapping were to change to to invoke the execute method of so B.jsp would be semi-populated then the user will have to fill out the rest of the form and hits submit. My question is how would the execute method of Baction perform two disttinct operations. view info from db to jsp and read data from jsp to db? or do I have to use a different Action class for each operation?
  4. Like everything else in struts, it seems there are several ways to handle this :)

    If you need an Action that can handle different operations, one approach might be to extend DispatchAction rather than Action. You could also use different action classes for each operation. I've seen both approaches used and they both worked.