I have a JSP page where I have two buttons check all (to check all
checkboxes) and uncheck all.
        I know that these features can be implemented with simple JavaScript
but it is not easy to associate
            the Javascript with Struts components like DynaValidatorForm.

        My JSP page is the following:

        <logic:iterate name="MyDynaValidatorForm" id="employees"
property="employees"                                    type="com.Employee"
offset="offset" length="length">
                <tr>
                   <td bgcolor="#EBEBEB" width="10%">
                        <input type="checkbox" name="selected"> 
                    </td>
                </tr>
        </logic:iterate>

        <table width="100%" border="0" cellpadding="0" cellspacing="0"
bgcolor="#ffffff">
          <tr>
            <td align="right" valign="top" width="10%"> 
              <html:button property="userAction"
onclick="checkAll(this.MyDynaValidatorForm.selected)" >
                <bean:message key="button.select.all"/></html:button>&nbsp
              <html:button property="userAction"
onclick="uncheckAll(this.MyDynaValidatorForm.selected)" >
                <bean:message key="button.unselect.all"/></html:button> 
            </td>
          <tr>
        </table>

        <script language="JavaScript">
        function checkAll(field)
        {
                for (i = 0; i < field.length; i++)
                field[i].checked = true ;
        }

        function uncheckAll(field)
        {
                for (i = 0; i < field.length; i++)
                field[i].checked = false ;
        }       
        </script>

        In the Struts-config.xml file I defined the following form:
        <form-bean name="MyDynaValidatorForm" dynamic="true"
type="org.apache.struts.validator.DynaValidatorForm">
                <form-property name="userAction" type="java.lang.String" />
                <form-property name="selected" type="java.lang.Boolean[]" />
        </form-beans>

        I don't understand the aim of the attribute property in the
<html:button> tag.
        This implementation doesn't work if someone has already done a
similar think,
        thanks a lot for your help.

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

As of February 12th, 2003 Thomson unifies its email addresses on a worldwide
basis. 
Please note my new email address: [EMAIL PROTECTED] 

http://www.thomson.net/ 

Reply via email to