File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Multibox reset method ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Multibox reset method ?" Watch "Multibox reset method ?" New topic

Multibox reset method ?

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 465
hi good day to all ,
i have a multibox which i use to display it in datagrid to let user tick and delete specific records, as shown below :

here is my actionform

number of multiboxes will depend on the List, let take an example for the List contains 3 records, so end up we have 3 multiboxes here and the values are "0" for mltibox1 , "1" for multibox2 and "3" for multibox3 .

my problem is , when i tick the multibox1 which have value='0'and click on "Delete" Button which eventually delete the List element with index = 0 , and it return two list now , however, now the multibox with value="1" ticked as it become first row , can i know how to reset it and make it all unchecked ? i already make a reset method but seem doesn't work

thanks for guidance
[ September 14, 2006: Message edited by: Nakata kokuyo ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If your ActionForm is in session scope, you will also have to reset the checkbox array to an empty array in the Action that performs the delete. Here is the sequence of events:

1- user checks a box and presses submit button

2- Struts calls reset, thereby making checkbox an empty array

3- Struts calls setCheckBox() making checkbox an array of at least one element.

4- The execute method of your Action class is called, performing the delete and forwarding back to the JSP.

5- JSP is redisplayed, and box still shows as checked because the checkbox array still has an element.

To fix this, you need to reset the array between steps 4 and 5.

Consultant, Sima Solutions
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 465
thanks Merrill Higginson for enlighten, i tackled the problem by setCheckBox(new String[]{}) right after perform the deletion operation ,

my curious now, how struts actually work for setCheckbox() and getCheckbox()? what is the logic behind ?
I agree. Here's the link:
subject: Multibox reset method ?
It's not a secret anymore!