You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brian McSweeney <br...@aurium.net> on 2003/05/29 15:42:21 UTC

Form validation over multiple pages

Hi all,

I'm almost there with using the validator over several pages with a single form. 
However I'm getting a strange little error. The first page is validating fine, and it 
doesn't seem to try to validate the info required on the second page - correct. 
However once I try to validate the second page, the javascript validates correctly, 
but the server side validation returns an error saying the first page's required field 
needs validating. 

I think it might be because I'm not sure how to pass the page parameter to the action. 
I've tried using a html:hidden tag. Anyway, snippets from the jsps, struts config and 
validation.xml file are included below. 

If someone could help me out I'd be very grateful. Thanks very much,
Brian.




My first jsp named "validatestep1.jsp" looks like:

<html:javascript formName="validateForm" page="1"/>

<html:form action="/secure/validateStep1.jspa" onsubmit="return validateValidateForm(this);" method="post">
    <html:hidden name="validateForm" property="page" value="1" />
<table>
 <tr><td>username</td>
  <td><html:text name="validateForm" property="userName" /></td>
 </tr>
 <tr>
  <td colspan="2" align="center">
   <html:image border="0" page="/images/button_submit.gif"/>
  </td>
  </tr>
</table>
</html:form>

My second jsp named "validatestep2.jsp" looks like

<html:javascript formName="validateForm" page="2"/>
<html:form action="/secure/validateStep2.jspa" onsubmit="return validateValidateForm(this);" method="post">
    <html:hidden name="validateForm" property="page" value="2" />
<table>
 <tr>
  <td>credit card with no spaces or dashes</td>
  <td><html:text name="validateForm" property="creditCard" /></td>
 </tr>
 <tr>
  <td colspan="2" align="center">
   <html:image border="0" page="/images/button_submit.gif"/>
  </td>
  </tr>
</table>
</html:form>


in my struts config I have

    <action
      path="/secure/validateStep1"
      type="ValidateStep1Action"
      name="validateForm"
      scope="session"
      input="/validatestep1.jsp"
      unknown="false"
      validate="true"
    >
      <forward
        name="success"
        path="/validatestep2.jsp"
        redirect="false"
      />

and then

    <action
      path="/secure/validateStep2"
      type="ValidateStep2Action"
      name="validateForm"
      scope="session"
      input="/validatestep2.jsp"
      unknown="false"
      validate="true"
    >
      <forward
        name="success"
        path="/validated.jsp"
        redirect="false"
      />

In my validation.xml file I have


      <form name="validateForm">
              <field property="userName" depends="required,minlength" page="1">

              <field property="creditCard" depends="required,creditCard" page="2">


Re: Form validation over multiple pages - Solution Found - Weird

Posted by Brian McSweeney <br...@aurium.net>.
Could anyone tell me if I am right in what I think the problem is here?

I use a web-filter for ssl. I use form-beans that have session scope
in a wizard, one of whose steps requires ssl.

However when the ssl step gets intercepted by the web filter,
the form-bean that should be in session scope seems to be
cleared/re-created.

Any ideas as to why?

Brian

----- Original Message -----
From: "Brian McSweeney" <br...@aurium.net>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, May 30, 2003 11:04 AM
Subject: Re: Form validation over multiple pages - Solution Found - Weird


