Try this. Works for me.

          <html:submit property="<%=Constants.SUBMIT %>">
                  <bean:message key="changePassword.submit"/>
      </html:submit>

Where Constants.java contains fixed constants. bean:message can be an
internationalized label which gets displayed to the user.
One other superior approach is to keep all the Constants in a properties
file and write your own PropertyFile manager to show the properties. The
advantage is that if you use the approach , the value is kept in the jsp
page at cmpile time. So if in the future you change Constants.java, the
value will not be reflected in the jsp page(cause it is already kept there
at compile time). Defer this till runtime by using a properties file to
store your contants. So even if you cnage your constants properties file,
you don't have to re-cmpile your jsp pages.

When you use the above approach, check for this name (in name=value) pairs
in your Action class and do your logic...So when the user clicks on the
Submit button, the name=value pair is send. Discard the value and look for
the name...

//Action class
---------------

    if( request.getParameter(Constants.SUBMIT)  != null )
      {
                //do something
      }


-----Original Message-----
From: Uwe Pleyer [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 26, 2001 4:31 AM
To: [EMAIL PROTECTED]
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: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> 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
> >

Reply via email to