You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jeremy Jardin <je...@gmail.com> on 2006/07/25 17:03:32 UTC

pb using validator with struts1.2.9

Hi,

I'm trying to use struts plugin validator to check a big form.. and it works
well.. but I've a little pb with validwhen constraint;

I've written something like this :

            <field property="enterpriseName"
                depends="validwhen">
                <arg0 key="error.inscription.entreprise.nom" />
                <var>
                    <var-name>test</var-name>
                    <var-value>((subscriptionType=="2")or
(subscriptionType=="3")or(subscriptionType=="4"))</var-value>
                </var>
            </field>

I just want to check the field 'enterpriseName' is not empty when I submit,
but only if my select field 'subscriptionType" is more than 1. (2,3 or4)

It does not work.

why ??


-- 
~ jebmail ~

Re: pb using validator with struts1.2.9

Posted by Jeremy Jardin <je...@gmail.com>.
Ok it works well now !

I didn't know that the validwhen rule was server-side validation.. so I
expected to
have js popup with the 'validwhen' worries ..

It' s ok now thanks a lot for you help.

++

On 7/26/06, Adam Gordon <ad...@readytalk.com> wrote:
>
> Jeremy-
>
> Sorry you're still having problems.
>
> Regarding the missing resource, I think it will either print out "null"
> (in the error-printing JSP code) or throw an exception if it cannot find
> a message resource so you should at least see something like that.
>
> Are you sure validation is even being run?  I.e., are your validation
> rules for other widgets being applied?
>
> I think the contents of the select box are irrelevant as whatever value
> is selected (i.e., the value of the "value" attribute on the <option>
> element that is currently selected) will be the value used when the
> setEnterpriseName(String) method is called on your form bean.
>
> Let's try this.  try changing "validwhen" to "required" and make sure it
> validates the field has something in it.  If that works, then we know
> your validation is working for that field and the problem is definately
> with "validwhen."
>
> I fought with "validwhen" for two days before just using the validate()
> method on the ValidatorForm.  Since server-side validation has to be
> done anyway, it's not like this detracts from the functionality.
>
> -Adam
>
> Jeremy Jardin wrote:
> > -Adam,
> >
> > first, thanks for all those explications. but I've still a problem with
> > my
> > validator using 'validwhen'.
> >
> > I've seen first, that I don't have any "errors.validwhen = mymessage"
> > line
> > in my messageResource file ?
> > I guess I need to add it and I did it.
> >
> > Otherwise, I've now clearly understood (I think so...) how It work.. but
> > have a look .. I've tried that :
> >
> >            <field property="enterpriseName" depends="validwhen">
> >                <arg0 key="error.inscription.entreprise.nom" />
> >                <var>
> >                    <var-name>test</var-name>
> >                    <var-value>((*this* ==  "hello"))</var-value>
> >                </var>
> >            </field>
> >
> > I think it sould warn me each time my field is not "hello".. but it does
> > not.
> >
> > I think now it's time to explain you clearly what I'm trying to do.
> >
> > I've got a select tag wich determine if some fieds appear or not.
> > "if select value > 1, some input:text tags appears, and there aren't
> > present
> > is select value=1."
> >
> > Maybe should I "hide" fields rather than "not display" fields.. ??
> >
> > thx
> >
> >
> >
> >
> >
> >
> >
> > On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
> >>
> >> Jeremy-
> >>
> >> Ok, sanity-check time.  Make sure your field names are all spelled
> >> correctly.  Also, are any errors being output to the form?  I had
> > errors
> >> displaying and it turned out that the validator was doing exactly what
> > I
> >> was asking it to do and the problem was that I just didn't understand
> >> the "validwhen" validation rule.
> >>
> >> I've found that overriding toString() on my form bean and having it
> > dump
> >> the contents of all the fields is an excellent way to see with what
> >> values the bean is being populated.  You can then call
> >> System.out.println(this) (or use a logger) in your bean's
> > validate(...)
> >> method to see what values your bean has.  Make sure the
> > subscriptionType
> >> is set to the value you expect.
> >>
> >> Also, your rule basically reads now as "the field enterpriseName is
> >> valid when the subscription type is greater than or equal to 1."   So,
> >> e.g., if your subscription type is a drop down list that only contains
> >> the values 1,2,3,4, the enterpriseName field will always be valid.
> >>
> >> Give that a whirl and let us know.
> >>
> >> cheers,
> >>
> >> -Adam
> >>
> >> Jeremy Jardin wrote:
> >> > -Adam,
> >> >
> >> > I've just changed my conf like that :
> >> >
> >> >            <field property="enterpriseName"
> >> >                depends="validwhen">
> >> >                <arg0 key="error.inscription.entreprise.nom" />
> >> >                <var>
> >> >                    <var-name>test</var-name>
> >> >                    <var-value>(subscriptionType>=1)</var-value>
> >> >                </var>
> >> >            </field>
> >> >
> >> > but, it still does not work..
> >> >
> >> > On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
> >> >>
> >> >> Jeremy-
> >> >>
> >> >> At first glance, I think you need to modify your parenthesis.  Per
> > the
> >> >> Validation docs at
> >> >> http://struts.apache.org/1.2.9/userGuide/dev_validator.html, only
> > two
> >> >> items may be joined with "and" or "or."  I don't know if that means
> >> > you
> >> >> can only have a max of two items or a max of two items per
> > parends...
> >> >>
> >> >> Secondly, I had a bunch of problems with "validwhen" and finally
> >> >> resorted to implementing my own solution in my ValidatorForm's
> >> >> validate(...) method because it appears that 'validwhen' is rather
> >> >> basic.  It basically says "field A is valid when..."  In my
> >> > experience,
> >> >> "validwhen" doesn't chain well with other validation rules.
> >> >>
> >> >> Alternatively, you could rewrite your rules to say:
> >> > ((subscriptionType
> >> >> >= 2) and (subscriptionType &lt;= 4)).  Note the &lt;, you'll get
> >> >> errors if you use a < character.  I assume you validate that
> >> >> subscriptionType is an integer on [1,4].  Also, you don't need
> > quotes
> >> >> around the numbers.  Struts is smart enough to try numbers first
> > and
> >> >> then if that doesn't work, it resorts to Strings.  Besides, I'm not
> >> > sure
> >> >> the functionality you want is to compare Strings using
> > inequalities...
> >> >>
> >> >> Hope this helps.
> >> >>
> >> >> -Adam
> >> >>
> >> >> Jeremy Jardin wrote:
> >> >> > Hi,
> >> >> >
> >> >> > I'm trying to use struts plugin validator to check a big form..
> > and
> >> > it
> >> >> > works
> >> >> > well.. but I've a little pb with validwhen constraint;
> >> >> >
> >> >> > I've written something like this :
> >> >> >
> >> >> >            <field property="enterpriseName"
> >> >> >                depends="validwhen">
> >> >> >                <arg0 key="error.inscription.entreprise.nom" />
> >> >> >                <var>
> >> >> >                    <var-name>test</var-name>
> >> >> >                    <var-value>((subscriptionType=="2")or
> >> >> > (subscriptionType=="3")or(subscriptionType=="4"))</var-value>
> >> >> >                </var>
> >> >> >            </field>
> >> >> >
> >> >> > I just want to check the field 'enterpriseName' is not empty when
> > I
> >> >> > submit,
> >> >> > but only if my select field 'subscriptionType" is more than 1.
> > (2,3
> >> > or4)
> >> >> >
> >> >> > It does not work.
> >> >> >
> >> >> > why ??
> >> >> >
> >> >> >
> >> >>
> >> >>
> > ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> >> For additional commands, e-mail: user-help@struts.apache.org
> >> >>
> >> >>
> >> >
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
~ jebmail ~