> Thanks for the help on this guys. It was good to know people had
> it working.
>
> I've got it to work now. The reason it wasn't working was that for
> all secure pages I use a ssl filter which takes any request mapped like
> "/secure" and sends it over ssl.
>
> For example, if I want to send the
> info for the first jsp I send it to:
>
> <html:form action="/secure/validateStep1.jspa"
>
> the weird thing is - the form object isn't staying in session scope if I
use
> the ssl filter and so the second page's validation was failing because the
> object wasn't in session scope anymore. However, once I removed the
> "secure" it works fine.
>
> Reading other threads, I think this might be to do with a redirect ( if
the
> filter is doing a re-direct, then a new http request might be getting
> created
> and thus a new form object gets created )
>
> Anyway, thanks for all the help, and if anyone knows how I could continue
> using the filter and keep the form object in session scope I'd really
> appreciate
> any ideas!
>
> Brian
>
>
> ----- Original Message -----
> From: "Paul Curren" <pc...@cisco.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Thursday, May 29, 2003 6:00 PM
> Subject: Re: Form validation over multiple pages
>
>
> > Hi there,
> > I've been doing this exact thing the last couple of days and I have it
> > working.
> > My html:hidden tags looks like -
> >
> > <html:hidden property="page" value="1"/>
> > i.e. only difference is I don't explicitly specify the form name.
> >
> > My form is a DynaValidatorForm and a bug which i've seen from rc1 right
> > up to the May 26 nightly so far means that I need to explicity define
> > the page property on the form e.g.
> >
> > <form-property name="page" type="java.lang.Integer" />
> >
> > Hope this helps,
> >
> > Paul C
> >
> >
> > Brian McSweeney wrote:
> >
> > >With a little further investigation I see that the page value does not
> > >get set in the validationForm using html:hidden approach as outlined
> > >below. Ie, this doen't work:
> > >
> > >    <html:hidden name="validateForm" property="page" value="1" />
> > >
> > >When I print out the value of the page field in the action, it is still
> set
> > >to zero.
> > >
> > >How do you set the page property?
> > >
> > >Also, this seems to imply the validator is VERY shaky over multiple
> > >pages. For example, the properties on my second page are marked
> > >as required, and they don't get validated in the first action (this
seems
> > >to show that the page based validation is working), yet on the second
> > >page, the associated action tries to validate the page 1 properties!!!
> > >
> > >Arrrg!! What's going on! Has anyone got this to work?
> > >
> > >Brian
> > >
> > >
> > >----- Original Message -----
> > >From: "Brian McSweeney" <br...@aurium.net>
> > >To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > >Sent: Thursday, May 29, 2003 2:42 PM
> > >Subject: Form validation over multiple pages
> > >
> > >
> > >Hi all,
> > >
> > >I'm almost there with using the validator over several pages with a
> single
> > >form.
> > >However I'm getting a strange little error. The first page is
validating
> > >fine, and it
> > >doesn't seem to try to validate the info required on the second page -
> > >correct.
> > >However once I try to validate the second page, the javascript
validates
> > >correctly,
> > >but the server side validation returns an error saying the first page's
> > >required field
> > >needs validating.
> > >
> > >I think it might be because I'm not sure how to pass the page parameter
> to
> > >the action.
> > >I've tried using a html:hidden tag. Anyway, snippets from the jsps,
> struts
> > >config and
> > >validation.xml file are included below.
> > >
> > >If someone could help me out I'd be very grateful. Thanks very much,
> > >Brian.
> > >
> > >
> > >
> > >
> > >My first jsp named "validatestep1.jsp" looks like:
> > >
> > ><html:javascript formName="validateForm" page="1"/>
> > >
> > ><html:form action="/secure/validateStep1.jspa" onsubmit="return
> > >validateValidateForm(this);" method="post">
> > >    <html:hidden name="validateForm" property="page" value="1" />
> > ><table>
> > > <tr><td>username</td>
> > >  <td><html:text name="validateForm" property="userName" /></td>
> > > </tr>
> > > <tr>
> > >  <td colspan="2" align="center">
> > >   <html:image border="0" page="/images/button_submit.gif"/>
> > >  </td>
> > >  </tr>
> > ></table>
> > ></html:form>
> > >
> > >My second jsp named "validatestep2.jsp" looks like
> > >
> > ><html:javascript formName="validateForm" page="2"/>
> > ><html:form action="/secure/validateStep2.jspa" onsubmit="return
> > >validateValidateForm(this);" method="post">
> > >    <html:hidden name="validateForm" property="page" value="2" />
> > ><table>
> > > <tr>
> > >  <td>credit card with no spaces or dashes</td>
> > >  <td><html:text name="validateForm" property="creditCard" /></td>
> > > </tr>
> > > <tr>
> > >  <td colspan="2" align="center">
> > >   <html:image border="0" page="/images/button_submit.gif"/>
> > >  </td>
> > >  </tr>
> > ></table>
> > ></html:form>
> > >
> > >
> > >in my struts config I have
> > >
> > >    <action
> > >      path="/secure/validateStep1"
> > >      type="ValidateStep1Action"
> > >      name="validateForm"
> > >      scope="session"
> > >      input="/validatestep1.jsp"
> > >      unknown="false"
> > >      validate="true"
> > >    >
> > >      <forward
> > >        name="success"
> > >        path="/validatestep2.jsp"
> > >        redirect="false"
> > >      />
> > >
> > >and then
> > >
> > >    <action
> > >      path="/secure/validateStep2"
> > >      type="ValidateStep2Action"
> > >      name="validateForm"
> > >      scope="session"
> > >      input="/validatestep2.jsp"
> > >      unknown="false"
> > >      validate="true"
> > >    >
> > >      <forward
> > >        name="success"
> > >        path="/validated.jsp"
> > >        redirect="false"
> > >      />
> > >
> > >In my validation.xml file I have
> > >
> > >
> > >      <form name="validateForm">
> > >              <field property="userName" depends="required,minlength"
> > >page="1">
> > >
> > >              <field property="creditCard"
depends="required,creditCard"
> > >page="2">
> > >
> > >
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >
> > >
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Form validation over multiple pages - Solution Found - Weird

