A couple of Newbie questionsAdd a hidden field to your jsp page, and a page attribute 
to your ActionForm.

<html:form>
<html:hidden property="page">
.
.
.
Then you can query your form for the page that was submitted (form.getPage()).

  ----- Original Message ----- 
  From: Kevin Roast 


  Hi, 

  I am currently working with Struts for the first time, I have a couple of "newbie" 
questions, my apologies if they are obvious to Struts veterans :-)

  1. I have an application where I use a single ActionForm instance to collect data 
over several pages (like a wizard). Each step of the wizard requires different fields 
on the Form to be validated. How do I know which page of my wizard I am on in my 
validate() method? Currently I am using some nasty code like this to work out which 
page to validate:

     public ActionErrors validate(ActionMapping mapping, HttpServletRequest req) 
     { 
        // get our current Form page 
        String strPage = mapping.getPath().substring(1); 
        
        // a switch statement provides different validation for each page. 
        . 
     } 

  Is there a better solution to this as I don't really want to create a Form object 
per page as logically it's one long form - or is this not the right approach? I'm 
concerned about the number of Form objects that will be required for a large 
application...

  2. For the same application, I am using one single Action to manage multiple pages 
in the wizard. I am having a similar problem to 1. above where in the execute() method 
I don't know which page I've been submitted from. Currently I have an unpleasant 
solution where I place a hidden control on the page which I examine to work out what 
page I'm on:

     public ActionForward execute(ActionMapping mapping, ActionForm form, 
        HttpServletRequest req, HttpServletResponse res) 
     { 
        // get the parameter which indicates the page of the form that we are on 
        String strPage = req.getParameter("page"); 
        String strSubmit = req.getParameter("submit"); 
        System.out.println("\tWizard page parameter: " + strPage + "\tsubmit value: " 
+ strSubmit); 
        
        // Step 1 of the wizard 
        if (strPage.equals(PAGE_STEP_1)) 
        . 
     } 

  I have the same problem where there are multiple submit buttons i.e. which one was 
pressed without testing the string value of the button label (which may have been 
I18Ned!).

  Is there a better solution to this or should I use a separate Action for every page? 
Again, I have similar reservations as above...

  3. "Nesting" to an arbitrary form from any location and "returning" back again. If I 
have an application that allow the user to jump to the same search screen from 
multiple locations and be able to "return" to the previous screen. Is there a way of 
doing this in Struts? My problem is that my action-mappings are hardcoded at the start 
of the application - I effectively need a "dynamic" return after a "nest" to an 
arbitrary page. Currently I am thinking of keeping a "stack" of the pages that I nest 
to in the users session and then forcing a return back to the last item page on the 
stack when I "return". Is there a better solution to this using the Struts framework?



  Thanks for your time, 

  Kev 
  -- 
  +44 (0)1628 589125 
  [EMAIL PROTECTED] 



------------------------------------------------------------------------------


  --
  To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
  For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to