Hi,
I've struck a problem while trying to do a Select on a Boolean with 3-
value logic: I display "", "true", and "false".
The problem is that when the user chooses "", Tapestry sets the value
field to Boolean.FALSE instead of null.
Here's the template code:
<select t:id="active" t:type="Select" value="active" model="actives"
encoder="booleanValueEncoder"/>
Here's the relevant java:
static private final Boolean[] ACTIVES = { null, Boolean.TRUE,
Boolean.FALSE };
static private final BooleanValueEncoder BOOLEAN_VALUE_ENCODER = new
BooleanValueEncoder();
public Boolean getActive() {
return _active;
}
public void setActive(Boolean active) {
_active = active;
}
public Boolean[] getActives() {
return ACTIVES;
}
public BooleanValueEncoder getBooleanValueEncoder() {
return BOOLEAN_VALUE_ENCODER;
}
Here's my BooleanValueEncoder:
public class BooleanValueEncoder implements ValueEncoder<Boolean> {
public String toClient(Boolean value) {
return value == null ? "" : value.toString();
}
public Boolean toValue(String clientValue) {
return clientValue.equals("") ? null :
Boolean.valueOf(clientValue);
}
}
I've checked that when "" is chosen the encoder does return null, but
then Tapestry calls setActive(false).
Am I doing something wrong?
Regards,
Geoff