admin管理员组

文章数量:1316974

I am working with JSF Facelets and have initialized parameters using <ui:param> in different templates. Here's the relevant code snippet:

<ui:composition xmlns="; xmlns:h="jakarta.faces.html" xmlns:f="jakarta.faces.core" xmlns:ui="jakarta.faces.facelets" xmlns:c="jakarta.tags.core">

    <ui:param name="param1" value="value 1" />
    <ui:param name="param2" value="value 2" />
    <ui:param name="param3" value="value 3" />

    param1: #{param1}
    <p></p>
    param2: #{param2}
    <p></p>
    param3: #{param3}

    <c:forEach begin="1" end="3" var="idx">
        <p></p>
        <h:outputText value="**How can I dynamically set the parameter name here (e.g., param${idx}) to get the corresponding value?**" />
    </c:forEach>
</ui:composition>

How can I dynamically access the ui:param values using a loop (like <c:forEach>)? I want to retrieve the corresponding values based on the dynamic parameter names.

I am working with JSF Facelets and have initialized parameters using <ui:param> in different templates. Here's the relevant code snippet:

<ui:composition xmlns="http://www.w3./1999/xhtml" xmlns:h="jakarta.faces.html" xmlns:f="jakarta.faces.core" xmlns:ui="jakarta.faces.facelets" xmlns:c="jakarta.tags.core">

    <ui:param name="param1" value="value 1" />
    <ui:param name="param2" value="value 2" />
    <ui:param name="param3" value="value 3" />

    param1: #{param1}
    <p></p>
    param2: #{param2}
    <p></p>
    param3: #{param3}

    <c:forEach begin="1" end="3" var="idx">
        <p></p>
        <h:outputText value="**How can I dynamically set the parameter name here (e.g., param${idx}) to get the corresponding value?**" />
    </c:forEach>
</ui:composition>

How can I dynamically access the ui:param values using a loop (like <c:forEach>)? I want to retrieve the corresponding values based on the dynamic parameter names.

Share Improve this question edited Feb 15 at 13:04 Mark Rotteveel 109k229 gold badges156 silver badges220 bronze badges asked Jan 28 at 12:59 Andrew ChurchillAndrew Churchill 112 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

The <ui:param> is not suitable for this. It's not stored in a publicly accessible scope and there's no such thing as #{faceletScope} (that's probably a good idea for next Faces version though).

Use <c:set> instead. On that you can explicitly specify the desired scope. The request scope is your best bet, but the view scope can also, depending on the nature of the param value. Then you can simply access the param via either #{requestScope} or #{viewScope} map respectively.

<c:set var="param1" value="value 1" scope="request" />
<c:set var="param2" value="value 2" scope="request" />
<c:set var="param3" value="value 3" scope="request" />

<p>param1: #{param1}</p>
<p>param2: #{param2}</p>
<p>param3: #{param3}</p>

<c:forEach begin="1" end="3" var="idx">
    <p>#{requestScope['param' += idx]}</p>
</c:forEach>

See also:

  • JSTL in JSF2 Facelets... makes sense?

本文标签: parametersHow to dynamically access uiparam values in JSF FaceletsStack Overflow