JSF 2 f:param inside of ui:repeat

瘦欲@ 提交于 2019-12-08 06:11:34

问题


as the question above mentiones, i need to create "dynamic" params for a

<ui:composition>
    <h:link>
        <h:outputText value="link with params" />
        <ui:repeat var="parameter" value="#{bean.getCurrentParameter}"> //customClass

            test: #{parameter.name} #{parameter.value} //output is fine

            <f:param name="#{parameter.name}" value="#{parameter.value}" />
        </ui:repeat>
    </h:link>
</ui:composition>

unfortunately the "test" returns all values correctly, but when I hover the link, there is not a single parameter set ("page.xhtml" instead of "page.xhtml?param1=ddd&param2=sss...")

To unterstand why I need this, I want to get all parameters of the current page and add/remove one (the link clicked on is the one I want to remove/add).

to I need to generate for each link its own parameters (when param1=1,2 by default, one link has e.g. "param1=1,2,3" (appends 3) and the other one has "param1=1,2,4" (appends 4))


回答1:


Classic taghandlers vs component tags issue. <ui:repeat/> is a component tag that runs after the view tree has been built while <f:param/> is a tag handler that is placed in the view tree during view build. What this means is that <f:param/> is parsed and processed before <ui:repeat/> ever makes it into the page. As a result var="parameter" is not available for use when <f:param/> needs it.

To fix, use the <c:forEach/> tag instead:

<h:link>
   <h:outputText value="link with params" />
   <c:forEach var="parameter" items="#{bean.getCurrentParameter}">
       test: #{parameter.name} #{parameter.value}
        <f:param name="#{parameter.name}" value="#{parameter.value}" />
   </c:forEach>
</h:link>


来源:https://stackoverflow.com/questions/19497481/jsf-2-fparam-inside-of-uirepeat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!