我创建了一个实现微调器的复合组件,我的工作非常好,但是当我从primefaces 2.2.1更改为primefaces 3.3.1时,当我尝试使用p:ajax而不是f:ajax时,组件崩溃了所有页面
以下是组件:
<c:interface>
<c:attribute name="value" required="true"/>
<c:attribute name="fator" required="false" default="1"/>
<c:attribute name="required" required="false" default="false"/>
<c:attribute name="requiredMessage" required="false" default=""/>
<c:attribute name="validatorMessage" required="false" default="Não é um número válido!"/>
<c:attribute name="disabled" required="false" default="false"/>
<c:attribute name="title" required="false" default=""/>
<c:attribute name="width" required="false" default="100"/>
<c:attribute name="dinheiro" required="false" default="false"/>
<c:attribute name="local" required="false" default="pt-BR"/>
<c:attribute name="imediato" required="false" default="false"/>
<c:attribute name="onchange" required="false" default=""/>
<c:attribute name="onkeyup" required="false" default=""/>
<c:attribute name="max" required="false" default="-1"/>
<c:attribute name="min" required="false" default="0"/>
<c:attribute name="parametro" required="false" default=""/>
<c:attribute name="casasDecimais" required="false" default="2"/>
<c:attribute name="valueChangeListener" method-signature="void method(javax.faces.event.ValueChangeEvent)"
targets="spinner"/>
<c:attribute name="rendered" required="false" default="true"/>
<c:editableValueHolder name="#{cc.id}" targets="spinner"/>
<c:clientBehavior name="blur" default="true" event="blur"
targets="spinner"/>
<c:clientBehavior name="change" default="true" event="change"
targets="spinner"/>
</c:interface>
<c:implementation>
<h:outputStylesheet library="css" name="hrgiSpinner.css" target="head"/>
<h:outputScript library="js" name="jquery.formatCurrency-1.4.0.min.js" target="head"/>
<h:outputScript library="js" name="jquery.formatCurrency.pt-BR.js" target="head"/>
<h:outputScript library="js" name="hrgiSpinner.js" target="head"/>
<h:panelGroup layout="block" styleClass="hrgi-spinner" rendered="#{cc.attrs.rendered}">
<p:inputText id="spinner" value="#{cc.attrs.value}"
styleClass="hrgi-spinner-input editableField" disabled="#{cc.attrs.disabled}"
onchange="formatar(this,'#{cc.attrs.fator}','#{cc.attrs.local}','#{cc.attrs.dinheiro}','#{cc.attrs.max}','#{cc.attrs.min}','#{cc.attrs.casasDecimais}'); #{cc.attrs.onchange}"
required="#{cc.attrs.required}" requiredMessage="#{cc.attrs.requiredMessage}"
validatorMessage="#{cc.attrs.validatorMessage}" onkeyup="#{cc.attrs.onkeyup}"
title="#{cc.attrs.title}" immediate="#{cc.attrs.imediato}" style="width: #{cc.attrs.width}px;"
converterMessage="O valor informado não é um número.">
<f:attribute name="objeto" value="#{cc.attrs.parametro}"/>
</p:inputText>
<h:panelGroup layout="block" styleClass="hrgi-spinner-painel-botoes"
rendered="#{not cc.attrs.disabled}">
<div onmousedown="incrementar('#{cc.clientId}'+':spinner','#{cc.attrs.fator}','#{cc.attrs.local}','#{cc.attrs.dinheiro}','#{cc.attrs.max}','#{cc.attrs.min}','#{cc.attrs.casasDecimais}');"
class="hrgi-spinner-botao hrgi-spinner-botao-alto clearfix"/>
<div onmousedown="decrementar('#{cc.clientId}'+':spinner','#{cc.attrs.fator}','#{cc.attrs.local}','#{cc.attrs.dinheiro}','#{cc.attrs.max}','#{cc.attrs.min}','#{cc.attrs.casasDecimais}');"
class="hrgi-spinner-botao hrgi-spinner-botao-baixo clearfix"/>
</h:panelGroup>
<h:panelGroup layout="block"
styleClass="hrgi-spinner-painel-botoes hrgi-spinner-painel-botoes-desabilitados"
rendered="#{cc.attrs.disabled}">
<div class="hrgi-spinner-botao hrgi-spinner-botao-alto clearfix"/>
<div class="hrgi-spinner-botao hrgi-spinner-botao-baixo clearfix"/>
</h:panelGroup>
</h:panelGroup>
</c:implementation>
当我使用f:ajax:
<hrgi:spinner id="aliquotaIpiItem" rendered="#{itemEmbrulhado.carregado}"
disabled="#{not modeloPopupLancamentoNF.lancamentoDanfe}"
value="#{controladorTabelaDinamicaItemNF.recuperarIPI(itemEmbrulhado).aliquota}"
dinheiro="false" fator="0.01" local="pt-BR" min="0.00" width="70"
parametro="#{itemEmbrulhado}">
<f:ajax render=":lancamentoNF:abasNF:painelItensNF :alerta" execute="@form"
event="blur" listener="#{controladorPopupLancamentoNF.validarAliquotasItemEAdicionar}"
onevent="definirFoco"/>
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="#{cc.attrs.local}"
for="aliquotaIpiItem"/>
</hrgi:spinner>
当我使用p:ajax:
时<hrgi:spinner id="aliquotaIpiItem" rendered="#{itemEmbrulhado.carregado}"
disabled="#{not modeloPopupLancamentoNF.lancamentoDanfe}"
value="#{controladorTabelaDinamicaItemNF.recuperarIPI(itemEmbrulhado).aliquota}"
dinheiro="false" fator="0.01" local="pt-BR" min="0.00" width="70"
parametro="#{itemEmbrulhado}">
<p:ajax update=":lancamentoNF:abasNF:painelItensNF :alerta" process="@form"
event="blur" listener="#{controladorPopupLancamentoNF.validarAliquotasItemEAdicionar(itemEmbrulhado)}"
onsuccess="salvarFoco();" oncomplete="carregarFoco(); exibirPopupAlerta(xhr, status, args);"/>
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="#{cc.attrs.local}"
for="aliquotaIpiItem"/>
</hrgi:spinner>
有人能解释我发生了什么吗?
答案 0 :(得分:2)
PrimeFaces ajax组件只能与其他Primefaces组件一起使用。我不相信你可以将它作为像这样的复合组件的clientBehavior插入并期望它能够工作。您必须使用f:ajax
。
另一方面,从PrimeFaces 3.0开始,已经引入了p:spinner
组件,因此您的复合组件虽然令人印象深刻,但实际上已不再需要了。 :)
答案 1 :(得分:1)
正如@maple_shaft所说,我无法将p:ajax传递给复合组件。 Primefaces有一个微调器组件,但不幸的是它仍然不好(不支持国际化并显示额外的十进制数字,如0.06666666669而不是0.07),我没有足够的时间等待更正。 rares是我需要使用p:ajax与这个组件的情况,通常只是为了得到像validationFailed这样的args。所以,我用一个丑陋的解决方法解决了这个问题:
<hrgi:spinner id="aliquotaIpiItem" rendered="#{itemEmbrulhado.carregado}"
disabled="#{not modeloPopupLancamentoNF.lancamentoDanfe}"
value="#{controladorTabelaDinamicaItemNF.recuperarIPI(itemEmbrulhado).aliquota}"
dinheiro="false" fator="0.01" local="pt-BR" min="0.00" width="70"
onblur="adicionarItemNF();">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="#{cc.attrs.local}"
for="aliquotaIpiItem"/>
</hrgi:spinner>
<p:remoteCommand name="adicionarItemNF" update=":lancamentoNF:abasNF:painelItensNF :alerta" process="@form"
action="#{controladorPopupLancamentoNF.validarAliquotasItemEAdicionar(itemEmbrulhado)}" global="false"
onsuccess="salvarFoco();" oncomplete="carregarFoco(); exibirPopupAlerta(xhr, status, args);"/>