You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Laufer, Michael" <mi...@entory.com> on 2000/11/20 09:10:30 UTC

checkbox-problems ?

Hi,

I have a problem with JSP and using Struts-checkboxes:

my code-fragement:

<struts:form action="editRules.do" name="editRulesForm"
type="org.apache.struts.example.EditRulesForm">
<div align="center">
<table width="100%" border=0 >
<tr bgcolor="white">
<th class="header" width="6%"><struts:message
key="entory.ruleEditor.active.header"/></th>
<th class="header" width="21%"><struts:message
key="entory.ruleEditor.ruleName.header"/></th>
<th class="header"  width="21%"><struts:message
key="entory.ruleEditor.attribute.header"/></th>
<th class="header"  width="12%"><struts:message
key="entory.ruleEditor.operator.header"/></th>
<th class="header"  width="21%"><struts:message
key="entory.ruleEditor.comparison.header"/></th>
<th class="header"  width="21%"><struts:message
key="entory.ruleEditor.mapping.header"/></th></tr>
<tr>

<!--I guess here is my problem -->
<td align="center"><struts:checkbox property="isActive"></td>

<td align="center"><struts:text property="ruleName" size="20"
maxlength="25"/></td>	
<td align="center"><struts:select property="attribute">
						<struts:options
property="values"/> 	
					</struts:select>
</td>
<td align="center"><struts:select property="operator">
						<struts:options
property="operatorValues"/> 	
					</struts:select>
</td>
<td align="center"><struts:text property="comparison" size="20"
maxlength="25"/></td>
<td align="center"><struts:select property="mapping">
						<struts:options
property="files"/> 	
					</struts:select></td>
</tr>
</table>
<table>
........
my problem seems to appear with the <struts:checkbox>-tag
whenever I redirect my request to the JSP again, the checkbox is set, it
doesn't matter, if it was checked before or not.
Is there anything I'm missing ??

Any help would be appreciated.

Thanks in advance,

Mike


Re: checkbox-problems ?

Posted by Pierre Métras <ge...@sympatico.ca>.
checkbox-problems ?Hi Michael,

That's a normal behavior. When you first check your check box, your browser sends the value to your Struts application, and it modify the corresponding property in your ActionForm. Next time, when you uncheck the checkbox, no value is transmitted by the browser (empty values in HTML forms are not transmitted), and your ActionForm property keeps set (if you haven't removed it, but generally you don't if you want to display the other properties...).

In Struts v1.0, there's a reset method that is called just before initializing the form. From that method, you can decide to reset all the checkboxes to their value from a database, for instance.
If you're using v0.5, search in the mailing list for different solutions (but incompatible with v1.0).

Pierre Métras

  ----- Original Message ----- 
  From: Laufer, Michael 
  To: 'Struts' 
  Sent: Monday, November 20, 2000 3:10 AM
  Subject: checkbox-problems ?


  Hi, 

  I have a problem with JSP and using Struts-checkboxes: 

  my code-fragement: 

  <struts:form action="editRules.do" name="editRulesForm" type="org.apache.struts.example.EditRulesForm"> 
  <div align="center"> 
  <table width="100%" border=0 > 
  <tr bgcolor="white"> 
  <th class="header" width="6%"><struts:message key="entory.ruleEditor.active.header"/></th> 
  <th class="header" width="21%"><struts:message key="entory.ruleEditor.ruleName.header"/></th> 
  <th class="header"  width="21%"><struts:message key="entory.ruleEditor.attribute.header"/></th> 
  <th class="header"  width="12%"><struts:message key="entory.ruleEditor.operator.header"/></th> 
  <th class="header"  width="21%"><struts:message key="entory.ruleEditor.comparison.header"/></th> 
  <th class="header"  width="21%"><struts:message key="entory.ruleEditor.mapping.header"/></th></tr> 
  <tr> 

  <!--I guess here is my problem --> 
  <td align="center"><struts:checkbox property="isActive"></td> 

  <td align="center"><struts:text property="ruleName" size="20" maxlength="25"/></td>     
  <td align="center"><struts:select property="attribute"> 
                                                  <struts:options property="values"/>     
                                          </struts:select> 
  </td> 
  <td align="center"><struts:select property="operator"> 
                                                  <struts:options property="operatorValues"/>     
                                          </struts:select> 
  </td> 
  <td align="center"><struts:text property="comparison" size="20" maxlength="25"/></td> 
  <td align="center"><struts:select property="mapping"> 
                                                  <struts:options property="files"/>      
                                          </struts:select></td> 
  </tr> 
  </table> 
  <table> 
  ........ 
  my problem seems to appear with the <struts:checkbox>-tag 
  whenever I redirect my request to the JSP again, the checkbox is set, it doesn't matter, if it was checked before or not.

  Is there anything I'm missing ?? 

  Any help would be appreciated. 

  Thanks in advance, 

  Mike