Comrades,

Let us take the check the fruit example posted by Larry Maturo. Here the Fruit Object 
needs to have a boolean value called checked.

The ValueObject makes sense when its in a Struts Environment but doesnt it look like 
we have compromised on the Value Object definition? the checked instance variable 
should not have been there in the first place as it has nothing to do with a "Fruit" 
abstraction. I guess we need something like a ValueObject "add on" object to plug it 
in when we use this Object in a Struts environment.

later
hemant




//------------------------------------------------start
<logic:iterate id="fruits" name="nameOfYourFormBean" property="fruits">
<html:checkbox indexed="true" name="fruits" property="checked"/>
<bean:write name="fruits" property="fruitName" />
</logic:iterate>

in class Fruit
public class Fruit {
private String fruitName = "";
private boolean checked = false;

    public Fruit() {
        super();
    }

public String getFruitName() {
return fruitName;
}

public void setFruitName(String _fruitName) {
fruitName = _fruitName;
}

public boolean getChecked() {
return checked;
}

public void setChecked(boolean _checked){
checked = _checked;
}
}

In you form bean:

private ArrayList frutis = null;

public ArrayList getFruits() {
return fruits;
}

public void setFruits(ArrayList _frutis) {
fruits = _fruits;
}

public Fruit getFruits(int index) {
return (Fruit) fruits.get(index);
}

public void setFruits(int index, Fruit fruit) {
fruits.set(index,fruit);
}

public void reset(ActionMapping mapping,
                javax.servlet.http.HttpServletRequest request){
Fruit f = null;
Iterator it = fruits.iterator();
while it.hasNext() {
  f = (Fruit) it.next();
  f.setChecked(false);
}
}

//-------------------------------------------------end

Reply via email to