• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

struts and multibox

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
suresh sai
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wowwwwww merill its working........thank you
 
Well THAT's new! Comfort me, reliable tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic