当前位置: 首页 > 知识库问答 >
问题:

java.lang.IllegalArgumentException具有primefaces dataTable的jsf复合组件

严修诚
2023-03-14

葡萄牙语:java.lang.IllegalArgumentException jsf composite componente composto jsf com dataTable do primefaces

tabela-padrao.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:cc="http://xmlns.jcp.org/jsf/composite"
  xmlns:c="http://java.sun.com/jsp/jstl/core"
  xmlns:p="http://primefaces.org/ui"
  xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:h="http://xmlns.jcp.org/jsf/html">

<!-- INTERFACE -->
<cc:interface>
    <cc:attribute name="uniqueId" required="true" />
    <cc:attribute name="value" required="true" />
    <cc:attribute name="var" required="true" />
    <cc:attribute name="selection" required="true" />
    <cc:attribute name="exportedFileName" required="true" />
    <cc:attribute name="renderedTable" default="true"/>
    <cc:attribute name="primaryKey" required="true"/>
    <cc:clientBehavior name="customRowSelectEvent" targets="#{cc.attrs.uniqueId}" event="rowSelect" />
    <cc:clientBehavior name="customRowUnselectEvent" targets="#{cc.attrs.uniqueId}" event="rowUnselect" />
</cc:interface>

<!-- IMPLEMENTATION -->
<cc:implementation>
    <p:dataTable value="#{cc.attrs.value}" 
                 id="#{cc.attrs.uniqueId}"
                 scrollable="true"
                 scrollWidth="100%"
                 var="#{cc.attrs.var}"
                 rendered="#{cc.attrs.renderedTable}"
                 selection="#{cc.attrs.selection}"
                 rowKey="#{cc.attrs.primaryKey}"                                             
                 selectionMode="single"
                 paginator="true"
                 rowsPerPageTemplate="15,30,45"
                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} {Exporters}"
                 emptyMessage="#{bundle.tabela_nenhum_registro_encontrado}">
        <cc:insertChildren/>
        <f:facet name="{Exporters}">
            <h:commandLink style="padding: 5px 5px 5px 5px ;" title="Converter para Excel" >                                            
                <h:outputText  styleClass="fa fa-file-excel-o Fs20"/>
                <p:dataExporter type="xls" target="#{cc.attrs.uniqueId}" fileName="#{cc.attrs.exportedFileName}" />
            </h:commandLink>
            <h:commandLink style="padding: 5px 5px 5px 5px ;" title="Converter para PDF" >
                <h:outputText  styleClass="fa fa-file-pdf-o Fs20"/>
                <p:dataExporter type="pdf" target="#{cc.attrs.uniqueId}" fileName="#{cc.attrs.exportedFileName}"/>
            </h:commandLink>
        </f:facet>
    </p:dataTable> 
</cc:implementation>

使用组件/Usando o组件

<h:form id="tabela-municipio">
<ezcomp:tabela-padrao value="#{municipioMB.listaMunicipios}"
                      uniqueId="id-tabela-municipio"
                      var="mun" 
                      primaryKey="#{mun.id}"
                      selection="#{municipioMB.municipio}"
                      exportedFileName="municipios">
    <p:ajax event="customRowSelectEvent" listener="#{municipioMB.onRowSelect}" update="@(form[id*='frm-municipio']),@(form[id*='tabela-municipio'])" />
    <p:ajax event="customRowUnselectEvent" listener="#{municipioMB.onRowUnselect}" update="@(form[id*='frm-municipio']),@(form[id*='tabela-municipio'])" />
    <p:column headerText="Pais" width="300" filterBy="#{mun.estado.pais.nome}" filterMatchMode="contains">
        <h:outputText value="#{mun.estado.pais.nome}"/>
    </p:column>
    <p:column headerText="Estado" width="300" filterBy="#{mun.estado.sigla} - #{mun.estado.nome}" filterMatchMode="contains">
        <h:outputText value="#{mun.estado.sigla} - #{mun.estado.nome}"/>
    </p:column>
    <p:column headerText="Município" filterBy="#{mun.nome}" filterMatchMode="contains">
        <h:outputText value="#{mun.nome}"/>
    </p:column>
</ezcomp:tabela-padrao>

我有一个例外/Ocorreu esta Exceção!

葡萄牙人:Oque estou fazendo de errado?

共有1个答案

夏侯旻
2023-03-14

uidata:

public void setValueExpression(String name, ValueExpression binding) {

    if ("value".equals(name)) {
        this.model = null;
    } else if ("var".equals(name) || "rowIndex".equals(name)) {
        throw new IllegalArgumentException();
    }
    super.setValueExpression(name, binding);

}

var不能是ValueExpression。我建议只在组件中硬编码一些静态var值。组件的用户在定义列时只需引用这个硬编码值。但是,如果您想嵌套组件,这将是一个问题。

 类似资料:
  • 主要内容:实例JSF通过Facelets提供复合组件(有点类似于)的概念。复合组件是一种特殊类型的模板,它充当应用程序中的一个组成部分。 复合组件由标记标签和其他现有组件组成。 这个可重复使用的用户创建的组件具有定制的定义功能,并且可以像任何其他组件一样具有连接到它的验证器,转换器和监听器。 包含标记标签和其他组件的任何XHTML页面都可以转换为复合组件。 以下表格包含复合标签以及说明 - 标签 功能 它用于声

  • 问题内容: 我有一个看起来像这样的复合组件: 我希望能够添加一个可选的“侦听器”属性,如果定义了该属性,则会将事件侦听器添加到我的f:ajax中,但是我在弄清楚如何完成此操作时遇到了麻烦。任何帮助,将不胜感激。 问题答案: 您需要指定标签的属性,以便将属性值视为方法表达式。您可以使用JSTL视图构建时间标记来有条件地添加标记。 (因为EL不能正常工作,所以会将属性作为值表达式隐式评估) 然后,您可

  • 所以,问题是当我试图通过转换器!这是枚举转换器(使用@FacesConverter(value=“TipoCampoConverter”)注释扩展EnumConverter) 错误为:javax.el.elException:无法将类java.lang.String类型的tipoCampoConverter转换为接口javax.faces.convert.Converter **编辑:

  • 我有两张阵列图。 有没有办法用流来完成这个任务? 或者我必须通过映射迭代?

  • 问题内容: 我收到此错误: 我敢肯定,我确切知道是什么原因造成的,但是我不知道如何解决它。 我的应用程序从数据库中加载用户朋友。当用户至少有1个朋友可以放入列表视图时,就可以了。当用户是全新用户并且还没有朋友时,该应用程序将崩溃,因为listview的计数为0。 这仅仅是错误处理的情况吗? 如果我没有发布所有必要的相关代码,请告诉我! 这是我的适配器: 问题答案: 我认为您错过了ViewTypeC

  • 如何将两个堆数组合并成一个平衡的堆数组,同时保持线性复杂度?我读过的很多关于堆合并的材料都需要O(nlogn)。