Search code examples
jsfcomposite-componentparameterized-types

How to pass a List<Note> in JSF composite component?


I have to create a JSF composite component where, I have to pass a attribute like below:

<composite:attribute name="noteList" type="XXX" required="true"></composite:attribute>

what should I pass in type attribute if it is a List of type Note class?

I know I can make type="java.util.List", but how can I make it specific to List of type Note?


Solution

  • but how can I make it specific to List of type Note

    Unfortunately, you can't. It's determined during runtime, during which the generic type information is already lost. Technically, this can be workarounded using reflection trickery, but JSF and EL spec guys may have their own reasons for not specifying it.

    Your best bet is to replace it by a custom subclass as below:

    public class Notes extends ArrayList<Note> {}
    
    <cc:attribute ... type="com.example.model.Notes" />
    

    But this may require changes in the model.