| Author |
Urgent Help Required with Checkboxes!
|
J Ho
Greenhorn
Joined: Feb 19, 2004
Posts: 2
|
|
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
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
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>
|
A good workman is known by his tools.
|
 |
J Ho
Greenhorn
Joined: Feb 19, 2004
Posts: 2
|
|
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
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
This is the best I could come up with. ActionForm - JSP - *** refers to the name attribute of form-bean in struts-config
|
 |
Sahil Singh
Ranch Hand
Joined: Sep 03, 2003
Posts: 41
|
|
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
Joined: Sep 03, 2003
Posts: 41
|
|
Hi Marc , I have the answer. Needed a complete build. Ur code ran fine....Thanks again.. -Sahil
|
 |
Boon Subra
Ranch Hand
Joined: Jul 18, 2001
Posts: 69
|
|
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
Joined: Sep 03, 2003
Posts: 41
|
|
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 ]
|
 |
duc da
Greenhorn
Joined: Sep 16, 2005
Posts: 1
|
|
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
|
 |
sudhakar Tadepalli
Ranch Hand
Joined: Dec 27, 2001
Posts: 130
|
|
You ned to replace "***" with the form name you defined in Struts Config file. -Sudhakar
|
 |
 |
|
|
subject: Urgent Help Required with Checkboxes!
|
|
|