jsfarraylistparameter-passingelfacelets

Send array list via ui:param to JSF ui:composition template


I know i can use ui:param to pass a string from a composition built upon a template

Like this: http://www.mkyong.com/jsf2/how-to-pass-parameters-to-jsf-2-0-template-file/

Then I can use the parameter in the XHTML for the template file.

Can you send an array?

I.e.

<ui:insert name="header" >
   <ui:include src="/template/common/commonHeader.xhtml">

    <ui:array name="tagArray" values="val1, val2, val3" />

   </ui:include>
</ui:insert>

Solution

  • Only if your environment supports EL 3.0 (part of Java EE 6 / Servlet 3.0, thus at least Tomcat 8, WildFly 8, GlassFish 4, etc or newer). You can the use the list construction notation #{[x,y,z]}.

    <ui:param name="tagList" value="#{['val1', 'val2', 'val3']}" />
    

    If you're not on EL 3.0 yet, then your best bet is using JSTL fn:split() to split a delimited string to an array.

    <ui:param name="tagArray" value="#{fn:split('val1,val2,val3', ',')}" />