【问题标题】:Error when creating a DataScroller inside Composite Component在复合组件中创建 DataScroller 时出错
【发布时间】:2015-03-05 14:39:24
【问题描述】:

我有一个复合组件,里面有一个 dataScroller(战斧)。在我的 xhtml 中,我尝试使用此组件,但收到错误消息:

java.lang.IllegalArgumentException: 找不到属性 dataScroller@for = 'myTable' 引用的 UIData

组件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:composite="http://java.sun.com/jsf/composite"
    xmlns:t="http://myfaces.apache.org/tomahawk">
<composite:interface>
    <composite:attribute name="for" targets="scroll"></composite:attribute>
    <composite:attribute name="paginatorMaxPages" />
</composite:interface>

<h:head>
</h:head>
<h:body>
    <composite:implementation>

        <div class="paginacao">
            <t:dataScroller id="scroll" for="#{cc.attrs.for}"
                styleClass="paginador" renderFacetsIfSinglePage="false"
                pageIndexVar="numeroPagina" pageCountVar="quantidadePaginas"
                rowsCountVar="quantidadeRegistros" paginator="true"
                paginatorMaxPages="#{cc.attrs.paginatorMaxPages}"
                paginatorTableClass="paginasPaginador"
                paginatorActiveColumnClass="negrito">

                <f:facet name="first">#{labels['paginacao.primeira']}</f:facet>
                <f:facet name="previous">#{labels['paginacao.anterior']}</f:facet>
                <f:facet name="next">#{labels['paginacao.proxima']}</f:facet>
                <f:facet name="last">#{labels['paginacao.ultima']}</f:facet>
            </t:dataScroller>
        </div>

    </composite:implementation>
</h:body>
</html>

我的数据表:

<h:form>
 ...
    <t:dataTable id="myTable" var="item" value="#{mBean.lista}">
 ...
    </t:dataTable>
 ...
</h:form>       

<param:parametrosScroll id="dataScroller" for="myTable" paginatorMaxPages="5" />

【问题讨论】:

    标签: jsf jsf-2 composite-component


    【解决方案1】:

    为确保同一视图中多个实例的可重用性,复合组件本质上是命名容器,如&lt;h:form&gt;&lt;h:dataTable&gt; 等。在您的具体情况下,将在for="myTable" 中搜索相对客户端 ID &lt;cc:implementation&gt; 的上下文,但没有这样的组件。相反,它位于组合之外,在另一个由&lt;h:form&gt; 表示的命名容器中。

    你有两个选择:

    1. 在给 &lt;h:form&gt; 一个固定 ID 后传递一个绝对客户端 ID。

      for=":myForm:myTable"
      
    2. Use a tagfile instead of a composite.

    【讨论】:

    • 我使用了一个标签文件。谢谢。
    猜你喜欢
    • 2017-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多