This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Struts and the fly likes struts and multibox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts and multibox" Watch "struts and multibox" New topic
Author

struts and multibox

suresh sai
Ranch Hand

Joined: Jul 16, 2007
Posts: 62
Hi all.,
I have a multibox in my JSP and I am displaying it through display tag.I have corresponding String array property in my form.But the deselection of the checkboxes is not refelcting once the form is submitted...that means I have selected 2 of 5 checkboxes and submitted.And again I went to the same page deselected and submitted.But this time,the string array is not changing.Once the selection is made ,the deselection is not working.For this I have written javascript code. I am calling javascript function upon each selection and deselction of the checkbox.In that function if it is selected..I am putting the value as rownumber+1 ,if deselected I am putting an Empty string.After setting ,I have displayed the values through alerts.They are showing the correct values.But in the reset(),validate() methods old values are coming..means, once the selection is made that particular index is updated,but its not updating afterwards.
Here I am showing the code for java script...

function setCheckBoxes(rowNum,formName)
{
mBox= document[formName]['mycheckbox'];
var checked=false;
if(mBox)
{
if(typeof mBox.length != 'undefined')
{
if(!mBox[rowNum].checked)
{
alert('you are not selected....');
document.getElementById("selectCheckBox["+rowNum+"]").value="";
alert("document.getElementById(selectCheckBox ["+rowNum+"]).value==="+document.getElementById("selectCheckBox ["+rowNum+"]").value);
}
else
{
document.getElementById("selectCheckBox ["+rowNum+"]").value=rowNum+1;
alert("document.getElementById(selectCheckBox["+rowNum+"]).value==="+document.getElementById("selectCheckBox["+rowNum+"]").value);
}

}
else
{
alert('mbox length is one.....');
if(!document.forms[formName]['mycheckbox'].checked)
{
selectCheckBox="";
alert('you are not selected....');
alert('the value...is'+selectCheckBox);
}
}


}
}

and in the JSP...

html:multibox property="selectCheckBox[${rowNo}]" value="${rowNo+1}"
title="click the check box to select" styleId="mycheckbox" on_click="setClientAccounts(${rowNo},'myForm')"

bean:write name="checklist_rowNum" /

/html:multibox
I have removed the angular brackets...I hope you can understand...
Please tellme the soluiton for reflecting the checkbox values....
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This problem is caused by an odd behavior of HTML: Check boxes that are left unchecked do not submit any value when the form is submitted. That means that the ActionForm will remain unaffected if you deselect a checkbox because there's no event to call the ActionForm setter.

The workaround for this is to override the reset(ActionMapping mapping, HTTPServletRequest request) method in your ActionForm and in that method set the string array to an empty array. Since the reset method is called by struts prior to calling the setters, this will cause all checkbox values to be set as unchecked, and then when the setters are called, only those checkboxes actually checked by the user will cause a value to be placed in the ActionForm array.


Merrill
Consultant, Sima Solutions
suresh sai
Ranch Hand

Joined: Jul 16, 2007
Posts: 62
wowwwwww merill its working........thank you
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: struts and multibox
 
Similar Threads
Multibox Not Populating as Checked!!!
multibox , resultSet, logic:iterate
html-multibox How can i make certain values checked
Iterator and multibox
Display tag and Struts multibox tag