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

html:checkbox problem

 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have "<html:checkbox property="selectedCheckBox" value="msgId"/>" in my JSP

here are the respective getter/setter methods for this

private boolean selectedCheckBox= false;

public boolean isSelectedCheckBox() {
return selectedCheckBox;
}
/**
* @param selectedCheckBox The selectedCheckBox to set.
*/
public void setSelectedCheckBox(boolean selectedCheckBox) {
this.selectedCheckBox = selectedCheckBox;
}

When I try to get the value of checkbox(when used checked from JSP) in my action class It always return fase whether it is checked or unchecked

Can someone help on this.

-santosh
[ May 01, 2006: Message edited by: Santosh Maskar ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change

<html:checkbox property="selectedCheckBox" value="msgId"/>

to

<html:checkbox property="selectedCheckBox" value="true"/>

For a checkbox, the value attribute indicates the value that the property in the ActionForm will be populated with if the box is checked.
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this is a problem in Struts. One way I know to work around the problem is to get the checkbox value from the request parameter and then use logic in your Java code to check the value of the checkbox property being returned in the parameter and then setting the property of ur checkbox in the bean.

e.g. String checkValue = request.getParameter("[checkBoxProperty]");

if(checkValue.equals(true)){
}
 
Zip Ped
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this is a problem in Struts. One way I know to work around the problem is to get the checkbox value from the request parameter and then use logic in your Java code to check the value of the checkbox property being returned in the parameter and then setting the property of ur checkbox in the bean.

e.g. String checkValue = request.getParameter("[checkBoxProperty]");

if(checkValue.equals("true")){
beanName.setCheckBoxProperty(true);
} else{
//....
}
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Struts have one problem as it will send value to form bean only if the check box is selected. For overcoming this issue,in java script u need to give the value externally.

For exmp.
if(document.forms[0].preselected.checked){
document.forms[0].preselected.value="true";
}else{
document.forms[0].preselected.value="false";
}

Where as preselected is the field in form bean, which we are using with check box name also, like

<html:checkbox property="preselected" value="on"/>

It should work as you expect....

Regards,
Thomas
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic