【问题标题】:Simple for loop in composite component复合组件中的简单 for 循环
【发布时间】:2018-07-13 05:02:13
【问题描述】:

我想在复合组件中创建一个简单的 for 循环。 我有一个组件应该显示一个字符 n 次。这似乎是最简单的情况。我不确定我做错了什么。

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:composite="http://xmlns.jcp.org/jsf/composite"
                xmlns:c="http://java.sun.com/jsp/jstl/core">

    <composite:interface>
        <composite:attribute name="length" required="true" shortDescription="The length of the anonymized text"/>
    </composite:interface>

    <composite:implementation>
            <c:forEach begin="0" end="#{cc.attrs.length}">•</c:forEach>
    </composite:implementation>
</ui:composition>

这个错误: javax.faces.FacesException: Error Instantiating: com.sun.faces.facelets.tag.composite.ImplementationHandler

【问题讨论】:

    标签: jsf primefaces jsf-2.2 composite-component


    【解决方案1】:

    我设法通过在 java 中创建一个 util 类来实现这一点,该类创建一个空数组以使用 &lt;ui:repeat /&gt; 进行迭代

    查看:

    <ui:repeat value="#{util:createArray(cc.attrs.length)}" var="index">•</ui:repeat>
    

    实用程序类:

    public final class UIHelper {
        public static Object[] createArray(int size) {
            return new Object[size];
        }
    }
    

    标签库:

    <?xml version="1.0" encoding="UTF-8"?> <facelet-taglib
    ...
    <function>
        <function-name>createArray</function-name>
        <function-class>package.UIHelper</function-class>
        <function-signature>Object[] createArray(int)</function-signature>
    </function> </facelet-taglib>
    

    【讨论】:

      猜你喜欢
      • 2014-10-18
      • 1970-01-01
      • 2017-03-28
      • 2014-01-15
      • 2017-09-20
      • 1970-01-01
      • 1970-01-01
      • 2019-02-06
      相关资源
      最近更新 更多