在 JSF 中使用 JSTL 函数

发布于 2024-12-21 11:36:55 字数 938 浏览 1 评论 0原文

我想使用 JSF2 中包含的 JSTL 函数 这是我尝试过的,但条件总是评估为 false,我想我错过了一些东西:

<c:forEach items="#{myBean.toSendCheckBoxes}" var="entry" varStatus="loop">                             

               <input type="checkbox" name="myArray" value="#{entry.value}" />

               <c:choose>

                 <c:when test="#{fn:contains(entry.key,'g')}">
                   <ice:graphicImage url="/resources/images/image1.bmp" />
                   <b>#{entry.key}</b>                      
                 </c:when>

                 <c:otherwise>
                   <ice:graphicImage url="/resources/images/image2.bmp" />
                   <span>#{entry.key}</span>
                 </c:otherwise>



               </c:choose>

            </c:forEach>

如果有另一种 JSF 方法可以实现这一点,那么非常高兴提及它,提前致谢。

i want to use the JSTL function contains in JSF2
here's what i tried but the condition always evaluates to false, i think i am missing something:

<c:forEach items="#{myBean.toSendCheckBoxes}" var="entry" varStatus="loop">                             

               <input type="checkbox" name="myArray" value="#{entry.value}" />

               <c:choose>

                 <c:when test="#{fn:contains(entry.key,'g')}">
                   <ice:graphicImage url="/resources/images/image1.bmp" />
                   <b>#{entry.key}</b>                      
                 </c:when>

                 <c:otherwise>
                   <ice:graphicImage url="/resources/images/image2.bmp" />
                   <span>#{entry.key}</span>
                 </c:otherwise>



               </c:choose>

            </c:forEach>

if there's another JSF way to accomplish that, would be very nice to mention it, thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱人如己 2024-12-28 11:36:55

更 JSFish 的方法是

<ui:repeat value="#{myBean.toSendCheckBoxes}" var="entry" varStatus="loop">                             

  <input type="checkbox" name="myArray" value="#{entry.value}" />

  <ui:fragment rendered="#{fn:contains(entry.key,'g')}">
    <ice:graphicImage url="/resources/images/image1.bmp" />
    <b>#{entry.key}</b>                      
  </ui:fragment>

  <ui:fragment rendered="#{!fn:contains(entry.key,'g')}">
    <ice:graphicImage url="/resources/images/image2.bmp" />
    <span>#{entry.key}</span>
  </ui:fragment>

</ui:repeat>

或者甚至

<ui:repeat value="#{myBean.toSendCheckBoxes}" var="entry" varStatus="loop">                             

  <input type="checkbox" name="myArray" value="#{entry.value}" />

  <ice:graphicImage url="#{fn:contains(entry.key,'g') ? '/resources/images/image1.bmp' : '/resources/images/image2.bmp'}" />
  <span class="#{fn:contains(entry.key,'g') ? 'bold-style' : ''}">#{entry.key}</span>
</ui:repeat>

,但我希望你的病情能够得到正确的评估。

More JSFish way to do it would be

<ui:repeat value="#{myBean.toSendCheckBoxes}" var="entry" varStatus="loop">                             

  <input type="checkbox" name="myArray" value="#{entry.value}" />

  <ui:fragment rendered="#{fn:contains(entry.key,'g')}">
    <ice:graphicImage url="/resources/images/image1.bmp" />
    <b>#{entry.key}</b>                      
  </ui:fragment>

  <ui:fragment rendered="#{!fn:contains(entry.key,'g')}">
    <ice:graphicImage url="/resources/images/image2.bmp" />
    <span>#{entry.key}</span>
  </ui:fragment>

</ui:repeat>

or even

<ui:repeat value="#{myBean.toSendCheckBoxes}" var="entry" varStatus="loop">                             

  <input type="checkbox" name="myArray" value="#{entry.value}" />

  <ice:graphicImage url="#{fn:contains(entry.key,'g') ? '/resources/images/image1.bmp' : '/resources/images/image2.bmp'}" />
  <span class="#{fn:contains(entry.key,'g') ? 'bold-style' : ''}">#{entry.key}</span>
</ui:repeat>

but I would expect your condition to evaluate properly nevertheless.

冷…雨湿花 2024-12-28 11:36:55

我使用 t:dataList (myfaces tomahawk xmlns:t="http://myfaces.apache.org/tomahawk") 循环元素以生成正确的标识符, rendered 属性用于列表中元素的不同显示。

<t:dataList layout="simple" value="#{myBean.toSendCheckBoxes}" var="entry">                             
    <input type="checkbox" name="myArray" value="#{entry.value}" />
        <h:panelGroup rendered="#{fn:contains(entry.key,'g')}">
            <ice:graphicImage url="/resources/images/image1.bmp" />
            <b>#{entry.key}</b>                      
        </h:panelGroup>
        <h:panelGroup rendered="#{not fn:contains(entry.key,'g')}">
            <ice:graphicImage url="/resources/images/image2.bmp" />
            <span>#{entry.key}</span>
        </h:panelGroup>
</t:dataList>

我在 ui:repeat 中遇到动态元素渲染(显示/隐藏行)的问题,因此我不得不使用 t:dataList 来代替。

I use t:dataList (myfaces tomahawk xmlns:t="http://myfaces.apache.org/tomahawk") for looping over elements to have correct identifier generation and rendered attribute for different displaying of elements in the list.

<t:dataList layout="simple" value="#{myBean.toSendCheckBoxes}" var="entry">                             
    <input type="checkbox" name="myArray" value="#{entry.value}" />
        <h:panelGroup rendered="#{fn:contains(entry.key,'g')}">
            <ice:graphicImage url="/resources/images/image1.bmp" />
            <b>#{entry.key}</b>                      
        </h:panelGroup>
        <h:panelGroup rendered="#{not fn:contains(entry.key,'g')}">
            <ice:graphicImage url="/resources/images/image2.bmp" />
            <span>#{entry.key}</span>
        </h:panelGroup>
</t:dataList>

I've had issues with dynamic element rendering (show/hide rows) within ui:repeat, so I had to use t:dataList instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文