Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

a problem in struts html:checkbox

  Asked By: Fern    Date: Mar 08    Category: Java    Views: 8373
  

I've written a page containing a checkbox. I want it to be preChecked at the first time.
Html has attribue checked for type="checkbox", but html:checkbox does not have such an attribute. The attribute "value" does not work properly.
Any idea?

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Alfonso Martin     Answered On: Mar 08

If it's a dynamic form, you can set a default value in struts-config.xml:


<form-bean name="contactForm"
type="edu.example.ContactForm">
<form-property name="onHoldFlag"
type="java.lang.Boolean" initial="true"/>
</form-bean>

Otherwise, the place to do this is in your Action, before you forward to the
JSP. You only need to set the default the first time  the form is displayed.
Exactly where and how depends on how you've written  the app

 
Answer #2    Answered By: Amir Shaikh     Answered On: Mar 08

I used html:checkbox in jsp and set value="true" to
precheck it.
and it works corretly , i suggest you try agin .

 
Answer #3    Answered By: Abriana Rossi     Answered On: Mar 08

simply way you could use :


<html:checkbox property="true" />
if you wanna preChecked on load a web page  Or you could set it with parameters that you pass it.
<html:checkbox property="<%= checked %>" />

 
Answer #4    Answered By: Mario Ryan     Answered On: Mar 08

In the formbean(ActionForm) you have to define a boolean member variable and in the reset() method set it to true or false for checked and unchecked respectively.

 
Answer #5    Answered By: Garry Sanchez     Answered On: Mar 08

u could set u'r checkBox value in the FormBean when
initilazie it!

 
Answer #6    Answered By: Chung Tran     Answered On: Mar 08

You must define check value in value attribute  and set init property in your form bean with this value. For example write as following:

In source code:
...
YOUR_FORM_BEAN,setStatus("y");
...

In jsp page:
...
<html:checkbox property="status" value="y"/>
...

 
Didn't find what you were looking for? Find more on a problem in struts html:checkbox Or get search suggestion and latest updates.




Tagged: