You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by "Artyom Kravchenko (JIRA)" <ji...@apache.org> on 2016/09/22 08:13:20 UTC
[jira] [Commented] (TAP5-2496) Inconsistent behavior of
EnumValueEncoder
[ https://issues.apache.org/jira/browse/TAP5-2496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15512569#comment-15512569 ]
Artyom Kravchenko commented on TAP5-2496:
-----------------------------------------
Hi
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:
{code:title=Pets.java|borderStyle=solid}
// Some comments here
public enum Pets {
DOG_PET("Dog"),
CAT_PET("Cat")
private String displayValue;
private Pets(String displayValue) {
this.displayValue = displayValue;
}
@Override
public String toString() {
return displayValue;
}
}
{code}
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 {code:borderStyle=solid}DOG_PET{code}
- 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 work).
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
(v6.3.4#6332)