• 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

Urgent Help Required with Checkboxes!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem I have is trying to default a checkbox on the initial load of the page, but then be set to whatever it is on submit.ie
I have two checkboxes, Assessed, and Non-Assessed. I want Non-Assessed to be defaulted to checked the first time the user views the page. However, the user can uncheck this box when he submits the page.
How would I achieve this? I've tried "setNonAssessed(true)" on the property in the action form's contstructor, and then adding a "setAsssessed(false)" statement to the reset method of the actionform, but this just causes the Non-Assessed box to be "rechecked" after I've submitted the form. I'm stumped ...
thanks in advance!
Jason
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Part of some of your frustration may stem from the fact that browsers typically do not submit a checkbox variable when it is unchecked.
Radio buttons seem more appropriate for your situation. Everything is either Assessed or Non-Assessed - always one but never both, right?
The following should do what you require.
ActionForm code:
private String rad = "Non-Assessed";
public String getRad(){
return this.rad;
}
public void setRad(String rad){
this.rad = rad;
}
JSP:
<html:radio property="rad" value="Non-Assessed"/>Non-Assessed<br>
<html:radio property="rad" value="Assessed"/>Assessed<br>
 
J Ho
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Marc, but I do require the case of "both" to be selected at the same time if need be.. I have implemented the checkboxes by manually doing the necessary logic in the actionform and setting the appropriate bean values.. but I was wanting to try and do it with the struts tags.. so if anyone does come up with a solution please let me know ...
J
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the best I could come up with.
ActionForm -

JSP - *** refers to the name attribute of form-bean in struts-config
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marc,
I have done exactly as you have described above,
but it gives the following error:


java.lang.NullPointerException
at java.util.Hashtable.get(Hashtable.java(Compiled Code))
at org.apache.jasper.runtime.PageContextImpl.findAttribute


Could u throw some light..
Thanks In advance,
-Sahil
 
Sahil Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marc ,
I have the answer.
Needed a complete build.
Ur code ran fine....Thanks again..
-Sahil
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sahil,

I also have the same task.This is something like.

I fetch the list of values from the database.for each record it has a checkbox column.

Depending on a particular logic, I should check the checkbox . Later the user can check/ uncheck it while submitting.

Can you please be clear with the codes.
Thanks,
Bhuvana
 
Sahil Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bhuvna,

From what i could understand,
u could define a array of string (depending on the no of records returned).
assign/populate them names on the fly using the values from the recordset ,
follow Marc's code from there and then the user is / should be able to check/uncheck the checkboxes..

Hope it made some sense,

i had to just cut/paste Mar'c code(just populating the Array with my own values for the checkboxes).

Questions are welcome,
-Sahil
[ July 09, 2004: Message edited by: Sahil Singh ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, but I still got errors. If I keep <logic:iterate name="***" so it said that cannot find the bean name ***, through *** I mapped in struts-config.xml.
Then I use type attribute instead of name, handly map to my actionForm, and I got this error
java.lang.NullPointerException
at java.util.Hashtable.get(Hashtable.java:333)
at org.apache.jasper.runtime.PageContextImpl.findAttribute(PageContextImpl.java:303)
Please tell me the way to handle this. Iam using JBuilder 10 to config the Struts-config
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You ned to replace "***" with the form name you defined in Struts Config file.

-Sudhakar
 
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic