不幸的是,如果你试图动态创建标签,那么primefaces accordionPanel在版本2.2.1中效果不佳。这是我的情况,我需要在用户点击添加图标时创建手风琴,如果他点击x图标则删除。没问题,我已经创建了自己的复合组件,就像你在这里看到的那样:
<c:interface>
<c:attribute name="titulo" default="" required="false" />
<c:attribute name="renderizar" default="true" required="false" />
<c:attribute name="width" required="false" default="300"/>
<c:facet name="extra" required="false" />
</c:interface>
<c:implementation>
<h:outputStylesheet library="css" name="hrgiAccordion.css" target="head" />
<h:outputStylesheet library="css" name="clearfix.css" target="head" />
<h:outputScript library="js" name="hrgiAccordion.js" target="head" />
<h:panelGroup layout="block" rendered="#{cc.attrs.renderizar}"
styleClass="hrgi-accordion clearfix" style="width: #{cc.attrs.width}px;">
<div class="hrgi-cabecalho-accordion clearfix"
onclick="abrirAccordion(this)">
<h:outputLabel value="#{cc.attrs.titulo}" />
<c:renderFacet name="extra" required="false"/>
</div>
<h:panelGroup layout="block" class="hrgi-conteudo-accordion clearfix">
<c:insertChildren />
</h:panelGroup>
</h:panelGroup>
</c:implementation>
它工作正常,但我有一些细节需求...手风琴选项卡的内容是一些选择和一个带有inputField和一个微调器(由我再次创建)的动态表,你可以在这里看到用户界面:< / p>
当用户在微调器中插入值时,标签“Total das parcelas”应该更新,但只有当对话框只有一个折叠式选项卡时它才会更新!看看生成的HTML代码,我看到不同手风琴标签中的微调器是相等的!可能这就是我无法更新值的原因。以下是此对话框的代码:
<ui:composition template="../templates/popupSubmit.xhtml">
<ui:param name="titulo" value="#{vendaMsg['popup.forma_pagamento.titulo']}"/>
<ui:param name="popup" value="#{modeloPopupFormaPagamento}"/>
<ui:param name="controladorPopup" value="#{controladorPopupFormaPagamento}"/>
<ui:define name="cabecalho">
<h:panelGroup id="cabecalhoValores" binding="#{cabecalhoValores}" layout="block">
<h:outputLabel value="#{vendaMsg['popup.forma_pagamento.total_prevenda']}" />
<h:outputLabel value="#{preVendaBean.valorLiquido}">
<f:convertNumber currencySymbol="R$" maxFractionDigits="2"
minFractionDigits="2" type="currency" currencyCode="BRL"/>
</h:outputLabel>
<hrgi:separador/>
<h:outputLabel value="#{vendaMsg['popup.forma_pagamento.total_parcelas']}" />
<h:outputLabel value="#{controladorPopupFormaPagamento.calcularTotalParcelas()}">
<f:convertNumber currencySymbol="R$" maxFractionDigits="2"
minFractionDigits="2" type="currency" currencyCode="BRL"/>
</h:outputLabel>
</h:panelGroup>
</ui:define>
<ui:define name="conteudo">
<h:panelGroup layout="block" styleClass="clearfix hrgi-div-form">
<h:panelGroup id="painelFormasDePagamento" binding="#{painelFormasDePagamento}" layout="block">
<ui:repeat id="repeticao" var="formaPagamento" value="#{modeloPopupFormaPagamento.formasDePagamento}">
<hrgi:accordion titulo="#{vendaMsg['popup.forma_pagamento.aba_acordeon.titulo']}" width="380">
<f:facet name="extra">
<p:commandLink action="#{controladorPopupFormaPagamento.removerForma(formaPagamento)}"
update=":#{painelFormasDePagamento.clientId}" global="false">
<h:graphicImage library="img" name="remover.png"/>
</p:commandLink>
</f:facet>
<h:panelGroup layout="block" class="clearfix">
<h:panelGroup id="painelSelecaoForma" layout="block">
<h:outputLabel value="#{vendaMsg['popup.forma_pagamento.forma_pagamento']}"/>
<h:selectOneMenu value="#{formaPagamento.idFormaPagamento}" valueChangeListener="#{controladorPopupFormaPagamento.processarMudancaFormaPagamento}">
<f:selectItems value="#{selectItemFormasPagamento.itens}"/>
<f:attribute value="#{formaPagamento}" name="formaPagamento"/>
<f:ajax event="change" render="painelSelecaoForma painelParcelasFormaPagamento" execute="painelSelecaoForma"/>
</h:selectOneMenu>
<h:outputLabel value="#{vendaMsg['popup.forma_pagamento.plano_pagamento']}" />
<h:selectOneMenu value="#{formaPagamento.idPlanoPagamento}" valueChangeListener="#{controladorPopupFormaPagamento.processarMudancaPlanoPagamento}">
<f:selectItems value="#{controladorPopupFormaPagamento.recuperarCarregador(formaPagamento).itens}"/>
<f:attribute value="#{formaPagamento}" name="formaPagamento"/>
<f:ajax event="change" render="painelParcelasFormaPagamento"/>
</h:selectOneMenu>
</h:panelGroup>
<h:panelGroup id="painelParcelasFormaPagamento" layout="block">
<p:dataTable id="tabela" value="#{formaPagamento.parcelas}" var="parcela"
emptyMessage="#{msgGerais['gerais.sem_dados']}"
scrollable="#{formaPagamento.parcelas.size()>2}"
height="76">
<p:column headerText="#{vendaMsg['popup.forma_pagamento.tabela.numero_parcela']}">
<h:outputText value="#{formaPagamento.parcelas.indexOf(parcela)+1}"/>
</p:column>
<p:column headerText="#{vendaMsg['popup.forma_pagamento.tabela.vencimento_parcela']}">
<hrgi:editableDate value="#{parcela.dataVencimento}" editable="true"/>
</p:column>
<p:column headerText="#{vendaMsg['popup.forma_pagamento.tabela.valor_parcela']}">
<hrgi:spinner id="valor"
dinheiro="true" fator="0.01" local="pt-BR"
value="#{parcela.valor}">
<f:ajax event="change" execute="@form"
render=":#{cabecalhoValores.clientId}"/>
<f:convertNumber currencySymbol="R$" maxFractionDigits="2"
minFractionDigits="2" type="currency" currencyCode="BRL"
for="input"/>
</hrgi:spinner>
</p:column>
</p:dataTable>
</h:panelGroup>
</h:panelGroup>
</hrgi:accordion>
</ui:repeat>
</h:panelGroup>
<p:commandLink immediate="true" action="#{controladorPopupFormaPagamento.adicionarForma}"
update="painelFormasDePagamento" global="false">
<h:graphicImage library="img" name="adicionar_48.png"/>
</p:commandLink>
</h:panelGroup>
</ui:define>
</ui:composition>
在这张图片中你可以看到发生了什么,在primefaces数据表中的组件id没有附加ui:repeat index:
我该如何解决这个问题?
答案 0 :(得分:7)
这是一个Mojarra错误,当您在UIData
内嵌套UIRepeat
组件时会显示该错误。我曾经把它报告为issue 1830。它到目前为止还没有修复,它在MyFaces中按预期工作。 UIRepeat
在Mojarra中以多种方式被打破,但在MyFaces中完美无缺。
如果您希望/需要坚持使用Mojarra,因此无法通过MyFaces替换它,请考虑将UIRepeat
替换为基于UIData
的完整组件。例如,Tomahawk's <t:dataList>
不会生成任何其他标记,并且是一个很好的<ui:repeat>
替代品。或者您可以使用PrimeFaces'<p:dataList>
并使用一些CSS list-style-type: none
隐藏列表项目符号。
更新:报告的问题已在Mojarra 2.1.12和2.2.0-m06中修复。所以,如果可以,只需升级到至少那个版本。