File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes html:multibox problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:multibox problem" Watch "html:multibox problem" New topic
Author

html:multibox problem

Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
There is html:multibox placed on my form for status. Problem is, when I select any values from multibox and submit the form, second time when submit the form by deselecting previous values, previous values of boxes are checked.
Can anybody tell me what might be the reason?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The reason is that nothing is submitted to the server when a checkbox is unchecked. For this reaason you should override the reset(...) method of ActionForm to set the String array associated with the checkboxes to an empty array (new String[0]). Struts calls reset before populating the properties, so only when boxes are checked will there be a value in the array. Otherwise it will be empty.


Merrill
Consultant, Sima Solutions
Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
Thanks for reply Merrill.
But I have another problem regarding this.
I have 2 jsps, one is to display criterias that user can apply and second is the result page.
On this result page there are Back and Refresh buttons.
On clicking Back button, it should go to first page and
On clicking Refresh button, it should refresh result page with previous form criterias.
Previously I used to call that action again on click of Back & Refresh button.
If I add this reset(..) method, form criterias are got reset, and on refresh it gives me NullPointerException.
Is there any way to tackle this?

Thanks
Deepa
[ April 24, 2007: Message edited by: Deepa More ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Overriding reset(...) alone would not have caused a NPE. Please show use the contents of your reset method, as well as the full text of the error message along with the first few lines of the stack trace. Also, are you overriding the function of the back button? If so, show us specifically what you're doing.
Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
That NPE was because of some mistake, but the problem is form getting reset on Back and refresh.

(I wrote onClickf as it was not able to save it with correct one)

And these are javascript functions:


And in action class, for first time and for Back option, we are setting forward as first page and for others we call DAO to get values from database.
Now if I write reset(...) method in form, as you said every time form is submitted it calls this method, so form values get reset.
So my Back & Refresh buttons doesn't work as they should be.
Back button does not go to previous history page, it should go to first criteria page, so we call submit on that too.

Hope you got my problem.

[ April 25, 2007: Message edited by: Deepa More ]

[ April 25, 2007: Message edited by: Deepa More ]
[ April 25, 2007: Message edited by: Deepa More ]
Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
I tried overloading reset() method with no args and calling that method for first time only, then back/refresh works fine, but multi box problem remains.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Don't reset everything in your reset method. Just reset the array used as the property for the html:multibox tag.
Luiz Antonio
Greenhorn

Joined: Jul 17, 2009
Posts: 1
Sorry to UP this topic, but it was really useful to me.

Thanks Merrill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: html:multibox problem
 
Similar Threads
Prventing Page to Cache
form values not updated
multibox , resultSet, logic:iterate
form values lost in request scope
Struts - Check boxes problem