• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
permaculture is largely about replacing oil with people. And one tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic