• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to get the value of checkbox?

 
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 have a checkbox in my jsp page,

When i click this ActionForm takes the value true otherwise it will take false,

How it is in struts,

Help me,

Thanks in advance.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When i click this ActionForm takes the value true otherwise it will take false,


That's exactly how it works in Struts.

One thing you do need to do, though, is override the reset() method in your ActionForm.

You must have your reset() method set any properties in your ActionForm controlled by a checkbox to false. You need to do this because if the checkbox is not checked, no data will be sent to the server for the property, and consequently the property's setter will not get called. By setting it to false in the reset method, you make sure that if it was true previously and the user unchecks the box, it will be false after the form is submitted.
 
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,

If the checkboxes multiple with same name ,

then how to define in ActionForm and reset method;

help me,

Thanks in advance
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this case, definie the property in your ActionForm as type String[]. Here's what your ActionForm would look like:

Also, make sure you use <html:multibox> instead of <html:checkbox>
[ July 20, 2006: Message edited by: Merrill Higginson ]
 
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

in my jsp proerties are like this

itemcode itemname checkbox ADDMORE

when i click addmore one more row added in jsp using javascript,

itemcode itemname checkbox
itemcode itemname checkbox like this

checkbox define like this
html:checkbox property="percent" value="true"

my Action form

public String[] getPercent() {
return percent;
}

public void setPercent(String[] percent) {
this.percent=percent;

}

public String[] percent;

public void reset(ActionMapping mapping, HttpServletRequest request)
{
}

when the checkbox is checked it takes the value true, it works fine,

when it is not cheked i want to take false,

how it is,keep in mind it is array,

ex may be it will come true,false,false,true,false like this

Help me

Thanks in advance
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a totally different situation. The solution I described before would work for a case where the value of the box is not boolean, and you just want a list of the values. It would not work for this situation

In your case, I think a JavaScript solution might be better. Try this:

Immediately before the form is submitted, use JavaScript to iterate over all the checkboxes, and for each one of them, perform the following logic:


By changing the value to false and checking the box, you are making sure that a value will be sent back to the server, and that the value will be false.
 
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
Thank u very much Higgi,

This script code is work fine
 
Greenhorn
Posts: 3
Monad Java ME Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

johny sil wrote:Hi,

I have a checkbox in my jsp page,

When i click this ActionForm takes the value true otherwise it will take false,

How it is in struts,

Help me,

Thanks in advance.

there have to be two values like "checked" and "" or null
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic