You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Kennedy <jk...@davincitechnology.com> on 2004/03/30 22:06:05 UTC

Problem with html:multibox not clearing

 I am using an html:multibox that is pretty much working fine except when I
uncheck all choices. I am also using the logic:iterate tag to generate many
checkboxes.  If I have a single box checked I can't seem to uncheck it if
it's the last one.  If I have several checked, I can uncheck them one at a
time and that works.  At least until I get down to just one checked.  Very
odd.  The problem seems to be that I can't get Struts to realize that there
are no checkboxes checked after I submit the form.

I am using struts 1.1, with DynaValidatorForm's.  Here's some of my code:

...
<form-property name="amenity" 		type="java.lang.String[]" />


...
	<td colspan="4">
	<logic-el:iterate id="item" name="amenities" indexId="i">
		<html-el:multibox  property="amenity">
			<bean:write name="item" property="code"/>
		</html-el:multibox>
			<bean:write name="item"
property="description"/>&nbsp;&nbsp;
	</logic-el:iterate>
	</td>

Don't think the above is the issue.  It's something deeper I think.

Any help is appreciated.

Jim Kennedy
IT Consultant



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


RE: Problem with html:multibox not clearing

Posted by Robert Taylor <rt...@mulework.com>.
Sorry, I missed the part that said your form was in the
session. 

And I also forgot that I do subclass my DynaValidatorActionForm and 
add the following code to the reset().

 public void reset(ActionMapping mapping, HttpServletRequest request) {

        this.initialize(mapping);       
 }

It works for me. Good luck with your solution.


robert


> -----Original Message-----
> From: Jim Kennedy [mailto:jkennedy@davincitechnology.com]
> Sent: Tuesday, March 30, 2004 5:02 PM
> To: 'Struts Users Mailing List'
> Subject: RE: Problem with html:multibox not clearing
> 
> 
> Just an FYI, this did not work.  I don't believe it's a reset() issue.  From
> other threads, it's the way an http request is sent when no checkboxes are
> selected. Since nothing gets sent, nothing gets changed.  I will write some
> JavaScript to manually check to see if anything has been checked.  If no
> boxes are checked, I will artificially create a form element that has the
> same name as the checkboxes.
> 
> That's my solution.
> 
> L8r and thanks
> 
> 
> -----Original Message-----
> From: Robert Taylor [mailto:rtaylor@mulework.com] 
> Sent: Tuesday, March 30, 2004 4:00 PM
> To: Struts Users Mailing List
> Subject: RE: Problem with html:multibox not clearing
> 
> Jim, you can try this in your dynavalidatorform declaration:
> 
> <form-property name="amenity" 		
>                type="java.lang.String[]"  
>                initial="{}"/>
> 
> When you invoke an action, Struts will automatically reset your form.
> So when you hit submit, Struts will invoke form.reset() which will reset all
> your form properties to their initial values.
> 
> If you declare your initial value as an empty array (as above), then if
> nothing is checked, the array will be empty. If something is checked, it
> will be populated by the values in the request.
> 
> Give it a try. 
> 
> robert
> 
> 
> 
> > -----Original Message-----
> > From: Jim Kennedy [mailto:jkennedy@davincitechnology.com]
> > Sent: Tuesday, March 30, 2004 3:42 PM
> > To: 'Struts Users Mailing List'
> > Subject: RE: Problem with html:multibox not clearing
> > 
> > 
> > That's not what I had in mind.  Thanks for the suggestion though.  I 
> > found a thread that suggests that you must subclass dynavalidatorform 
> > and override the reset() method.  Not really sure how that will help.
> > 
> > My form is a multipage form and the dynavalidatorform is in the session.
> > 
> > I now know why it happens, but are there any other suggestions? 
> > 
> > 
> > 
> > -----Original Message-----
> > From: Wiebe de Jong [mailto:wiebedj@shaw.ca]
> > Sent: Tuesday, March 30, 2004 3:31 PM
> > To: 'Struts Users Mailing List'; jgkennedy@mindspring.com
> > Subject: RE: Problem with html:multibox not clearing
> > 
> > This is an HTTP problem. If the user clears all the checkboxes, the 
> > browser doesn't send anything back to the server. In this case, it 
> > seems that all the checkboxes still have their default value.
> > 
> > To fix this, I included a hidden checkbox on the form that is always 
> > checked. The user can't see or modify it, so it will always remain
> checked.
> > This ensures that the browser will always send back the checkbox list, 
> > even if all the checkboxes that the user can see are cleared.
> > 
> > Wiebe
> > http://frontierj.blogspot.com
> > 
> > 
> > -----Original Message-----
> > From: Jim Kennedy [mailto:jkennedy@davincitechnology.com]
> > Sent: Tuesday, March 30, 2004 12:06 PM
> > To: 'Struts Users Mailing List'
> > Subject: Problem with html:multibox not clearing
> > 
> >  I am using an html:multibox that is pretty much working fine except 
> > when I uncheck all choices. I am also using the logic:iterate tag to 
> > generate many checkboxes.  If I have a single box checked I can't seem 
> > to uncheck it if it's the last one.  If I have several checked, I can 
> > uncheck them one at a time and that works.  At least until I get down 
> > to just one checked.  Very odd.  The problem seems to be that I can't 
> > get Struts to realize that there are no checkboxes checked after I submit
> the form.
> > 
> > I am using struts 1.1, with DynaValidatorForm's.  Here's some of my code:
> > 
> > ...
> > <form-property name="amenity" 		type="java.lang.String[]" />
> > 
> > 
> > ...
> > 	<td colspan="4">
> > 	<logic-el:iterate id="item" name="amenities" indexId="i">
> > 		<html-el:multibox  property="amenity">
> > 			<bean:write name="item" property="code"/>
> > 		</html-el:multibox>
> > 			<bean:write name="item"
> > property="description"/>&nbsp;&nbsp;
> > 	</logic-el:iterate>
> > 	</td>
> > 
> > Don't think the above is the issue.  It's something deeper I think.
> > 
> > Any help is appreciated.
> > 
> > Jim Kennedy
> > IT Consultant
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > 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
> > 
> 
> ---------------------------------------------------------------------
> 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: Problem with html:multibox not clearing

Posted by Jim Kennedy <jk...@davincitechnology.com>.
Just an FYI, this did not work.  I don't believe it's a reset() issue.  From
other threads, it's the way an http request is sent when no checkboxes are
selected. Since nothing gets sent, nothing gets changed.  I will write some
JavaScript to manually check to see if anything has been checked.  If no
boxes are checked, I will artificially create a form element that has the
same name as the checkboxes.

That's my solution.

L8r and thanks


-----Original Message-----
From: Robert Taylor [mailto:rtaylor@mulework.com] 
Sent: Tuesday, March 30, 2004 4:00 PM
To: Struts Users Mailing List
Subject: RE: Problem with html:multibox not clearing

Jim, you can try this in your dynavalidatorform declaration:

<form-property name="amenity" 		
               type="java.lang.String[]"  
               initial="{}"/>

When you invoke an action, Struts will automatically reset your form.
So when you hit submit, Struts will invoke form.reset() which will reset all
your form properties to their initial values.

If you declare your initial value as an empty array (as above), then if
nothing is checked, the array will be empty. If something is checked, it
will be populated by the values in the request.

Give it a try. 

robert



> -----Original Message-----
> From: Jim Kennedy [mailto:jkennedy@davincitechnology.com]
> Sent: Tuesday, March 30, 2004 3:42 PM
> To: 'Struts Users Mailing List'
> Subject: RE: Problem with html:multibox not clearing
> 
> 
> That's not what I had in mind.  Thanks for the suggestion though.  I 
> found a thread that suggests that you must subclass dynavalidatorform 
> and override the reset() method.  Not really sure how that will help.
> 
> My form is a multipage form and the dynavalidatorform is in the session.
> 
> I now know why it happens, but are there any other suggestions? 
> 
> 
> 
> -----Original Message-----
> From: Wiebe de Jong [mailto:wiebedj@shaw.ca]
> Sent: Tuesday, March 30, 2004 3:31 PM
> To: 'Struts Users Mailing List'; jgkennedy@mindspring.com
> Subject: RE: Problem with html:multibox not clearing
> 
> This is an HTTP problem. If the user clears all the checkboxes, the 
> browser doesn't send anything back to the server. In this case, it 
> seems that all the checkboxes still have their default value.
> 
> To fix this, I included a hidden checkbox on the form that is always 
> checked. The user can't see or modify it, so it will always remain
checked.
> This ensures that the browser will always send back the checkbox list, 
> even if all the checkboxes that the user can see are cleared.
> 
> Wiebe
> http://frontierj.blogspot.com
> 
> 
> -----Original Message-----
> From: Jim Kennedy [mailto:jkennedy@davincitechnology.com]
> Sent: Tuesday, March 30, 2004 12:06 PM
> To: 'Struts Users Mailing List'
> Subject: Problem with html:multibox not clearing
> 
>  I am using an html:multibox that is pretty much working fine except 
> when I uncheck all choices. I am also using the logic:iterate tag to 
> generate many checkboxes.  If I have a single box checked I can't seem 
> to uncheck it if it's the last one.  If I have several checked, I can 
> uncheck them one at a time and that works.  At least until I get down 
> to just one checked.  Very odd.  The problem seems to be that I can't 
> get Struts to realize that there are no checkboxes checked after I submit
the form.
> 
> I am using struts 1.1, with DynaValidatorForm's.  Here's some of my code:
> 
> ...
> <form-property name="amenity" 		type="java.lang.String[]" />
> 
> 
> ...
> 	<td colspan="4">
> 	<logic-el:iterate id="item" name="amenities" indexId="i">
> 		<html-el:multibox  property="amenity">
> 			<bean:write name="item" property="code"/>
> 		</html-el:multibox>
> 			<bean:write name="item"
> property="description"/>&nbsp;&nbsp;
> 	</logic-el:iterate>
> 	</td>
> 
> Don't think the above is the issue.  It's something deeper I think.
> 
> Any help is appreciated.
> 
> Jim Kennedy
> IT Consultant
> 
> 
> 
> ---------------------------------------------------------------------
> 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
> 

