File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Dynamic iterate checkbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Dynamic iterate checkbox" Watch "Dynamic iterate checkbox" New topic

Dynamic iterate checkbox

Albert Mora

Joined: Feb 14, 2007
Posts: 2
Hi, i've a problem with the tag html:checkbox. With other tags (html:text) i try this and it's ok. I put one checkbox in a logic:iterate, and its prints me the data from the BBDD, but the problem is when i unckecked some checkbox and submit() the form, in the Form in Action(ActuMedioambiental.saveTareas()) not appears the new value... but if i check and unchecked checkbox the value in the Action is the correct.

My code:


<logic:iterate indexId="i" name="actuMedioambientalForm" id="tarea" property="tareas">
<html:checkbox name="tarea" property="fechaPrevistaInd" value="true"></html:checkbox>

private ActionForward loadTareas(...) {

private ActionForward saveTareas(...) {
ActuMedioambientalForm actuMedioambientalFrom = (ActuMedioambientalForm) form;

public void setTareas(List tareas) {
this.tareas = tareas;

public List getTareas() {
return tareas;

public TareaBean getTarea(int index)
return (TareaBean)tareas.get(index);

public void setTarea(int index, TareaBean tarea) {


<action path="/actuMedioambiental" type="es.indra.tram.control.action.actuMedioambiental.ActuMedioambiental" name="actuMedioambientalForm" scope="session" validate="false">
<forward name="tareas" path="/paginas/actuMedioambiental/tareas.jsp"/>

private boolean fechaPrevistaInd = false;
private boolean fechaRealInd = false;
public void setFechaPrevistaInd(boolean fechaPrevistaInd) {
this.fechaPrevistaInd = fechaPrevistaInd;
public boolean getFechaPrevistaInd() {
return this.fechaPrevistaInd;

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This problem is due to an odd behavior of the HTML for checkboxes. If a checkbox is unchecked, no parameter is sent to the server, and hence, no setter is called in the Struts ActionForm. To get around this problem, you must override the reset method in your ActionForm, and in that method, set the value of each property associated with a checkbox to its unchecked value. Since struts calls the reset method before it calls the setters, any checkboxes that are checked will cause the setters to override the values set in the reset method. Here's an example:

Consultant, Sima Solutions
Dave Hayward

Joined: Feb 28, 2007
Posts: 14
Merrill - a quick non-related question.

I have seen you use the @Override before re-defining the public void reset() method. Is that necessary? I don't have that when I override the reset() method. Thanks!

The worst thing with having everything is finding a place in the garage to keep it.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
@Override is a java 1.5 annotation, so it only works if your development environment and your App Server supports Java SE 1.5. It's entirely optional, but I like it and have started using it because it gives me an added level of error checking. If I get one of the parameters wrong on the method, the compiler will tell me "Hey, you said you were overriding a method, but there's no method in any of your superclasses that matches that signature."

It also makes for good documentation. When looking at a class, it's very helpful to know which methods are overriding superclass methods.
[ March 01, 2007: Message edited by: Merrill Higginson ]
I agree. Here's the link:
subject: Dynamic iterate checkbox
It's not a secret anymore!