Re: pb using validator with struts1.2.9

Posted by Adam Gordon <ad...@readytalk.com>.
Jeremy-

Sorry you're still having problems.

Regarding the missing resource, I think it will either print out "null" 
(in the error-printing JSP code) or throw an exception if it cannot find 
a message resource so you should at least see something like that.

Are you sure validation is even being run?  I.e., are your validation 
rules for other widgets being applied?

I think the contents of the select box are irrelevant as whatever value 
is selected (i.e., the value of the "value" attribute on the <option> 
element that is currently selected) will be the value used when the 
setEnterpriseName(String) method is called on your form bean.

Let's try this.  try changing "validwhen" to "required" and make sure it 
validates the field has something in it.  If that works, then we know 
your validation is working for that field and the problem is definately 
with "validwhen."

I fought with "validwhen" for two days before just using the validate() 
method on the ValidatorForm.  Since server-side validation has to be 
done anyway, it's not like this detracts from the functionality.

-Adam

Jeremy Jardin wrote:
> -Adam,
>
> first, thanks for all those explications. but I've still a problem with
> my
> validator using 'validwhen'.
>
> I've seen first, that I don't have any "errors.validwhen = mymessage"
> line
> in my messageResource file ?
> I guess I need to add it and I did it.
>
> Otherwise, I've now clearly understood (I think so...) how It work.. but
> have a look .. I've tried that :
>
>            <field property="enterpriseName" depends="validwhen">
>                <arg0 key="error.inscription.entreprise.nom" />
>                <var>
>                    <var-name>test</var-name>
>                    <var-value>((*this* ==  "hello"))</var-value>
>                </var>
>            </field>
>
> I think it sould warn me each time my field is not "hello".. but it does
> not.
>
> I think now it's time to explain you clearly what I'm trying to do.
>
> I've got a select tag wich determine if some fieds appear or not.
> "if select value > 1, some input:text tags appears, and there aren't
> present
> is select value=1."
>
> Maybe should I "hide" fields rather than "not display" fields.. ??
>
> thx
>
>
>
>
>
>
>
> On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
>>
>> Jeremy-
>>
>> Ok, sanity-check time.  Make sure your field names are all spelled
>> correctly.  Also, are any errors being output to the form?  I had
> errors
>> displaying and it turned out that the validator was doing exactly what
> I
>> was asking it to do and the problem was that I just didn't understand
>> the "validwhen" validation rule.
>>
>> I've found that overriding toString() on my form bean and having it
> dump
>> the contents of all the fields is an excellent way to see with what
>> values the bean is being populated.  You can then call
>> System.out.println(this) (or use a logger) in your bean's
> validate(...)
>> method to see what values your bean has.  Make sure the
> subscriptionType
>> is set to the value you expect.
>>
>> Also, your rule basically reads now as "the field enterpriseName is
>> valid when the subscription type is greater than or equal to 1."   So,
>> e.g., if your subscription type is a drop down list that only contains
>> the values 1,2,3,4, the enterpriseName field will always be valid.
>>
>> Give that a whirl and let us know.
>>
>> cheers,
>>
>> -Adam
>>
>> Jeremy Jardin wrote:
>> > -Adam,
>> >
>> > I've just changed my conf like that :
>> >
>> >            <field property="enterpriseName"
>> >                depends="validwhen">
>> >                <arg0 key="error.inscription.entreprise.nom" />
>> >                <var>
>> >                    <var-name>test</var-name>
>> >                    <var-value>(subscriptionType>=1)</var-value>
>> >                </var>
>> >            </field>
>> >
>> > but, it still does not work..
>> >
>> > On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
>> >>
>> >> Jeremy-
>> >>
>> >> At first glance, I think you need to modify your parenthesis.  Per
> the
>> >> Validation docs at
>> >> http://struts.apache.org/1.2.9/userGuide/dev_validator.html, only
> two
>> >> items may be joined with "and" or "or."  I don't know if that means
>> > you
>> >> can only have a max of two items or a max of two items per
> parends...
>> >>
>> >> Secondly, I had a bunch of problems with "validwhen" and finally
>> >> resorted to implementing my own solution in my ValidatorForm's
>> >> validate(...) method because it appears that 'validwhen' is rather
>> >> basic.  It basically says "field A is valid when..."  In my
>> > experience,
>> >> "validwhen" doesn't chain well with other validation rules.
>> >>
>> >> Alternatively, you could rewrite your rules to say:
>> > ((subscriptionType
>> >> >= 2) and (subscriptionType &lt;= 4)).  Note the &lt;, you'll get
>> >> errors if you use a < character.  I assume you validate that
>> >> subscriptionType is an integer on [1,4].  Also, you don't need
> quotes
>> >> around the numbers.  Struts is smart enough to try numbers first
> and
>> >> then if that doesn't work, it resorts to Strings.  Besides, I'm not
>> > sure
>> >> the functionality you want is to compare Strings using
> inequalities...
>> >>
>> >> Hope this helps.
>> >>
>> >> -Adam
>> >>
>> >> Jeremy Jardin wrote:
>> >> > Hi,
>> >> >
>> >> > I'm trying to use struts plugin validator to check a big form..
> and
>> > it
>> >> > works
>> >> > well.. but I've a little pb with validwhen constraint;
>> >> >
>> >> > I've written something like this :
>> >> >
>> >> >            <field property="enterpriseName"
>> >> >                depends="validwhen">
>> >> >                <arg0 key="error.inscription.entreprise.nom" />
>> >> >                <var>
>> >> >                    <var-name>test</var-name>
>> >> >                    <var-value>((subscriptionType=="2")or
>> >> > (subscriptionType=="3")or(subscriptionType=="4"))</var-value>
>> >> >                </var>
>> >> >            </field>
>> >> >
>> >> > I just want to check the field 'enterpriseName' is not empty when
> I
>> >> > submit,
>> >> > but only if my select field 'subscriptionType" is more than 1.
> (2,3
>> > or4)
>> >> >
>> >> > It does not work.
>> >> >
>> >> > why ??
>> >> >
>> >> >
>> >>
>> >>
> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> For additional commands, e-mail: user-help@struts.apache.org
>> >>
>> >>
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>

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


Re: pb using validator with struts1.2.9

Posted by Jeremy Jardin <je...@gmail.com>.
If I have a look at my generatated js source code, I can't see the validwhen
method :

    function validateStartSubscriptionForm(form) {
        if (bCancel) {
            return true;
        } else {
            var formValidationResult;
            formValidationResult = validateRequired(form) &&
validateDate(form) && validateEmail(form);
            return (formValidationResult);
        }
    }


Maybe should I see a validateValidWhen(form) method should'nt I ?



On 7/26/06, Jeremy Jardin <je...@gmail.com> wrote:
>
> I've change my validwhen rule into this :
>
>
>             <field property="enterpriseName" depends="validwhen">
>                 <arg0 key="error.inscription.entreprise.nom" />
>                 <msg name= "validwhen" key= "errors.validwhen"/>
>
>                 <var>
>                     <var-name>test</var-name>
>                     <var-value>
>                     (((subscriptionType !=1)AND(*THIS*!=null)) OR
> (subscriptionType==1))
>                     </var-value>
>                 </var>
>             </field>
>
>
> but it still doesn't work..
>
>
>
> On 7/26/06, Jeremy Jardin <je...@gmail.com> wrote:
> >
> > -Irwan,
> >
> > Thank you myuch for your help, but I don't have any problem regarding
> > those show/hide method !
> >
> > I'm just wondering if the fact of removing some fields in the form could
> > be at the origin of my validation matters ??
> >
> >
> >
> > On 7/26/06, Irwan Nurwandi < irwan.nurwandi@gmail.com> wrote:
> >
> > > Dear Jeremy ..
> > >
> > > According to your code below, it seems that for the first time the jsp
> > > page load you're initialiaze the var variable into string "1". So the
> > > three object you've mention before automatically will not visible.
> > >
> > > try this and hope you can learn more ..
> > >
> > > Modify your jsp code
> > >
> > > <%
> > > String val = "";
> > > if (request.getParameter("subscriptionType") != null) {
> > >        val = request.getParameter ("subscriptionType") ;
> > > }
> > > else {
> > >        val = "1";
> > > }
> > > %>
> > >
> > > then create the javascript function ChangeUrl(x).
> > >
> > > <script language="javascript">
> > > function ChangeUrl(x) {
> > >       location.href = "yourActionToDisplayJsp.do?subscriptionType=" +
> > > x;
> > > }.
> > > </script>
> > >
> > > on your select tag call this function
> > >
> > > <html:select property="subscriptionType" styleId="inscrit"
> > > styleClass="form" onchange="ChangeUrl(this.value)">
> > >
> > > you do not need to modify another section of code ..
> > >
> > > hope this help ..
> > >
> > > Regards
> > >
> > > Irwan
> > >
> > > On 7/26/06, Jeremy Jardin < jeremy.jardin@gmail.com> wrote:
> > > > hum,
> > > >
> > > > I mean my jsp is built dynamically.. so when my select box is set to
> > > "1",
> > > > my jsp is made with 4 fields.
> > > > But if my select box is set to "2", "3" or "4". my JSP page is made
> > > with 3
> > > > new fields.
> > > >
> > > > And I think that "hide" means present but not visible.. and "not
> > > display"
> > > > means not present in the page.
> > > >
> > > > I hope you'll understand, I'm sorry for my poor english.
> > > >
> > > >
> > > > SO, have a look at my jsp, it could be more comprehensive:
> > > >
> > > >                   <html:select property="subscriptionType"
> > > styleId="inscrit"
> > > > styleClass="form" onchange="ChangeUrl(this.form)">
> > > >                       <html:option value="1"><bean:message key="
> > > > inscription.particulier"/></html:option>
> > > >                       <html:option value="2"><bean:message key="
> > > > inscription.membre.entreprise"/></html:option>
> > > >                       <html:option value="3"><bean:message key="
> > > > inscription.professionnel"/></html:option>
> > > >                       <html:option value="4"><bean:message key="
> > > > inscription.elu"/></html:option>
> > > >                   </html:select></td>
> > > >                 </tr>
> > > >
> > > >                 <% String val = new String("1") ; %>
> > > >
> > > >             <logic:notEqual  name="startSubscriptionForm"
> > > > property="subscriptionType" value="<%=val%>">
> > > >
> > > >             <html:text property="enterpriseName" name="S_ENTREP"
> > > > styleId="nomentreprise" styleClass="form" size="20" value=""/>
> > > >             <html:text property="legalRepresentant" name="S_REPRES"
> > > > styleId="representant" styleClass="form" size="20"
> > > >               <html:text property="siren" styleId="siren"
> > > name="S_SIREN"
> > > > styleClass="form2" size="10" maxlength="14" value="" /></td>
> > > >
> > > >             </logic:notEqual>
> > > >
> > > > I just want those 3 fields (enterpriseName, legalRepresentant and
> > > siren) to
> > > > be required if select box != 1.
> > > >
> > > >
> > > > ??
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> >
> >
> > --
> > ~ jebmail ~
> >
>
>
>
> --
> ~ jebmail ~
>



-- 
~ jebmail ~

Re: pb using validator with struts1.2.9

Posted by Jeremy Jardin <je...@gmail.com>.
I've change my validwhen rule into this :

            <field property="enterpriseName" depends="validwhen">
                <arg0 key="error.inscription.entreprise.nom" />
                <msg name= "validwhen" key= "errors.validwhen"/>
                <var>
                    <var-name>test</var-name>
                    <var-value>
                    (((subscriptionType !=1)AND(*THIS*!=null)) OR
(subscriptionType==1))
                    </var-value>
                </var>
            </field>


but it still doesn't work..


On 7/26/06, Jeremy Jardin <je...@gmail.com> wrote:
>
> -Irwan,
>
> Thank you myuch for your help, but I don't have any problem regarding
> those show/hide method !
>
> I'm just wondering if the fact of removing some fields in the form could
> be at the origin of my validation matters ??
>
>
>
> On 7/26/06, Irwan Nurwandi <ir...@gmail.com> wrote:
>
> > Dear Jeremy ..
> >
> > According to your code below, it seems that for the first time the jsp
> > page load you're initialiaze the var variable into string "1". So the
> > three object you've mention before automatically will not visible.
> >
> > try this and hope you can learn more ..
> >
> > Modify your jsp code
> >
> > <%
> > String val = "";
> > if (request.getParameter("subscriptionType") != null) {
> >        val = request.getParameter ("subscriptionType") ;
> > }
> > else {
> >        val = "1";
> > }
> > %>
> >
> > then create the javascript function ChangeUrl(x).
> >
> > <script language="javascript">
> > function ChangeUrl(x) {
> >       location.href = "yourActionToDisplayJsp.do?subscriptionType=" + x;
> > }.
> > </script>
> >
> > on your select tag call this function
> >
> > <html:select property="subscriptionType" styleId="inscrit"
> > styleClass="form" onchange="ChangeUrl(this.value)">
> >
> > you do not need to modify another section of code ..
> >
> > hope this help ..
> >
> > Regards
> >
> > Irwan
> >
> > On 7/26/06, Jeremy Jardin < jeremy.jardin@gmail.com> wrote:
> > > hum,
> > >
> > > I mean my jsp is built dynamically.. so when my select box is set to
> > "1",
> > > my jsp is made with 4 fields.
> > > But if my select box is set to "2", "3" or "4". my JSP page is made
> > with 3
> > > new fields.
> > >
> > > And I think that "hide" means present but not visible.. and "not
> > display"
> > > means not present in the page.
> > >
> > > I hope you'll understand, I'm sorry for my poor english.
> > >
> > >
> > > SO, have a look at my jsp, it could be more comprehensive:
> > >
> > >                   <html:select property="subscriptionType"
> > styleId="inscrit"
> > > styleClass="form" onchange="ChangeUrl(this.form)">
> > >                       <html:option value="1"><bean:message key="
> > > inscription.particulier"/></html:option>
> > >                       <html:option value="2"><bean:message key="
> > > inscription.membre.entreprise"/></html:option>
> > >                       <html:option value="3"><bean:message key="
> > > inscription.professionnel"/></html:option>
> > >                       <html:option value="4"><bean:message key="
> > > inscription.elu"/></html:option>
> > >                   </html:select></td>
> > >                 </tr>
> > >
> > >                 <% String val = new String("1") ; %>
> > >
> > >             <logic:notEqual  name="startSubscriptionForm"
> > > property="subscriptionType" value="<%=val%>">
> > >
> > >             <html:text property="enterpriseName" name="S_ENTREP"
> > > styleId="nomentreprise" styleClass="form" size="20" value=""/>
> > >             <html:text property="legalRepresentant" name="S_REPRES"
> > > styleId="representant" styleClass="form" size="20"
> > >               <html:text property="siren" styleId="siren"
> > name="S_SIREN"
> > > styleClass="form2" size="10" maxlength="14" value="" /></td>
> > >
> > >             </logic:notEqual>
> > >
> > > I just want those 3 fields (enterpriseName, legalRepresentant and
> > siren) to
> > > be required if select box != 1.
> > >
> > >
> > > ??
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> --
> ~ jebmail ~
>



-- 
~ jebmail ~

Re: pb using validator with struts1.2.9

Posted by Jeremy Jardin <je...@gmail.com>.
-Irwan,

Thank you myuch for your help, but I don't have any problem regarding those
show/hide method !

I'm just wondering if the fact of removing some fields in the form could be
at the origin of my validation matters ??



On 7/26/06, Irwan Nurwandi <ir...@gmail.com> wrote:
>
> Dear Jeremy ..
>
> According to your code below, it seems that for the first time the jsp
> page load you're initialiaze the var variable into string "1". So the
> three object you've mention before automatically will not visible.
>
> try this and hope you can learn more ..
>
> Modify your jsp code
>
> <%
> String val = "";
> if (request.getParameter("subscriptionType") != null) {
>        val = request.getParameter("subscriptionType") ;
> }
> else {
>        val = "1";
> }
> %>
>
> then create the javascript function ChangeUrl(x).
>
> <script language="javascript">
> function ChangeUrl(x) {
>       location.href = "yourActionToDisplayJsp.do?subscriptionType=" + x;
> }.
> </script>
>
> on your select tag call this function
>
> <html:select property="subscriptionType" styleId="inscrit"
> styleClass="form" onchange="ChangeUrl(this.value)">
>
> you do not need to modify another section of code ..
>
> hope this help ..
>
> Regards
>
> Irwan
>
> On 7/26/06, Jeremy Jardin <je...@gmail.com> wrote:
> > hum,
> >
> > I mean my jsp is built dynamically.. so when my select box is set to
> "1",
> > my jsp is made with 4 fields.
> > But if my select box is set to "2", "3" or "4". my JSP page is made with
> 3
> > new fields.
> >
> > And I think that "hide" means present but not visible.. and "not
> display"
> > means not present in the page.
> >
> > I hope you'll understand, I'm sorry for my poor english.
> >
> >
> > SO, have a look at my jsp, it could be more comprehensive:
> >
> >                   <html:select property="subscriptionType"
> styleId="inscrit"
> > styleClass="form" onchange="ChangeUrl(this.form)">
> >                       <html:option value="1"><bean:message key="
> > inscription.particulier"/></html:option>
> >                       <html:option value="2"><bean:message key="
> > inscription.membre.entreprise"/></html:option>
> >                       <html:option value="3"><bean:message key="
> > inscription.professionnel"/></html:option>
> >                       <html:option value="4"><bean:message key="
> > inscription.elu"/></html:option>
> >                   </html:select></td>
> >                 </tr>
> >
> >                 <% String val = new String("1") ; %>
> >
> >             <logic:notEqual  name="startSubscriptionForm"
> > property="subscriptionType" value="<%=val%>">
> >
> >             <html:text property="enterpriseName" name="S_ENTREP"
> > styleId="nomentreprise" styleClass="form" size="20" value=""/>
> >             <html:text property="legalRepresentant" name="S_REPRES"
> > styleId="representant" styleClass="form" size="20"
> >               <html:text property="siren" styleId="siren" name="S_SIREN"
> > styleClass="form2" size="10" maxlength="14" value="" /></td>
> >
> >             </logic:notEqual>
> >
> > I just want those 3 fields (enterpriseName, legalRepresentant and siren)
> to
> > be required if select box != 1.
> >
> >
> > ??
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
~ jebmail ~

Re: pb using validator with struts1.2.9

Posted by Irwan Nurwandi <ir...@gmail.com>.
Dear Jeremy ..

According to your code below, it seems that for the first time the jsp
page load you're initialiaze the var variable into string "1". So the
three object you've mention before automatically will not visible.

try this and hope you can learn more ..

Modify your jsp code

<%
String val = "";
if (request.getParameter("subscriptionType") != null) {
       val = request.getParameter("subscriptionType") ;
}
else {
       val = "1";
}
%>

then create the javascript function ChangeUrl(x).

<script language="javascript">
function ChangeUrl(x) {
      location.href = "yourActionToDisplayJsp.do?subscriptionType=" + x;
}.
</script>

on your select tag call this function

 <html:select property="subscriptionType" styleId="inscrit"
 styleClass="form" onchange="ChangeUrl(this.value)">

you do not need to modify another section of code ..

hope this help ..

Regards

Irwan

On 7/26/06, Jeremy Jardin <je...@gmail.com> wrote:
> hum,
>
> I mean my jsp is built dynamically.. so when my select box is set to "1",
> my jsp is made with 4 fields.
> But if my select box is set to "2", "3" or "4". my JSP page is made with 3
> new fields.
>
> And I think that "hide" means present but not visible.. and "not display"
> means not present in the page.
>
> I hope you'll understand, I'm sorry for my poor english.
>
>
> SO, have a look at my jsp, it could be more comprehensive:
>
>                   <html:select property="subscriptionType" styleId="inscrit"
> styleClass="form" onchange="ChangeUrl(this.form)">
>                       <html:option value="1"><bean:message key="
> inscription.particulier"/></html:option>
>                       <html:option value="2"><bean:message key="
> inscription.membre.entreprise"/></html:option>
>                       <html:option value="3"><bean:message key="
> inscription.professionnel"/></html:option>
>                       <html:option value="4"><bean:message key="
> inscription.elu"/></html:option>
>                   </html:select></td>
>                 </tr>
>
>                 <% String val = new String("1") ; %>
>
>             <logic:notEqual  name="startSubscriptionForm"
> property="subscriptionType" value="<%=val%>">
>
>             <html:text property="enterpriseName" name="S_ENTREP"
> styleId="nomentreprise" styleClass="form" size="20" value=""/>
>             <html:text property="legalRepresentant" name="S_REPRES"
> styleId="representant" styleClass="form" size="20"
>               <html:text property="siren" styleId="siren" name="S_SIREN"
> styleClass="form2" size="10" maxlength="14" value="" /></td>
>
>             </logic:notEqual>
>
> I just want those 3 fields (enterpriseName, legalRepresentant and siren) to
> be required if select box != 1.
>
>
> ??

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


Re: pb using validator with struts1.2.9

Posted by Jeremy Jardin <je...@gmail.com>.
hum,

I mean my jsp is built dynamically.. so when my select box is set to "1",
my jsp is made with 4 fields.
But if my select box is set to "2", "3" or "4". my JSP page is made with 3
new fields.

And I think that "hide" means present but not visible.. and "not display"
means not present in the page.

I hope you'll understand, I'm sorry for my poor english.


SO, have a look at my jsp, it could be more comprehensive:

                  <html:select property="subscriptionType" styleId="inscrit"
styleClass="form" onchange="ChangeUrl(this.form)">
                      <html:option value="1"><bean:message key="
inscription.particulier"/></html:option>
                      <html:option value="2"><bean:message key="
inscription.membre.entreprise"/></html:option>
                      <html:option value="3"><bean:message key="
inscription.professionnel"/></html:option>
                      <html:option value="4"><bean:message key="
inscription.elu"/></html:option>
                  </html:select></td>
                </tr>

                <% String val = new String("1") ; %>

            <logic:notEqual  name="startSubscriptionForm"
property="subscriptionType" value="<%=val%>">

            <html:text property="enterpriseName" name="S_ENTREP"
styleId="nomentreprise" styleClass="form" size="20" value=""/>
            <html:text property="legalRepresentant" name="S_REPRES"
styleId="representant" styleClass="form" size="20"
              <html:text property="siren" styleId="siren" name="S_SIREN"
styleClass="form2" size="10" maxlength="14" value="" /></td>

            </logic:notEqual>

I just want those 3 fields (enterpriseName, legalRepresentant and siren) to
be required if select box != 1.


??

On 7/26/06, Irwan Nurwandi <ir...@gmail.com> wrote:
>
> Dear Jeremy ..
>
> what do you mean with "should I "hide" fields rather than "not
> display" fields.. ??",
> "hide" and "not display" are the same things isn't it :-)
>
> if you're expect the validwhen to manage hide and unhide HTML object,
> validwhen couldn't do such a thing.
>
> =====
> Taken from struts doc :
> [Since Struts 1.2.0] A frequent requirement in validation design is
> to validate one field against another (for example, if you have asked
> the user to type in a password twice for confirmation, to make sure
> that the values match.) In addition, there are fields in a form that
> may only be required if other fields have certain values. The
> validwhen  validation rule is designed to handle these cases.
> =====
>
> Otherwise, to manage hide and unhide HTML Object which is generated by
> Struts, you can create your own javascript function to hide/unhide the
> object, and then call the function manually using OnChange property in
> your select tag.
>
> Regards
> Irwan
>
> > I think now it's time to explain you clearly what I'm trying to do.
> >
> > I've got a select tag wich determine if some fieds appear or not.
> > "if select value > 1, some input:text tags appears, and there aren't
> present
> > is select value=1."
> >
> > Maybe should I "hide" fields rather than "not display" fields.. ??
> >
> > thx
> >
> >
> >
> >
> >
> >
> >
> > On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
> > >
> > > Jeremy-
> > >
> > > Ok, sanity-check time.  Make sure your field names are all spelled
> > > correctly.  Also, are any errors being output to the form?  I had
> errors
> > > displaying and it turned out that the validator was doing exactly what
> I
> > > was asking it to do and the problem was that I just didn't understand
> > > the "validwhen" validation rule.
> > >
> > > I've found that overriding toString() on my form bean and having it
> dump
> > > the contents of all the fields is an excellent way to see with what
> > > values the bean is being populated.  You can then call
> > > System.out.println(this) (or use a logger) in your bean's
> validate(...)
> > > method to see what values your bean has.  Make sure the
> subscriptionType
> > > is set to the value you expect.
> > >
> > > Also, your rule basically reads now as "the field enterpriseName is
> > > valid when the subscription type is greater than or equal to 1."   So,
> > > e.g., if your subscription type is a drop down list that only contains
> > > the values 1,2,3,4, the enterpriseName field will always be valid.
> > >
> > > Give that a whirl and let us know.
> > >
> > > cheers,
> > >
> > > -Adam
> > >
> > > Jeremy Jardin wrote:
> > > > -Adam,
> > > >
> > > > I've just changed my conf like that :
> > > >
> > > >            <field property="enterpriseName"
> > > >                depends="validwhen">
> > > >                <arg0 key="error.inscription.entreprise.nom" />
> > > >                <var>
> > > >                    <var-name>test</var-name>
> > > >                    <var-value>(subscriptionType>=1)</var-value>
> > > >                </var>
> > > >            </field>
> > > >
> > > > but, it still does not work..
> > > >
> > > > On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
> > > >>
> > > >> Jeremy-
> > > >>
> > > >> At first glance, I think you need to modify your parenthesis.  Per
> the
> > > >> Validation docs at
> > > >> http://struts.apache.org/1.2.9/userGuide/dev_validator.html, only
> two
> > > >> items may be joined with "and" or "or."  I don't know if that means
> > > > you
> > > >> can only have a max of two items or a max of two items per
> parends...
> > > >>
> > > >> Secondly, I had a bunch of problems with "validwhen" and finally
> > > >> resorted to implementing my own solution in my ValidatorForm's
> > > >> validate(...) method because it appears that 'validwhen' is rather
> > > >> basic.  It basically says "field A is valid when..."  In my
> > > > experience,
> > > >> "validwhen" doesn't chain well with other validation rules.
> > > >>
> > > >> Alternatively, you could rewrite your rules to say:
> > > > ((subscriptionType
> > > >> >= 2) and (subscriptionType &lt;= 4)).  Note the &lt;, you'll get
> > > >> errors if you use a < character.  I assume you validate that
> > > >> subscriptionType is an integer on [1,4].  Also, you don't need
> quotes
> > > >> around the numbers.  Struts is smart enough to try numbers first
> and
> > > >> then if that doesn't work, it resorts to Strings.  Besides, I'm not
> > > > sure
> > > >> the functionality you want is to compare Strings using
> inequalities...
> > > >>
> > > >> Hope this helps.
> > > >>
> > > >> -Adam
> > > >>
> > > >> Jeremy Jardin wrote:
> > > >> > Hi,
> > > >> >
> > > >> > I'm trying to use struts plugin validator to check a big form..
> and
> > > > it
> > > >> > works
> > > >> > well.. but I've a little pb with validwhen constraint;
> > > >> >
> > > >> > I've written something like this :
> > > >> >
> > > >> >            <field property="enterpriseName"
> > > >> >                depends="validwhen">
> > > >> >                <arg0 key="error.inscription.entreprise.nom" />
> > > >> >                <var>
> > > >> >                    <var-name>test</var-name>
> > > >> >                    <var-value>((subscriptionType=="2")or
> > > >> > (subscriptionType=="3")or(subscriptionType=="4"))</var-value>
> > > >> >                </var>
> > > >> >            </field>
> > > >> >
> > > >> > I just want to check the field 'enterpriseName' is not empty when
> I
> > > >> > submit,
> > > >> > but only if my select field 'subscriptionType" is more than 1.
> (2,3
> > > > or4)
> > > >> >
> > > >> > It does not work.
> > > >> >
> > > >> > why ??
> > > >> >
> > > >> >
> > > >>
> > > >>
> ---------------------------------------------------------------------
> > > >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > >> For additional commands, e-mail: user-help@struts.apache.org
> > > >>
> > > >>
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> >
> >
> > --
> > ~ jebmail ~
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
~ jebmail ~

Re: pb using validator with struts1.2.9

Posted by Irwan Nurwandi <ir...@gmail.com>.
Dear Jeremy ..

what do you mean with "should I "hide" fields rather than "not
display" fields.. ??",
 "hide" and "not display" are the same things isn't it :-)

if you're expect the validwhen to manage hide and unhide HTML object,
validwhen couldn't do such a thing.

=====
Taken from struts doc :
 [Since Struts 1.2.0] A frequent requirement in validation design is
to validate one field against another (for example, if you have asked
the user to type in a password twice for confirmation, to make sure
that the values match.) In addition, there are fields in a form that
may only be required if other fields have certain values. The
validwhen  validation rule is designed to handle these cases.
=====

Otherwise, to manage hide and unhide HTML Object which is generated by
Struts, you can create your own javascript function to hide/unhide the
object, and then call the function manually using OnChange property in
your select tag.

Regards
Irwan

> I think now it's time to explain you clearly what I'm trying to do.
>
> I've got a select tag wich determine if some fieds appear or not.
> "if select value > 1, some input:text tags appears, and there aren't present
> is select value=1."
>
> Maybe should I "hide" fields rather than "not display" fields.. ??
>
> thx
>
>
>
>
>
>
>
> On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
> >
> > Jeremy-
> >
> > Ok, sanity-check time.  Make sure your field names are all spelled
> > correctly.  Also, are any errors being output to the form?  I had errors
> > displaying and it turned out that the validator was doing exactly what I
> > was asking it to do and the problem was that I just didn't understand
> > the "validwhen" validation rule.
> >
> > I've found that overriding toString() on my form bean and having it dump
> > the contents of all the fields is an excellent way to see with what
> > values the bean is being populated.  You can then call
> > System.out.println(this) (or use a logger) in your bean's validate(...)
> > method to see what values your bean has.  Make sure the subscriptionType
> > is set to the value you expect.
> >
> > Also, your rule basically reads now as "the field enterpriseName is
> > valid when the subscription type is greater than or equal to 1."   So,
> > e.g., if your subscription type is a drop down list that only contains
> > the values 1,2,3,4, the enterpriseName field will always be valid.
> >
> > Give that a whirl and let us know.
> >
> > cheers,
> >
> > -Adam
> >
> > Jeremy Jardin wrote:
> > > -Adam,
> > >
> > > I've just changed my conf like that :
> > >
> > >            <field property="enterpriseName"
> > >                depends="validwhen">
> > >                <arg0 key="error.inscription.entreprise.nom" />
> > >                <var>
> > >                    <var-name>test</var-name>
> > >                    <var-value>(subscriptionType>=1)</var-value>
> > >                </var>
> > >            </field>
> > >
> > > but, it still does not work..
> > >
> > > On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
> > >>
> > >> Jeremy-
> > >>
> > >> At first glance, I think you need to modify your parenthesis.  Per the
> > >> Validation docs at
> > >> http://struts.apache.org/1.2.9/userGuide/dev_validator.html, only two
> > >> items may be joined with "and" or "or."  I don't know if that means
> > > you
> > >> can only have a max of two items or a max of two items per parends...
> > >>
> > >> Secondly, I had a bunch of problems with "validwhen" and finally
> > >> resorted to implementing my own solution in my ValidatorForm's
> > >> validate(...) method because it appears that 'validwhen' is rather
> > >> basic.  It basically says "field A is valid when..."  In my
> > > experience,
> > >> "validwhen" doesn't chain well with other validation rules.
> > >>
> > >> Alternatively, you could rewrite your rules to say:
> > > ((subscriptionType
> > >> >= 2) and (subscriptionType &lt;= 4)).  Note the &lt;, you'll get
> > >> errors if you use a < character.  I assume you validate that
> > >> subscriptionType is an integer on [1,4].  Also, you don't need quotes
> > >> around the numbers.  Struts is smart enough to try numbers first and
> > >> then if that doesn't work, it resorts to Strings.  Besides, I'm not
> > > sure
> > >> the functionality you want is to compare Strings using inequalities...
> > >>
> > >> Hope this helps.
> > >>
> > >> -Adam
> > >>
> > >> Jeremy Jardin wrote:
> > >> > Hi,
> > >> >
> > >> > I'm trying to use struts plugin validator to check a big form.. and
> > > it
> > >> > works
> > >> > well.. but I've a little pb with validwhen constraint;
> > >> >
> > >> > I've written something like this :
> > >> >
> > >> >            <field property="enterpriseName"
> > >> >                depends="validwhen">
> > >> >                <arg0 key="error.inscription.entreprise.nom" />
> > >> >                <var>
> > >> >                    <var-name>test</var-name>
> > >> >                    <var-value>((subscriptionType=="2")or
> > >> > (subscriptionType=="3")or(subscriptionType=="4"))</var-value>
> > >> >                </var>
> > >> >            </field>
> > >> >
> > >> > I just want to check the field 'enterpriseName' is not empty when I
> > >> > submit,
> > >> > but only if my select field 'subscriptionType" is more than 1. (2,3
> > > or4)
> > >> >
> > >> > It does not work.
> > >> >
> > >> > why ??
> > >> >
> > >> >
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > >> For additional commands, e-mail: user-help@struts.apache.org
> > >>
> > >>
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> --
> ~ jebmail ~
>
>

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