---------------------------------------------------------------------
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: Problem with html:multibox not clearing

Posted by Robert Taylor <rt...@mulework.com>.
Jim, you can try this in your dynavalidatorform declaration:

<form-property name="amenity" 		
               type="java.lang.String[]"  
               initial="{}"/>

When you invoke an action, Struts will automatically reset your form.
So when you hit submit, Struts will invoke form.reset() which will
reset all your form properties to their initial values.

If you declare your initial value as an empty array (as above), then if nothing is checked,
the array will be empty. If something is checked, it will be populated by
the values in the request.

Give it a try. 

robert



> -----Original Message-----
> From: Jim Kennedy [mailto:jkennedy@davincitechnology.com]
> Sent: Tuesday, March 30, 2004 3:42 PM
> To: 'Struts Users Mailing List'
> Subject: RE: Problem with html:multibox not clearing
> 
> 
> That's not what I had in mind.  Thanks for the suggestion though.  I found a
> thread that suggests that you must subclass dynavalidatorform and override
> the reset() method.  Not really sure how that will help. 
> 
> My form is a multipage form and the dynavalidatorform is in the session.
> 
> I now know why it happens, but are there any other suggestions? 
> 
> 
> 
> -----Original Message-----
> From: Wiebe de Jong [mailto:wiebedj@shaw.ca] 
> Sent: Tuesday, March 30, 2004 3:31 PM
> To: 'Struts Users Mailing List'; jgkennedy@mindspring.com
> Subject: RE: Problem with html:multibox not clearing
> 
> This is an HTTP problem. If the user clears all the checkboxes, the browser
> doesn't send anything back to the server. In this case, it seems that all
> the checkboxes still have their default value. 
> 
> To fix this, I included a hidden checkbox on the form that is always
> checked. The user can't see or modify it, so it will always remain checked.
> This ensures that the browser will always send back the checkbox list, even
> if all the checkboxes that the user can see are cleared.
> 
> Wiebe
> http://frontierj.blogspot.com
> 
> 
> -----Original Message-----
> From: Jim Kennedy [mailto:jkennedy@davincitechnology.com]
> Sent: Tuesday, March 30, 2004 12:06 PM
> To: 'Struts Users Mailing List'
> Subject: Problem with html:multibox not clearing
> 
>  I am using an html:multibox that is pretty much working fine except when I
> uncheck all choices. I am also using the logic:iterate tag to generate many
> checkboxes.  If I have a single box checked I can't seem to uncheck it if
> it's the last one.  If I have several checked, I can uncheck them one at a
> time and that works.  At least until I get down to just one checked.  Very
> odd.  The problem seems to be that I can't get Struts to realize that there
> are no checkboxes checked after I submit the form.
> 
> I am using struts 1.1, with DynaValidatorForm's.  Here's some of my code:
> 
> ...
> <form-property name="amenity" 		type="java.lang.String[]" />
> 
> 
> ...
> 	<td colspan="4">
> 	<logic-el:iterate id="item" name="amenities" indexId="i">
> 		<html-el:multibox  property="amenity">
> 			<bean:write name="item" property="code"/>
> 		</html-el:multibox>
> 			<bean:write name="item"
> property="description"/>&nbsp;&nbsp;
> 	</logic-el:iterate>
> 	</td>
> 
> Don't think the above is the issue.  It's something deeper I think.
> 
> Any help is appreciated.
> 
> Jim Kennedy
> IT Consultant
> 
> 
> 
> ---------------------------------------------------------------------
> 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
> 

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


RE: Problem with html:multibox not clearing

Posted by Jim Kennedy <jk...@davincitechnology.com>.
That's not what I had in mind.  Thanks for the suggestion though.  I found a
thread that suggests that you must subclass dynavalidatorform and override
the reset() method.  Not really sure how that will help. 

My form is a multipage form and the dynavalidatorform is in the session.

I now know why it happens, but are there any other suggestions? 



-----Original Message-----
From: Wiebe de Jong [mailto:wiebedj@shaw.ca] 
Sent: Tuesday, March 30, 2004 3:31 PM
To: 'Struts Users Mailing List'; jgkennedy@mindspring.com
Subject: RE: Problem with html:multibox not clearing

This is an HTTP problem. If the user clears all the checkboxes, the browser
doesn't send anything back to the server. In this case, it seems that all
the checkboxes still have their default value. 

To fix this, I included a hidden checkbox on the form that is always
checked. The user can't see or modify it, so it will always remain checked.
This ensures that the browser will always send back the checkbox list, even
if all the checkboxes that the user can see are cleared.

Wiebe
http://frontierj.blogspot.com


-----Original Message-----
From: Jim Kennedy [mailto:jkennedy@davincitechnology.com]
Sent: Tuesday, March 30, 2004 12:06 PM
To: 'Struts Users Mailing List'
Subject: Problem with html:multibox not clearing

 I am using an html:multibox that is pretty much working fine except when I
uncheck all choices. I am also using the logic:iterate tag to generate many
checkboxes.  If I have a single box checked I can't seem to uncheck it if
it's the last one.  If I have several checked, I can uncheck them one at a
time and that works.  At least until I get down to just one checked.  Very
odd.  The problem seems to be that I can't get Struts to realize that there
are no checkboxes checked after I submit the form.

I am using struts 1.1, with DynaValidatorForm's.  Here's some of my code:

...
<form-property name="amenity" 		type="java.lang.String[]" />


...
	<td colspan="4">
	<logic-el:iterate id="item" name="amenities" indexId="i">
		<html-el:multibox  property="amenity">
			<bean:write name="item" property="code"/>
		</html-el:multibox>
			<bean:write name="item"
property="description"/>&nbsp;&nbsp;
	</logic-el:iterate>
	</td>

Don't think the above is the issue.  It's something deeper I think.

Any help is appreciated.

Jim Kennedy
IT Consultant



---------------------------------------------------------------------
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: Problem with html:multibox not clearing

Posted by Wiebe de Jong <wi...@shaw.ca>.
This is an HTTP problem. If the user clears all the checkboxes, the browser
doesn't send anything back to the server. In this case, it seems that all
the checkboxes still have their default value. 

To fix this, I included a hidden checkbox on the form that is always
checked. The user can't see or modify it, so it will always remain checked.
This ensures that the browser will always send back the checkbox list, even
if all the checkboxes that the user can see are cleared.

Wiebe
http://frontierj.blogspot.com


-----Original Message-----
From: Jim Kennedy [mailto:jkennedy@davincitechnology.com] 
Sent: Tuesday, March 30, 2004 12:06 PM
To: 'Struts Users Mailing List'
Subject: Problem with html:multibox not clearing

 I am using an html:multibox that is pretty much working fine except when I
uncheck all choices. I am also using the logic:iterate tag to generate many
checkboxes.  If I have a single box checked I can't seem to uncheck it if
it's the last one.  If I have several checked, I can uncheck them one at a
time and that works.  At least until I get down to just one checked.  Very
odd.  The problem seems to be that I can't get Struts to realize that there
are no checkboxes checked after I submit the form.

I am using struts 1.1, with DynaValidatorForm's.  Here's some of my code:

...
<form-property name="amenity" 		type="java.lang.String[]" />


...
	<td colspan="4">
	<logic-el:iterate id="item" name="amenities" indexId="i">
		<html-el:multibox  property="amenity">
			<bean:write name="item" property="code"/>
		</html-el:multibox>
			<bean:write name="item"
property="description"/>&nbsp;&nbsp;
	</logic-el:iterate>
	</td>

Don't think the above is the issue.  It's something deeper I think.

Any help is appreciated.

Jim Kennedy
IT Consultant



---------------------------------------------------------------------
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