开发者

Why does UISelectMany not convert selectItems to a list of objects?

Just found the following in the Java EE Documentation for javax.faces.component.UISelectMany:

Obtain the Converter using the following algorithm: If the component has an attached Converter, use it. If not, look for a ValueExpression for value (if any). The ValueExpression must point to something that is:

  • An array of primitives (such as int[]). Look up the registered

    by-class Converter for this primitive type.

  • An array of objects (such as Integer[] or String[])开发者_C百科. Look up the

    registered by-class Converter for the underlying element type.

  • A java.util.Collection. Do not convert the values.

For a better understanding, I would like to know why the values won't be converted if the ValueExpression is a Collection.

If I want to attach a converter to UISelectMany, do I need to write a converter for the Collection or for the underlying element type?


Because EL don't/can't know about the generic list type, because it got lost during runtime. All it knows is that it's a collection of something. The items will be treated as String by default. You need to write a converter for the generic list type, not for the collection. See also this related answer.

To learn more about the type erasure of Java generics, check the generics tutorial.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