Re: pb using validator with struts1.2.9

Posted by Jeremy Jardin <je...@gmail.com>.
-Adam,

first, thanks for all those explications. but I've still a problem with my
validator using 'validwhen'.

I've seen first, that I don't have any "errors.validwhen = mymessage" line
in my messageResource file ?
I guess I need to add it and I did it.

Otherwise, I've now clearly understood (I think so...) how It work.. but
have a look .. I've tried that :

            <field property="enterpriseName" depends="validwhen">
                <arg0 key="error.inscription.entreprise.nom" />
                <var>
                    <var-name>test</var-name>
                    <var-value>((*this* ==  "hello"))</var-value>
                </var>
            </field>

I think it sould warn me each time my field is not "hello".. but it does
not.

I think now it's time to explain you clearly what I'm trying to do.

I've got a select tag wich determine if some fieds appear or not.
"if select value > 1, some input:text tags appears, and there aren't present
is select value=1."

Maybe should I "hide" fields rather than "not display" fields.. ??

thx







On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
>
> Jeremy-
>
> Ok, sanity-check time.  Make sure your field names are all spelled
> correctly.  Also, are any errors being output to the form?  I had errors
> displaying and it turned out that the validator was doing exactly what I
> was asking it to do and the problem was that I just didn't understand
> the "validwhen" validation rule.
>
> I've found that overriding toString() on my form bean and having it dump
> the contents of all the fields is an excellent way to see with what
> values the bean is being populated.  You can then call
> System.out.println(this) (or use a logger) in your bean's validate(...)
> method to see what values your bean has.  Make sure the subscriptionType
> is set to the value you expect.
>
> Also, your rule basically reads now as "the field enterpriseName is
> valid when the subscription type is greater than or equal to 1."   So,
> e.g., if your subscription type is a drop down list that only contains
> the values 1,2,3,4, the enterpriseName field will always be valid.
>
> Give that a whirl and let us know.
>
> cheers,
>
> -Adam
>
> Jeremy Jardin wrote:
> > -Adam,
> >
> > I've just changed my conf like that :
> >
> >            <field property="enterpriseName"
> >                depends="validwhen">
> >                <arg0 key="error.inscription.entreprise.nom" />
> >                <var>
> >                    <var-name>test</var-name>
> >                    <var-value>(subscriptionType>=1)</var-value>
> >                </var>
> >            </field>
> >
> > but, it still does not work..
> >
> > On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
> >>
> >> Jeremy-
> >>
> >> At first glance, I think you need to modify your parenthesis.  Per the
> >> Validation docs at
> >> http://struts.apache.org/1.2.9/userGuide/dev_validator.html, only two
> >> items may be joined with "and" or "or."  I don't know if that means
> > you
> >> can only have a max of two items or a max of two items per parends...
> >>
> >> Secondly, I had a bunch of problems with "validwhen" and finally
> >> resorted to implementing my own solution in my ValidatorForm's
> >> validate(...) method because it appears that 'validwhen' is rather
> >> basic.  It basically says "field A is valid when..."  In my
> > experience,
> >> "validwhen" doesn't chain well with other validation rules.
> >>
> >> Alternatively, you could rewrite your rules to say:
> > ((subscriptionType
> >> >= 2) and (subscriptionType &lt;= 4)).  Note the &lt;, you'll get
> >> errors if you use a < character.  I assume you validate that
> >> subscriptionType is an integer on [1,4].  Also, you don't need quotes
> >> around the numbers.  Struts is smart enough to try numbers first and
> >> then if that doesn't work, it resorts to Strings.  Besides, I'm not
> > sure
> >> the functionality you want is to compare Strings using inequalities...
> >>
> >> Hope this helps.
> >>
> >> -Adam
> >>
> >> Jeremy Jardin wrote:
> >> > Hi,
> >> >
> >> > I'm trying to use struts plugin validator to check a big form.. and
> > it
> >> > works
> >> > well.. but I've a little pb with validwhen constraint;
> >> >
> >> > I've written something like this :
> >> >
> >> >            <field property="enterpriseName"
> >> >                depends="validwhen">
> >> >                <arg0 key="error.inscription.entreprise.nom" />
> >> >                <var>
> >> >                    <var-name>test</var-name>
> >> >                    <var-value>((subscriptionType=="2")or
> >> > (subscriptionType=="3")or(subscriptionType=="4"))</var-value>
> >> >                </var>
> >> >            </field>
> >> >
> >> > I just want to check the field 'enterpriseName' is not empty when I
> >> > submit,
> >> > but only if my select field 'subscriptionType" is more than 1. (2,3
> > or4)
> >> >
> >> > It does not work.
> >> >
> >> > why ??
> >> >
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
~ jebmail ~

Re: pb using validator with struts1.2.9

Posted by Adam Gordon <ad...@readytalk.com>.
Jeremy-

Ok, sanity-check time.  Make sure your field names are all spelled 
correctly.  Also, are any errors being output to the form?  I had errors 
displaying and it turned out that the validator was doing exactly what I 
was asking it to do and the problem was that I just didn't understand 
the "validwhen" validation rule.

I've found that overriding toString() on my form bean and having it dump 
the contents of all the fields is an excellent way to see with what 
values the bean is being populated.  You can then call 
System.out.println(this) (or use a logger) in your bean's validate(...) 
method to see what values your bean has.  Make sure the subscriptionType 
is set to the value you expect.

Also, your rule basically reads now as "the field enterpriseName is 
valid when the subscription type is greater than or equal to 1."   So, 
e.g., if your subscription type is a drop down list that only contains 
the values 1,2,3,4, the enterpriseName field will always be valid.

Give that a whirl and let us know.

cheers,

-Adam