Posted by Brian McSweeney <br...@aurium.net>.
Thanks for the help on this guys. It was good to know people had
it working.

I've got it to work now. The reason it wasn't working was that for
all secure pages I use a ssl filter which takes any request mapped like
"/secure" and sends it over ssl.

For example, if I want to send the
info for the first jsp I send it to:

<html:form action="/secure/validateStep1.jspa"

the weird thing is - the form object isn't staying in session scope if I use
the ssl filter and so the second page's validation was failing because the
object wasn't in session scope anymore. However, once I removed the
"secure" it works fine.

Reading other threads, I think this might be to do with a redirect ( if the
filter is doing a re-direct, then a new http request might be getting
created
and thus a new form object gets created )

Anyway, thanks for all the help, and if anyone knows how I could continue
using the filter and keep the form object in session scope I'd really
appreciate
any ideas!

Brian


----- Original Message -----
From: "Paul Curren" <pc...@cisco.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, May 29, 2003 6:00 PM
Subject: Re: Form validation over multiple pages


> Hi there,
> I've been doing this exact thing the last couple of days and I have it
> working.
> My html:hidden tags looks like -
>
> <html:hidden property="page" value="1"/>
> i.e. only difference is I don't explicitly specify the form name.
>
> My form is a DynaValidatorForm and a bug which i've seen from rc1 right
> up to the May 26 nightly so far means that I need to explicity define
> the page property on the form e.g.
>
> <form-property name="page" type="java.lang.Integer" />
>
> Hope this helps,
>
> Paul C
>
>
> Brian McSweeney wrote:
>
> >With a little further investigation I see that the page value does not
> >get set in the validationForm using html:hidden approach as outlined
> >below. Ie, this doen't work:
> >
> >    <html:hidden name="validateForm" property="page" value="1" />
> >
> >When I print out the value of the page field in the action, it is still
set
> >to zero.
> >
> >How do you set the page property?
> >
> >Also, this seems to imply the validator is VERY shaky over multiple
> >pages. For example, the properties on my second page are marked
> >as required, and they don't get validated in the first action (this seems
> >to show that the page based validation is working), yet on the second
> >page, the associated action tries to validate the page 1 properties!!!
> >
> >Arrrg!! What's going on! Has anyone got this to work?
> >
> >Brian
> >
> >
> >----- Original Message -----
> >From: "Brian McSweeney" <br...@aurium.net>
> >To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> >Sent: Thursday, May 29, 2003 2:42 PM
> >Subject: Form validation over multiple pages
> >
> >
> >Hi all,
> >
> >I'm almost there with using the validator over several pages with a
single
> >form.
> >However I'm getting a strange little error. The first page is validating
> >fine, and it
> >doesn't seem to try to validate the info required on the second page -
> >correct.
> >However once I try to validate the second page, the javascript validates
> >correctly,
> >but the server side validation returns an error saying the first page's
> >required field
> >needs validating.
> >
> >I think it might be because I'm not sure how to pass the page parameter
to
> >the action.
> >I've tried using a html:hidden tag. Anyway, snippets from the jsps,
struts
> >config and
> >validation.xml file are included below.
> >
> >If someone could help me out I'd be very grateful. Thanks very much,
> >Brian.
> >
> >
> >
> >
> >My first jsp named "validatestep1.jsp" looks like:
> >
> ><html:javascript formName="validateForm" page="1"/>
> >
> ><html:form action="/secure/validateStep1.jspa" onsubmit="return
> >validateValidateForm(this);" method="post">
> >    <html:hidden name="validateForm" property="page" value="1" />
> ><table>
> > <tr><td>username</td>
> >  <td><html:text name="validateForm" property="userName" /></td>
> > </tr>
> > <tr>
> >  <td colspan="2" align="center">
> >   <html:image border="0" page="/images/button_submit.gif"/>
> >  </td>
> >  </tr>
> ></table>
> ></html:form>
> >
> >My second jsp named "validatestep2.jsp" looks like
> >
> ><html:javascript formName="validateForm" page="2"/>
> ><html:form action="/secure/validateStep2.jspa" onsubmit="return
> >validateValidateForm(this);" method="post">
> >    <html:hidden name="validateForm" property="page" value="2" />
> ><table>
> > <tr>
> >  <td>credit card with no spaces or dashes</td>
> >  <td><html:text name="validateForm" property="creditCard" /></td>
> > </tr>
> > <tr>
> >  <td colspan="2" align="center">
> >   <html:image border="0" page="/images/button_submit.gif"/>
> >  </td>
> >  </tr>
> ></table>
> ></html:form>
> >
> >
> >in my struts config I have
> >
> >    <action
> >      path="/secure/validateStep1"
> >      type="ValidateStep1Action"
> >      name="validateForm"
> >      scope="session"
> >      input="/validatestep1.jsp"
> >      unknown="false"
> >      validate="true"
> >    >
> >      <forward
> >        name="success"
> >        path="/validatestep2.jsp"
> >        redirect="false"
> >      />
> >
> >and then
> >
> >    <action
> >      path="/secure/validateStep2"
> >      type="ValidateStep2Action"
> >      name="validateForm"
> >      scope="session"
> >      input="/validatestep2.jsp"
> >      unknown="false"
> >      validate="true"
> >    >
> >      <forward
> >        name="success"
> >        path="/validated.jsp"
> >        redirect="false"
> >      />
> >
> >In my validation.xml file I have
> >
> >
> >      <form name="validateForm">
> >              <field property="userName" depends="required,minlength"
> >page="1">
> >
> >              <field property="creditCard" depends="required,creditCard"
> >page="2">
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Form validation over multiple pages

Posted by Paul Curren <pc...@cisco.com>.
Hi there,
I've been doing this exact thing the last couple of days and I have it 
working.
My html:hidden tags looks like -

<html:hidden property="page" value="1"/>
i.e. only difference is I don't explicitly specify the form name.

My form is a DynaValidatorForm and a bug which i've seen from rc1 right 
up to the May 26 nightly so far means that I need to explicity define 
the page property on the form e.g.

<form-property name="page" type="java.lang.Integer" />

Hope this helps,

Paul C


Brian McSweeney wrote:

>With a little further investigation I see that the page value does not
>get set in the validationForm using html:hidden approach as outlined
>below. Ie, this doen't work:
>
>    <html:hidden name="validateForm" property="page" value="1" />
>
>When I print out the value of the page field in the action, it is still set
>to zero.
>
>How do you set the page property?
>
>Also, this seems to imply the validator is VERY shaky over multiple
>pages. For example, the properties on my second page are marked
>as required, and they don't get validated in the first action (this seems
>to show that the page based validation is working), yet on the second
>page, the associated action tries to validate the page 1 properties!!!
>
>Arrrg!! What's going on! Has anyone got this to work?
>
>Brian
>
>
>----- Original Message -----
>From: "Brian McSweeney" <br...@aurium.net>
>To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>Sent: Thursday, May 29, 2003 2:42 PM
>Subject: Form validation over multiple pages
>
>
>Hi all,
>
>I'm almost there with using the validator over several pages with a single
>form.
>However I'm getting a strange little error. The first page is validating
>fine, and it
>doesn't seem to try to validate the info required on the second page -
>correct.
>However once I try to validate the second page, the javascript validates
>correctly,
>but the server side validation returns an error saying the first page's
>required field
>needs validating.
>
>I think it might be because I'm not sure how to pass the page parameter to
>the action.
>I've tried using a html:hidden tag. Anyway, snippets from the jsps, struts
>config and
>validation.xml file are included below.
>
>If someone could help me out I'd be very grateful. Thanks very much,
>Brian.
>
>
>
>
>My first jsp named "validatestep1.jsp" looks like:
>
><html:javascript formName="validateForm" page="1"/>
>
><html:form action="/secure/validateStep1.jspa" onsubmit="return
>validateValidateForm(this);" method="post">
>    <html:hidden name="validateForm" property="page" value="1" />
><table>
> <tr><td>username</td>
>  <td><html:text name="validateForm" property="userName" /></td>
> </tr>
> <tr>
>  <td colspan="2" align="center">
>   <html:image border="0" page="/images/button_submit.gif"/>
>  </td>
>  </tr>
></table>
></html:form>
>
>My second jsp named "validatestep2.jsp" looks like
>
><html:javascript formName="validateForm" page="2"/>
><html:form action="/secure/validateStep2.jspa" onsubmit="return
>validateValidateForm(this);" method="post">
>    <html:hidden name="validateForm" property="page" value="2" />
><table>
> <tr>
>  <td>credit card with no spaces or dashes</td>
>  <td><html:text name="validateForm" property="creditCard" /></td>
> </tr>
> <tr>
>  <td colspan="2" align="center">
>   <html:image border="0" page="/images/button_submit.gif"/>
>  </td>
>  </tr>
></table>
></html:form>
>
>
>in my struts config I have
>
>    <action
>      path="/secure/validateStep1"
>      type="ValidateStep1Action"
>      name="validateForm"
>      scope="session"
>      input="/validatestep1.jsp"
>      unknown="false"
>      validate="true"
>    >
>      <forward
>        name="success"
>        path="/validatestep2.jsp"
>        redirect="false"
>      />
>
>and then
>
>    <action
>      path="/secure/validateStep2"
>      type="ValidateStep2Action"
>      name="validateForm"
>      scope="session"
>      input="/validatestep2.jsp"
>      unknown="false"
>      validate="true"
>    >
>      <forward
>        name="success"
>        path="/validated.jsp"
>        redirect="false"
>      />
>
>In my validation.xml file I have
>
>
>      <form name="validateForm">
>              <field property="userName" depends="required,minlength"
>page="1">
>
>              <field property="creditCard" depends="required,creditCard"
>page="2">
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Form validation over multiple pages

