Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jsp/checkbox problem

Status
Not open for further replies.

jagprg

Programmer
Jun 16, 2005
11
US
HI,

I have a jsp page with 2-3 check boxes, I get the object from the database which returns a boolean, How do I use that to set the checkbox

Code:
<html:checkbox property="Supplies"  value='<%= obj.getUnmeteredTO().getSupplies() ? "true" : "false" %>'/> -- Supplies<br/>



I am able to set the value but not the check box itself, how do i set it so that it is visible as checked on the jsp page.(depending on the value from db)

thanks
 
try this :
Code:
<html:checkbox property="Supplies"  checked='<%= obj.getUnmeteredTO().getSupplies() ? "checked" : "" %>'/> -- Supplies<br/>

That should work.

Water is not bad as long as it remains outside human body ;-)
 
Hi,

In the action class that invokes the jsp page set Supplies value with the values in the jsp and set it back to the ActionForm.

Ex:
CheckBoxForm.java
Code:
  private String[] fruits = {};
  public void setFruits(String[] fruits) {
        this.fruits = fruits;
    }
  public String[] getFruits() {
        return fruits;
    }
In CheckBoxAction.java
Code:
 String[] defaultFruits = { "Orange", "Banana", "Apple" };
 CheckBoxForm form = (CheckBoxForm)form;
 form.setFruits(defaultFruits)

checkBox.jsp
Code:
<html:multibox property="fruits" value="Strawberry" />Strawberry<br />
	<html:multibox property="fruits" value="Apple"/>Apple<br />
	<html:multibox property="fruits" value="Orange"/>Orange<br />
	<html:multibox property="fruits" value="Pear"/>Pear<br />
	<html:multibox property="fruits" value="Mango"/>Mango<br />
	<html:multibox property="fruits" value="Banana"/>Banana<br />
	<html:multibox property="fruits" value="Pineapple"/>Pineapple<br />

It will select only the fruits in the defaultFruits[]. Try some thing like this.

Cheers
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top