Jeremy Jardin wrote:
> -Adam,
>
> I've just changed my conf like that :
>
>            <field property="enterpriseName"
>                depends="validwhen">
>                <arg0 key="error.inscription.entreprise.nom" />
>                <var>
>                    <var-name>test</var-name>
>                    <var-value>(subscriptionType>=1)</var-value>
>                </var>
>            </field>
>
> but, it still does not work..
>
> On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
>>
>> Jeremy-
>>
>> At first glance, I think you need to modify your parenthesis.  Per the
>> Validation docs at
>> http://struts.apache.org/1.2.9/userGuide/dev_validator.html, only two
>> items may be joined with "and" or "or."  I don't know if that means
> you
>> can only have a max of two items or a max of two items per parends...
>>
>> Secondly, I had a bunch of problems with "validwhen" and finally
>> resorted to implementing my own solution in my ValidatorForm's
>> validate(...) method because it appears that 'validwhen' is rather
>> basic.  It basically says "field A is valid when..."  In my
> experience,
>> "validwhen" doesn't chain well with other validation rules.
>>
>> Alternatively, you could rewrite your rules to say:
> ((subscriptionType
>> >= 2) and (subscriptionType &lt;= 4)).  Note the &lt;, you'll get
>> errors if you use a < character.  I assume you validate that
>> subscriptionType is an integer on [1,4].  Also, you don't need quotes
>> around the numbers.  Struts is smart enough to try numbers first and
>> then if that doesn't work, it resorts to Strings.  Besides, I'm not
> sure
>> the functionality you want is to compare Strings using inequalities...
>>
>> Hope this helps.
>>
>> -Adam
>>
>> Jeremy Jardin wrote:
>> > Hi,
>> >
>> > I'm trying to use struts plugin validator to check a big form.. and
> it
>> > works
>> > well.. but I've a little pb with validwhen constraint;
>> >
>> > I've written something like this :
>> >
>> >            <field property="enterpriseName"
>> >                depends="validwhen">
>> >                <arg0 key="error.inscription.entreprise.nom" />
>> >                <var>
>> >                    <var-name>test</var-name>
>> >                    <var-value>((subscriptionType=="2")or
>> > (subscriptionType=="3")or(subscriptionType=="4"))</var-value>
>> >                </var>
>> >            </field>
>> >
>> > I just want to check the field 'enterpriseName' is not empty when I
>> > submit,
>> > but only if my select field 'subscriptionType" is more than 1. (2,3
> or4)
>> >
>> > It does not work.
>> >
>> > why ??
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>

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


Re: pb using validator with struts1.2.9

Posted by Jeremy Jardin <je...@gmail.com>.
-Adam,

I've just changed my conf like that :

            <field property="enterpriseName"
                depends="validwhen">
                <arg0 key="error.inscription.entreprise.nom" />
                <var>
                    <var-name>test</var-name>
                    <var-value>(subscriptionType>=1)</var-value>
                </var>
            </field>

but, it still does not work..

On 7/25/06, Adam Gordon <ad...@readytalk.com> wrote:
>
> Jeremy-
>
> At first glance, I think you need to modify your parenthesis.  Per the
> Validation docs at
> http://struts.apache.org/1.2.9/userGuide/dev_validator.html, only two
> items may be joined with "and" or "or."  I don't know if that means you
> can only have a max of two items or a max of two items per parends...
>
> Secondly, I had a bunch of problems with "validwhen" and finally
> resorted to implementing my own solution in my ValidatorForm's
> validate(...) method because it appears that 'validwhen' is rather
> basic.  It basically says "field A is valid when..."  In my experience,
> "validwhen" doesn't chain well with other validation rules.
>
> Alternatively, you could rewrite your rules to say:  ((subscriptionType
> >= 2) and (subscriptionType &lt;= 4)).  Note the &lt;, you'll get
> errors if you use a < character.  I assume you validate that
> subscriptionType is an integer on [1,4].  Also, you don't need quotes
> around the numbers.  Struts is smart enough to try numbers first and
> then if that doesn't work, it resorts to Strings.  Besides, I'm not sure
> the functionality you want is to compare Strings using inequalities...
>
> Hope this helps.
>
> -Adam
>
> Jeremy Jardin wrote:
> > Hi,
> >
> > I'm trying to use struts plugin validator to check a big form.. and it
> > works
> > well.. but I've a little pb with validwhen constraint;
> >
> > I've written something like this :
> >
> >            <field property="enterpriseName"
> >                depends="validwhen">
> >                <arg0 key="error.inscription.entreprise.nom" />
> >                <var>
> >                    <var-name>test</var-name>
> >                    <var-value>((subscriptionType=="2")or
> > (subscriptionType=="3")or(subscriptionType=="4"))</var-value>
> >                </var>
> >            </field>
> >
> > I just want to check the field 'enterpriseName' is not empty when I
> > submit,
> > but only if my select field 'subscriptionType" is more than 1. (2,3 or4)
> >
> > It does not work.
> >
> > why ??
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
~ jebmail ~

Re: pb using validator with struts1.2.9

Posted by Adam Gordon <ad...@readytalk.com>.
Jeremy-

At first glance, I think you need to modify your parenthesis.  Per the 
Validation docs at 
http://struts.apache.org/1.2.9/userGuide/dev_validator.html, only two 
items may be joined with "and" or "or."  I don't know if that means you 
can only have a max of two items or a max of two items per parends...

Secondly, I had a bunch of problems with "validwhen" and finally 
resorted to implementing my own solution in my ValidatorForm's 
validate(...) method because it appears that 'validwhen' is rather 
basic.  It basically says "field A is valid when..."  In my experience, 
"validwhen" doesn't chain well with other validation rules.

Alternatively, you could rewrite your rules to say:  ((subscriptionType 
 >= 2) and (subscriptionType &lt;= 4)).  Note the &lt;, you'll get 
errors if you use a < character.  I assume you validate that 
subscriptionType is an integer on [1,4].  Also, you don't need quotes 
around the numbers.  Struts is smart enough to try numbers first and 
then if that doesn't work, it resorts to Strings.  Besides, I'm not sure 
the functionality you want is to compare Strings using inequalities...

Hope this helps.

-Adam

Jeremy Jardin wrote:
> Hi,
>
> I'm trying to use struts plugin validator to check a big form.. and it
> works
> well.. but I've a little pb with validwhen constraint;
>
> I've written something like this :
>
>            <field property="enterpriseName"
>                depends="validwhen">
>                <arg0 key="error.inscription.entreprise.nom" />
>                <var>
>                    <var-name>test</var-name>
>                    <var-value>((subscriptionType=="2")or
> (subscriptionType=="3")or(subscriptionType=="4"))</var-value>
>                </var>
>            </field>
>
> I just want to check the field 'enterpriseName' is not empty when I
> submit,
> but only if my select field 'subscriptionType" is more than 1. (2,3 or4)
>
> It does not work.
>
> why ??
>
>

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