Posted by Brian McSweeney <br...@aurium.net>.
With a little further investigation I see that the page value does not
get set in the validationForm using html:hidden approach as outlined
below. Ie, this doen't work:

    <html:hidden name="validateForm" property="page" value="1" />

When I print out the value of the page field in the action, it is still set
to zero.

How do you set the page property?

Also, this seems to imply the validator is VERY shaky over multiple
pages. For example, the properties on my second page are marked
as required, and they don't get validated in the first action (this seems
to show that the page based validation is working), yet on the second
page, the associated action tries to validate the page 1 properties!!!

Arrrg!! What's going on! Has anyone got this to work?

Brian


----- Original Message -----
From: "Brian McSweeney" <br...@aurium.net>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, May 29, 2003 2:42 PM
Subject: Form validation over multiple pages


Hi all,

I'm almost there with using the validator over several pages with a single
form.
However I'm getting a strange little error. The first page is validating
fine, and it
doesn't seem to try to validate the info required on the second page -
correct.
However once I try to validate the second page, the javascript validates
correctly,
but the server side validation returns an error saying the first page's
required field
needs validating.

I think it might be because I'm not sure how to pass the page parameter to
the action.
I've tried using a html:hidden tag. Anyway, snippets from the jsps, struts
config and
validation.xml file are included below.

If someone could help me out I'd be very grateful. Thanks very much,
Brian.




My first jsp named "validatestep1.jsp" looks like:

<html:javascript formName="validateForm" page="1"/>

<html:form action="/secure/validateStep1.jspa" onsubmit="return
validateValidateForm(this);" method="post">
    <html:hidden name="validateForm" property="page" value="1" />
<table>
 <tr><td>username</td>
  <td><html:text name="validateForm" property="userName" /></td>
 </tr>
 <tr>
  <td colspan="2" align="center">
   <html:image border="0" page="/images/button_submit.gif"/>
  </td>
  </tr>
</table>
</html:form>

My second jsp named "validatestep2.jsp" looks like

<html:javascript formName="validateForm" page="2"/>
<html:form action="/secure/validateStep2.jspa" onsubmit="return
validateValidateForm(this);" method="post">
    <html:hidden name="validateForm" property="page" value="2" />
<table>
 <tr>
  <td>credit card with no spaces or dashes</td>
  <td><html:text name="validateForm" property="creditCard" /></td>
 </tr>
 <tr>
  <td colspan="2" align="center">
   <html:image border="0" page="/images/button_submit.gif"/>
  </td>
  </tr>
</table>
</html:form>


in my struts config I have

    <action
      path="/secure/validateStep1"
      type="ValidateStep1Action"
      name="validateForm"
      scope="session"
      input="/validatestep1.jsp"
      unknown="false"
      validate="true"
    >
      <forward
        name="success"
        path="/validatestep2.jsp"
        redirect="false"
      />

and then

    <action
      path="/secure/validateStep2"
      type="ValidateStep2Action"
      name="validateForm"
      scope="session"
      input="/validatestep2.jsp"
      unknown="false"
      validate="true"
    >
      <forward
        name="success"
        path="/validated.jsp"
        redirect="false"
      />

In my validation.xml file I have


      <form name="validateForm">
              <field property="userName" depends="required,minlength"
page="1">

              <field property="creditCard" depends="required,creditCard"
page="2">



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org