Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.java.programmer > #4981

Re: JSF feeds a Set<String> into a Set<Foo>

From Stanimir Stamenkov <s7an10@netscape.net>
Newsgroups comp.lang.java.programmer
Subject Re: JSF feeds a Set<String> into a Set<Foo>
Date 2011-06-04 17:42 +0300
Organization A noiseless patient Spider
Message-ID <isdg7s$npv$1@dont-email.me> (permalink)
References <4de7e53a$0$21180$426a34cc@news.free.fr>

Show all headers | View raw


Thu, 02 Jun 2011 21:32:09 +0200, /Elegie/:

> I am currently learning JSF2.0, and have just encountered a behavior
> I do not understand. Basically, I have a test case (see below) where
> I have a typed set (Set<Foo>) whose content, automatically populated
> by JSF, is made of strings (Set<String>). This should not even
> compile, yet this runs. What am I missing?
> (...)

You're missing the generics type erasure [1].  JSF doesn't have the 
generics type information at run time.  A related (but not the same) 
issue [2] has been brought to the JSF Dev mailing list.

To resolve the issue you could attach converter to your input 
component explicitly, e.g.:

   <h:selectManyCheckbox
       value="#{testCase.foos}"
       converter="#{...}">
     ...
   </h:selectManyCheckbox>

where you bind the converter instance directly, or:

   <h:selectManyCheckbox
       value="#{testCase.foos}">
     <f:converter converterId="..." />
     ...
   </h:selectManyCheckbox>

where you provide a registered converter ID.  With JSF 1.2 one 
register a custom converter by adding such an element in the 
"faces-config.xml" file:

   <converter>
     <converter-id>test.FooConverter</converter-id>
     <converter-class>test.faces.FooConverter</converter-class>
   </converter>

JSF 2.0 may provide more convenient annotation placed on the 
converter class directly (don't know, I have really no JSF 2 
experience, yet).

[1] 
http://download.oracle.com/javase/tutorial/java/generics/erasure.html
[2] "JSF & Support for Generic Types... Again..." 
<http://java.net/projects/javaserverfaces/lists/dev/archive/2011-04/message/15>

-- 
Stanimir

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

JSF feeds a Set<String> into a Set<Foo> Elegie <elegie@invalid> - 2011-06-02 21:32 +0200
  Re: JSF feeds a Set<String> into a Set<Foo> Stanimir Stamenkov <s7an10@netscape.net> - 2011-06-04 17:42 +0300
    Re: JSF feeds a Set<String> into a Set<Foo> Elegie <elegie@invalid> - 2011-06-04 18:49 +0200

csiph-web