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:checkbox problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:checkbox problem" Watch "html:checkbox problem" New topic
Author

html:checkbox problem

Santosh Maskar
Ranch Hand

Joined: Jul 02, 2003
Posts: 226
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 ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
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

Joined: Jul 26, 2005
Posts: 336
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{
//....
}
Thomas vezhamb
Greenhorn

Joined: May 01, 2006
Posts: 3
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: html:checkbox problem