You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mississippi John Hurt <jo...@gmail.com> on 2006/09/20 06:30:19 UTC

Validator and At Least 1 Checkbox Checked

Can struts validator validate that at least one checkbox in a set is
checked?  I guess somehow it has to validate that a String[] array property
of the form has size of 1 or more, but I dont know how.

reset index properties

Posted by "Strachan, Paul" <Pa...@det.nsw.edu.au>.
Hi everyone,

I have a multi-row edit page with linked dropdowns which I render using 
logic:interate (using indexed properties)

The struts html tags documentation mentions about needing the reset trick 
for the html:select tag.

I'm a bit stuck how this java code should be applied in the reset method

set("qualifications[].institutionCode", "");  // ??? trying validator syntax doesnt work

(I also have some validWhen indexed validations which should fail, but sometimes pass 
- this seems typical behaviour for those properties which should be reset)

What is good practice in this situtation? Should I be getting the ArrayList 
off the form and iterating through the objects and just reset the properties 
which map to a select tag?

e.g.
      

  ArrayList qualifications = (ArrayList) get("qualifications");
        if (qualifications != null && !qualifications.isEmpty()) {
            Iterator iter = qualifications.iterator();
            while (iter.hasNext()) {
                AcademicQualification qual = (AcademicQualification) iter.next();
                qual.setInstitutionCode("");
                qual.setQualificationCode("");
            }
        }

 

Dyna validator form config:

    <form-bean name="AcademicQualificationForm" type="forms.AcademicQualificationForm">
      <form-property name="qualifications" type="java.util.ArrayList"/>
      <form-property name="otherQualifications" type="java.util.ArrayList"/>
</form-bean>

JSP code:

<logic:iterate id="qualifications" indexId="idx" name="AcademicQualificationForm" property="qualifications">

        <html-el:select indexed="true" name="qualifications" property="institutionCode" styleId="institutionCode${idx}" errorStyleClass="formFieldError">
          <html-el:option value=""><fmt:message key="common.select" /></html-el:option>
          <html-el:options collection="uniList" property="uniCode" labelProperty="description"/>
        </html-el:select>
...

</logic:iterate>


Thanks for any advice


**********************************************************************
This message is intended for the addressee named and may contain
privileged information or confidential information or both. If you
are not the intended recipient please delete it and notify the sender.
**********************************************************************

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


Re: Validator and At Least 1 Checkbox Checked

Posted by Paul Benedict <pb...@apache.org>.
Laurie, absolutely, use the required validation. I do that for my 
applications. Since he was specifically talking about length of an 
array, there is no such validation; but as long as a valid is present, 
it was submitted.

Laurie Harper wrote:
> Can't you just use the 'required' validation rule? Or possibly a 
> validwhen with something like *this* != null and *tihs*.length >= 1? 
> Admittedly I haven't tried either, though.
> 
> L.
> 
> Paul Benedict wrote:
>> I've always wanted this feature myself. However, no such validation 
>> exists.. but if you write it, you could share it back to the Struts 
>> community.
>>
>> So you'll have to add this validation yourself by override the 
>> validate() method of your form, checking the property's length; if it 
>> is not null then add your message to the existing error messages.
>>
>> Paul
>>
>> Mississippi John Hurt wrote:
>>> Can struts validator validate that at least one checkbox in a set is
>>> checked?  I guess somehow it has to validate that a String[] array 
>>> property
>>> of the form has size of 1 or more, but I dont know how.
>>>
> 
> 
> ---------------------------------------------------------------------
> 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: Validator and At Least 1 Checkbox Checked

Posted by Laurie Harper <la...@holoweb.net>.
Can't you just use the 'required' validation rule? Or possibly a 
validwhen with something like *this* != null and *tihs*.length >= 1? 
Admittedly I haven't tried either, though.

L.

Paul Benedict wrote:
> I've always wanted this feature myself. However, no such validation 
> exists.. but if you write it, you could share it back to the Struts 
> community.
> 
> So you'll have to add this validation yourself by override the 
> validate() method of your form, checking the property's length; if it is 
> not null then add your message to the existing error messages.
> 
> Paul
> 
> Mississippi John Hurt wrote:
>> Can struts validator validate that at least one checkbox in a set is
>> checked?  I guess somehow it has to validate that a String[] array 
>> property
>> of the form has size of 1 or more, but I dont know how.
>>


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


Re: Validator and At Least 1 Checkbox Checked

Posted by Paul Benedict <pb...@apache.org>.
I've always wanted this feature myself. However, no such validation 
exists.. but if you write it, you could share it back to the Struts 
community.

So you'll have to add this validation yourself by override the 
validate() method of your form, checking the property's length; if it is 
not null then add your message to the existing error messages.

Paul

Mississippi John Hurt wrote:
> Can struts validator validate that at least one checkbox in a set is
> checked?  I guess somehow it has to validate that a String[] array property
> of the form has size of 1 or more, but I dont know how.
> 

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