Setting <f:param> value with <ui:repeat> var

2.1k Views Asked by At
<h:form>
    <ui:repeat value="#{sampleManagedBean.food}" var="food">
        <h:commandLink value="Name" action="#{sampleManagedBean.outcome}">
            <f:param name="name" value="ssd" />
            <f:param name="v" value="#{food.boy}" />
        </h:commandLink>
        <h2>#{food.boy}</h2>
    </ui:repeat>
</h:form> 

I can't get the the second <f:param> value which is set based on <ui:repeat var>. I can get only the first one which is hardcoded.

2

There are 2 best solutions below

0
On

try this way,

    <h:form>
    <ui:repeat value="#{sampleManagedBean.food}" var="food">
        <h:commandLink value="Name" action="#{sampleManagedBean.outcome}">
            <f:setPropertyActionListener value="ssd" target="#{sampleManagedBean.name}" />
            <f:setPropertyActionListener value="#{food.boy}" target="#{sampleManagedBean.v}" />
        </h:commandLink>
    </ui:repeat>
    </h:form>
0
On

The ui:repeat is an UI component while f:param is a taghandler (like JSTL). Taghandlers run during view build time before UI components which run during view render time (see here).

In our case it means that in the view build phase f:param knows nothing about #{food.boy}. c:forEach will be fine, but if we call some kind of ajax action to change the size of
#{sampleManagedBean.food} and rerender the form, we'll not see any changes on page. Because partial rerendering (ajax) affects only UI component tree. c:forEach is somewhere between hardcoding and ui:repeat, we'll have to reload the page to see changes.