• 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

Display checkbox intially checked

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

I want to display checkbox is cheked intially in sturts

I am using <html:checkbox>

is there any attribute to solve this problem

Help me,

Thanks in advance
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<html:checkbox value="1" property="nameOfField" />

Then when it goes to prepopulate if it returns a value of 1 for "nameOfField" it will show as checked.
 
johny sil
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply

How it is define in ActionForm
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The value attribute for an <html:checkbox> is a little different than other controls. It indicates the value that will be passed to the server when the box is checked. It does not indicate whether the box will initially be displayed as checked or not.

Since the <html:checkbox> is tied to the value of the ActionForm property you specify, the way to indicate that the box is to be displayed as checked is to set the ActionForm property it is tied to as "true" prior to the page being displayed. Example:

in your Action form:

private boolean myCheckbox;
public boolean isMyCheckBox() { return myCheckbox; }
public void setMyCheckBox(checkboxValue) { myCheckbox = checkBoxValue; }

In the Action that forwards to the JSP

myForm.setCheckBox(true);

In your JSP:

<html:checkBox property="myCheckBox" />

This will cause the checkbox to show as checked when the page is displayed.
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic