This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi All, I am facing a problem in struts. My requirement is to check a checkbox automatically when the form is loaded. In HTML, We can do the same by following code. <input type="checkbox" name="product" value="Rice"> <input type="checkbox" name="product" value="Wheat" checked> <input type="checkbox" name="product" value="Sugar"> The above html code will show three checkboxes with second check boxes as checked. Same thing i want to perform using struts. But unable to do it. <html:checkbox property="product" value="Rice" /> <html:checkbox property="product" value="Wheat" checked="true" />//Error as no property like checked. <html:checkbox property="product" value="Sugar" />
You are facing this problem because when the JSP is rendered, the compiler checks for the method getChecked() in the corresponding form bean class. However, I don't think you are using any form bean class to represent your JSP page.
Joined: Aug 13, 2003
Dear, I am using FormBean corresponding to my JSP page. I don't want to use java script. Can you please explain the functionality of getChecked() method. Thanks, Jatinder Arora. [ January 20, 2006: Message edited by: dimpsonu arora ]
The <html:checkbox> tag will automatically check the box if the value of product property of your form bean is "Wheat". To make sure the checkbox for "Wheat" is checked, in the action that forwards to this JSP, just include the statement
Or, if the value comes from a database, populate the product property with a call to the database.