You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by iw...@nttdata.co.jp on 2001/04/24 15:51:14 UTC

wizard style example, anywhere?

Hello struts-users,

I am very new to Struts (or JSP for that matter), and in need of
some examples that I can get my hands on.

Specifically, an application that uses "wizard" style, multiple-page
input forms would be very nice. Couple of Struts documents I looked
mention that Struts works well with wizard style application, but I get
confused when it comes to writing struts-config.xml, JSPs that share
the same ActionForm or Action, etc.. I gotta see it working before I
start building mine.

Good examples, anywhere, anyone?

thanks,

- kazumi

Re: wizard style example, anywhere?

Posted by Udo Walker <Ud...@abas.de>.
Hi,

there's a hack for image submit buttons.

E.g. if you have a <html:image property="openOrders" page="..."/>
you'll get a request parameter with the value of the property attribute
combined with a '.x' and '.y' for the position in the image submit
button. If you only want to test which of the many submit buttons it
was use following statement in your action class:

  String openAction = request.getParameter("openOrders.x");
  
  if(openAction != null) {
    
    // it was the openOrders submit button

    ...

  }

I agree with you that there should be another way to get the information
which submit button was pressed in a form with more than one submit
button.
Why not use the value of the property attribute?

Regards

Udo.


Uwe Pleyer wrote:
> 
> Much thanks for this clearfying hack.
> 
> In my opinion we should look for a way to identify the pressed button without
> refering the label, cause this can be change due to internalization (maybe with
> an German locale "<< Prev" Button will be labeled "<< Zurück").
> 
> May be someone out there knows a way to have an fixed value that will be passed
> back beside the label.
> 
> Regards
> Uwe
> 
> Tharwat Abdul-Malik schrieb:
> 
> > I use something like the following in my struts-config.xml file:
> >
> >     <action    path="/signup"
> >                type="SignupAction"
> >                name="signupForm"
> >               scope="session"
> >               input="page1.jsp">
> >               <forward name="page1"              path="page1jsp"/>
> >               <forward name="page2"              path="page2.jsp"/>
> >               <forward name="page3"              path="page3.jsp"/>
> >               <forward name="page4"              path="page4.jsp"/>
> >               <forward name="success"            path="confirm.jsp"/>
> >     </action>
> >
> > In page1.jsp I declare the following buttons:
> >
> >                   <html:hidden property="page" value="1"/>
> >                   <html:submit>
> >                     <bean:message key="button.next"/>
> >                   </html:submit>
> >
> > Page2.jsp:
> >
> >                   <html:hidden property="page" value="2"/>
> >                   <html:submit>
> >                     <bean:message key="button.prev"/>
> >                   </html:submit>
> >
> >                   <html:submit>
> >                     <bean:message key="button.next"/>
> >                   </html:submit>
> >
> > Page3.jsp
> >
> >                   <html:hidden property="page" value="3"/>
> >                   <html:submit>
> >                     <bean:message key="button.prev"/>
> >                   </html:submit>
> >
> >                   <html:submit>
> >                     <bean:message key="button.next"/>
> >                   </html:submit>
> >
> > Page4.jsp
> >
> >                   <html:hidden property="page" value="4"/>
> >                   <html:submit>
> >                     <bean:message key="button.prev"/>
> >                   </html:submit>
> >
> >                   <html:submit>
> >                     <bean:message key="button.finish"/>
> >                   </html:submit>
> >
> > In my SignupForm.java I define all fields for each page. Then I have a
> > switch statement in the validate method to validate the data for each page:
> >
> >     public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> > request)
> >     {
> >
> >         ActionErrors errors = new ActionErrors();
> >         switch (page)
> >         {
> >         case 1:
> >                 // Validate fields on page 1
> >         case 2:
> >                ///
> >         }
> >        return errors;
> > }
> >
> > Finally in the SignupAction.java I check for which button was pressed and
> > return the next or previous page:
> >
> >     public ActionForward perform(ActionMapping mapping,
> >                                  ActionForm form,
> >                                  HttpServletRequest request,
> >                                  HttpServletResponse response)
> >     throws IOException, ServletException
> >     {
> >
> >         HttpSession session = request.getSession();
> >         SignupForm signupform = (SignupForm) form;
> >         int page = signupform.getPage();
> >
> >         String label = request.getParameter("submit");
> >         if (label != null)
> >         {
> >             if ("<< Prev".equals(label))                // Previous was
> > pressed
> >             {
> >                 return mapping.findForward("page"+(page-1));
> >             }
> >             else if ("Next >>".equals(label))        // Next was pressed
> >             {
> >                 return mapping.findForward("page"+(page+1));        //
> > Finished was pressed
> >             }
> >             else if ("Finish".equals(label))
> >             {
> >                 // Do finish work, add data to database, whatever
> >             }
> > ..... return(mapping.findForward("success"));
> >
> > I'm new to struts (about 2 weeks now). I tried to find examples but couldn't
> > find any. So I hacked out this. Perhaps if someone has a better way we can
> > all learn something new.
> >
> > I hope this helps.
> >
> > ----- Original Message -----
> > From: <iw...@nttdata.co.jp>
> > To: <st...@jakarta.apache.org>
> > Sent: Tuesday, April 24, 2001 9:51 AM
> > Subject: wizard style example, anywhere?
> >
> > > Hello struts-users,
> > >
> > > I am very new to Struts (or JSP for that matter), and in need of
> > > some examples that I can get my hands on.
> > >
> > > Specifically, an application that uses "wizard" style, multiple-page
> > > input forms would be very nice. Couple of Struts documents I looked
> > > mention that Struts works well with wizard style application, but I get
> > > confused when it comes to writing struts-config.xml, JSPs that share
> > > the same ActionForm or Action, etc.. I gotta see it working before I
> > > start building mine.
> > >
> > > Good examples, anywhere, anyone?
> > >
> > > thanks,
> > >
> > > - kazumi
> > >

Re: wizard style example, anywhere?

Posted by Tharwat Abdul-Malik <ta...@grandtalent.com>.
If you want to internationalize the labels, just use the Locale and
MessageResources classes. There are plenty of instructions and examples on
how to use them.

I was responding to the statement "I get confused when it comes to writing
struts-config.xml, JSPs that share the same ActionForm or Action, etc" and I
tried to provide an example.

----- Original Message -----
From: "Uwe Pleyer" <uw...@up-soft.de>
To: <st...@jakarta.apache.org>
Sent: Thursday, April 26, 2001 4:30 AM
Subject: Re: wizard style example, anywhere?


> Much thanks for this clearfying hack.
>
> In my opinion we should look for a way to identify the pressed button
without
> refering the label, cause this can be change due to internalization (maybe
with
> an German locale "<< Prev" Button will be labeled "<< Zurück").
>
> May be someone out there knows a way to have an fixed value that will be
passed
> back beside the label.
>
> Regards
> Uwe
>
> Tharwat Abdul-Malik schrieb:
>
> > I use something like the following in my struts-config.xml file:
> >
> >     <action    path="/signup"
> >                type="SignupAction"
> >                name="signupForm"
> >               scope="session"
> >               input="page1.jsp">
> >               <forward name="page1"              path="page1jsp"/>
> >               <forward name="page2"              path="page2.jsp"/>
> >               <forward name="page3"              path="page3.jsp"/>
> >               <forward name="page4"              path="page4.jsp"/>
> >               <forward name="success"            path="confirm.jsp"/>
> >     </action>
> >
> > In page1.jsp I declare the following buttons:
> >
> >                   <html:hidden property="page" value="1"/>
> >                   <html:submit>
> >                     <bean:message key="button.next"/>
> >                   </html:submit>
> >
> > Page2.jsp:
> >
> >                   <html:hidden property="page" value="2"/>
> >                   <html:submit>
> >                     <bean:message key="button.prev"/>
> >                   </html:submit>
> >
> >                   <html:submit>
> >                     <bean:message key="button.next"/>
> >                   </html:submit>
> >
> > Page3.jsp
> >
> >                   <html:hidden property="page" value="3"/>
> >                   <html:submit>
> >                     <bean:message key="button.prev"/>
> >                   </html:submit>
> >
> >                   <html:submit>
> >                     <bean:message key="button.next"/>
> >                   </html:submit>
> >
> > Page4.jsp
> >
> >                   <html:hidden property="page" value="4"/>
> >                   <html:submit>
> >                     <bean:message key="button.prev"/>
> >                   </html:submit>
> >
> >                   <html:submit>
> >                     <bean:message key="button.finish"/>
> >                   </html:submit>
> >
> > In my SignupForm.java I define all fields for each page. Then I have a
> > switch statement in the validate method to validate the data for each
page:
> >
> >     public ActionErrors validate(ActionMapping mapping,
HttpServletRequest
> > request)
> >     {
> >
> >         ActionErrors errors = new ActionErrors();
> >         switch (page)
> >         {
> >         case 1:
> >                 // Validate fields on page 1
> >         case 2:
> >                ///
> >         }
> >        return errors;
> > }
> >
> > Finally in the SignupAction.java I check for which button was pressed
and
> > return the next or previous page:
> >
> >     public ActionForward perform(ActionMapping mapping,
> >                                  ActionForm form,
> >                                  HttpServletRequest request,
> >                                  HttpServletResponse response)
> >     throws IOException, ServletException
> >     {
> >
> >         HttpSession session = request.getSession();
> >         SignupForm signupform = (SignupForm) form;
> >         int page = signupform.getPage();
> >
> >         String label = request.getParameter("submit");
> >         if (label != null)
> >         {
> >             if ("<< Prev".equals(label))                // Previous was
> > pressed
> >             {
> >                 return mapping.findForward("page"+(page-1));
> >             }
> >             else if ("Next >>".equals(label))        // Next was pressed
> >             {
> >                 return mapping.findForward("page"+(page+1));        //
> > Finished was pressed
> >             }
> >             else if ("Finish".equals(label))
> >             {
> >                 // Do finish work, add data to database, whatever
> >             }
> > ..... return(mapping.findForward("success"));
> >
> > I'm new to struts (about 2 weeks now). I tried to find examples but
couldn't
> > find any. So I hacked out this. Perhaps if someone has a better way we
can
> > all learn something new.
> >
> > I hope this helps.
> >
> > ----- Original Message -----
> > From: <iw...@nttdata.co.jp>
> > To: <st...@jakarta.apache.org>
> > Sent: Tuesday, April 24, 2001 9:51 AM
> > Subject: wizard style example, anywhere?
> >
> > > Hello struts-users,
> > >
> > > I am very new to Struts (or JSP for that matter), and in need of
> > > some examples that I can get my hands on.
> > >
> > > Specifically, an application that uses "wizard" style, multiple-page
> > > input forms would be very nice. Couple of Struts documents I looked
> > > mention that Struts works well with wizard style application, but I
get
> > > confused when it comes to writing struts-config.xml, JSPs that share
> > > the same ActionForm or Action, etc.. I gotta see it working before I
> > > start building mine.
> > >
> > > Good examples, anywhere, anyone?
> > >
> > > thanks,
> > >
> > > - kazumi
> > >
>
>


Re: wizard style example, anywhere?

Posted by Uwe Pleyer <uw...@up-soft.de>.
Much thanks for this clearfying hack.

In my opinion we should look for a way to identify the pressed button without
refering the label, cause this can be change due to internalization (maybe with
an German locale "<< Prev" Button will be labeled "<< Zurück").

May be someone out there knows a way to have an fixed value that will be passed
back beside the label.

Regards
Uwe

Tharwat Abdul-Malik schrieb:

> I use something like the following in my struts-config.xml file:
>
>     <action    path="/signup"
>                type="SignupAction"
>                name="signupForm"
>               scope="session"
>               input="page1.jsp">
>               <forward name="page1"              path="page1jsp"/>
>               <forward name="page2"              path="page2.jsp"/>
>               <forward name="page3"              path="page3.jsp"/>
>               <forward name="page4"              path="page4.jsp"/>
>               <forward name="success"            path="confirm.jsp"/>
>     </action>
>
> In page1.jsp I declare the following buttons:
>
>                   <html:hidden property="page" value="1"/>
>                   <html:submit>
>                     <bean:message key="button.next"/>
>                   </html:submit>
>
> Page2.jsp:
>
>                   <html:hidden property="page" value="2"/>
>                   <html:submit>
>                     <bean:message key="button.prev"/>
>                   </html:submit>
>
>                   <html:submit>
>                     <bean:message key="button.next"/>
>                   </html:submit>
>
> Page3.jsp
>
>                   <html:hidden property="page" value="3"/>
>                   <html:submit>
>                     <bean:message key="button.prev"/>
>                   </html:submit>
>
>                   <html:submit>
>                     <bean:message key="button.next"/>
>                   </html:submit>
>
> Page4.jsp
>
>                   <html:hidden property="page" value="4"/>
>                   <html:submit>
>                     <bean:message key="button.prev"/>
>                   </html:submit>
>
>                   <html:submit>
>                     <bean:message key="button.finish"/>
>                   </html:submit>
>
> In my SignupForm.java I define all fields for each page. Then I have a
> switch statement in the validate method to validate the data for each page:
>
>     public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> request)
>     {
>
>         ActionErrors errors = new ActionErrors();
>         switch (page)
>         {
>         case 1:
>                 // Validate fields on page 1
>         case 2:
>                ///
>         }
>        return errors;
> }
>
> Finally in the SignupAction.java I check for which button was pressed and
> return the next or previous page:
>
>     public ActionForward perform(ActionMapping mapping,
>                                  ActionForm form,
>                                  HttpServletRequest request,
>                                  HttpServletResponse response)
>     throws IOException, ServletException
>     {
>
>         HttpSession session = request.getSession();
>         SignupForm signupform = (SignupForm) form;
>         int page = signupform.getPage();
>
>         String label = request.getParameter("submit");
>         if (label != null)
>         {
>             if ("<< Prev".equals(label))                // Previous was
> pressed
>             {
>                 return mapping.findForward("page"+(page-1));
>             }
>             else if ("Next >>".equals(label))        // Next was pressed
>             {
>                 return mapping.findForward("page"+(page+1));        //
> Finished was pressed
>             }
>             else if ("Finish".equals(label))
>             {
>                 // Do finish work, add data to database, whatever
>             }
> ..... return(mapping.findForward("success"));
>
> I'm new to struts (about 2 weeks now). I tried to find examples but couldn't
> find any. So I hacked out this. Perhaps if someone has a better way we can
> all learn something new.
>
> I hope this helps.
>
> ----- Original Message -----
> From: <iw...@nttdata.co.jp>
> To: <st...@jakarta.apache.org>
> Sent: Tuesday, April 24, 2001 9:51 AM
> Subject: wizard style example, anywhere?
>
> > Hello struts-users,
> >
> > I am very new to Struts (or JSP for that matter), and in need of
> > some examples that I can get my hands on.
> >
> > Specifically, an application that uses "wizard" style, multiple-page
> > input forms would be very nice. Couple of Struts documents I looked
> > mention that Struts works well with wizard style application, but I get
> > confused when it comes to writing struts-config.xml, JSPs that share
> > the same ActionForm or Action, etc.. I gotta see it working before I
> > start building mine.
> >
> > Good examples, anywhere, anyone?
> >
> > thanks,
> >
> > - kazumi
> >


Re: wizard style example, anywhere?

Posted by Tharwat Abdul-Malik <ta...@grandtalent.com>.
I use something like the following in my struts-config.xml file:

    <action    path="/signup"
               type="SignupAction"
               name="signupForm"
              scope="session"
              input="page1.jsp">
              <forward name="page1"              path="page1jsp"/>
              <forward name="page2"              path="page2.jsp"/>
              <forward name="page3"              path="page3.jsp"/>
              <forward name="page4"              path="page4.jsp"/>
              <forward name="success"            path="confirm.jsp"/>
    </action>

In page1.jsp I declare the following buttons:

                  <html:hidden property="page" value="1"/>
                  <html:submit>
                    <bean:message key="button.next"/>
                  </html:submit>

Page2.jsp:

                  <html:hidden property="page" value="2"/>
                  <html:submit>
                    <bean:message key="button.prev"/>
                  </html:submit>

                  <html:submit>
                    <bean:message key="button.next"/>
                  </html:submit>


Page3.jsp

                  <html:hidden property="page" value="3"/>
                  <html:submit>
                    <bean:message key="button.prev"/>
                  </html:submit>

                  <html:submit>
                    <bean:message key="button.next"/>
                  </html:submit>

Page4.jsp

                  <html:hidden property="page" value="4"/>
                  <html:submit>
                    <bean:message key="button.prev"/>
                  </html:submit>

                  <html:submit>
                    <bean:message key="button.finish"/>
                  </html:submit>


In my SignupForm.java I define all fields for each page. Then I have a
switch statement in the validate method to validate the data for each page:

    public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request)
    {

        ActionErrors errors = new ActionErrors();
        switch (page)
        {
        case 1:
                // Validate fields on page 1
        case 2:
               ///
        }
       return errors;
}


Finally in the SignupAction.java I check for which button was pressed and
return the next or previous page:

    public ActionForward perform(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
    throws IOException, ServletException
    {

        HttpSession session = request.getSession();
        SignupForm signupform = (SignupForm) form;
        int page = signupform.getPage();

        String label = request.getParameter("submit");
        if (label != null)
        {
            if ("<< Prev".equals(label))                // Previous was
pressed
            {
                return mapping.findForward("page"+(page-1));
            }
            else if ("Next >>".equals(label))        // Next was pressed
            {
                return mapping.findForward("page"+(page+1));        //
Finished was pressed
            }
            else if ("Finish".equals(label))
            {
                // Do finish work, add data to database, whatever
            }
..... return(mapping.findForward("success"));


I'm new to struts (about 2 weeks now). I tried to find examples but couldn't
find any. So I hacked out this. Perhaps if someone has a better way we can
all learn something new.

I hope this helps.

----- Original Message -----
From: <iw...@nttdata.co.jp>
To: <st...@jakarta.apache.org>
Sent: Tuesday, April 24, 2001 9:51 AM
Subject: wizard style example, anywhere?


> Hello struts-users,
>
> I am very new to Struts (or JSP for that matter), and in need of
> some examples that I can get my hands on.
>
> Specifically, an application that uses "wizard" style, multiple-page
> input forms would be very nice. Couple of Struts documents I looked
> mention that Struts works well with wizard style application, but I get
> confused when it comes to writing struts-config.xml, JSPs that share
> the same ActionForm or Action, etc.. I gotta see it working before I
> start building mine.
>
> Good examples, anywhere, anyone?
>
> thanks,
>
> - kazumi
>


RE: wizard style example, anywhere?

Posted by Marouane Louah <Ma...@selftrade.com>.
you can try the example provided with the installation 



-----Message d'origine-----
De?: iwanek@nttdata.co.jp [mailto:iwanek@nttdata.co.jp]
Envoye?: mardi 24 avril 2001 15:51
A?: struts-user@jakarta.apache.org
Objet?: wizard style example, anywhere?


Hello struts-users,

I am very new to Struts (or JSP for that matter), and in need of
some examples that I can get my hands on.

Specifically, an application that uses "wizard" style, multiple-page
input forms would be very nice. Couple of Struts documents I looked
mention that Struts works well with wizard style application, but I get
confused when it comes to writing struts-config.xml, JSPs that share
the same ActionForm or Action, etc.. I gotta see it working before I
start building mine.

Good examples, anywhere, anyone?

thanks,

- kazumi