You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Geoff Callender <ge...@gmail.com> on 2007/11/23 12:07:29 UTC
Boolean ValueEncoder
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
Re: Boolean ValueEncoder
Posted by Geoff Callender <ge...@gmail.com>.
It seems the type coercer is coercing null to Boolean.FALSE. I see
this as a bug so I've created https://issues.apache.org/jira/browse/TAPESTRY-1928
.
On 23/11/2007, at 10:07 PM, Geoff Callender wrote:
> 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