Artyom Kravchenko commented on TAP5-2496:

I use 5.4.1 version. 
I see that {code:borderStyle=solid}EnumValueEncoder.toClient(E){code} has 
{code:borderStyle=solid}typeCoercer.coerce(value, String.class){code} instead 
of  {code:borderStyle=solid}java.lang.Enum.name(){code} as it was in 5.3.8 (my 
previous version). I did not find any commits (work logs) in this task and 
5.4.1 tasks where  {code:borderStyle=solid}EnumValueEncoder.toClient(E){code} 
was changed.

But any way it was changed and I faced with issue after upgrade. The main 
reason is: 
I have enum like:

// Some comments here
public enum Pets {

    private String displayValue;

    private Pets(String displayValue) {
                this.displayValue = displayValue;

    public String toString() {
        return displayValue;

As you see 
 {code:borderStyle=solid}toString(){code} method overridden therefore   
{code:borderStyle=solid}DOG_PET.toString() != DOG_PET.name(){code} 

When 'select options' (combo box with enum) renders it uses  
{code:borderStyle=solid}typeCoercer.coerce(DOG_PET, enumType){code} to get 
value attribute for <option/> tag  (before it was just 
{code:borderStyle=solid}DOG_PET.name() == "DOG_PET"{code}).  Eventually we just 
get {code:borderStyle=solid}DOG_PET.toString() == "Dog"{code} as a result value.

Then on submit {code:borderStyle=solid}StringToEnumCoercion{code} try to 
'restore' selected option value to enum instance:

- collect all enum values to map where key is: 
{code:borderStyle=solid}DOG_PET.name(){code} and value 
- extract value from map (using option value as key == "Dog")

Of course it has null result since "Dog" != "DOG_PET".

In other word <t:select/> will not works if my enum has overridden 
{code:borderStyle=solid}toString(){code} method (it require custom encoder to 

I think it is need to use single mechanist to bind enum to string and vice 
versa in both cases: {code:borderStyle=solid}typeCoercer.coerce(value, 
String.class){code} or  {code:borderStyle=solid}value.name(){code}

> Inconsistent behavior of EnumValueEncoder 
> ------------------------------------------
>                 Key: TAP5-2496
>                 URL: https://issues.apache.org/jira/browse/TAP5-2496
>             Project: Tapestry 5
>          Issue Type: Bug
>    Affects Versions: 5.4
>            Reporter: Jochen Kemnade
>            Assignee: Jochen Kemnade
>             Fix For: 5.4
> EnumValueEncoder uses {{java.lang.Enum.name()}} in {{toClient(E)}} but uses 
> {{typeCoercer.coerce(clientValue, enumType)}} in {{toValue(String 
> clientValue)}}.
> I have a custom coercer in my project and this causes the value encoder to be 
> unable to decode the client-side value back to a server-side value.
> I think we should remove {{EnumValueEncoderFactory}} altogether because 
> {{TypeCoercedValueEncoderFactory}} should do its job just fine.

This message was sent by Atlassian JIRA

Reply via email to