3

我创建了一个实现微调器的复合组件,我工作得很好,但是当我从 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>

坠毁

有人可以解释一下发生了什么吗?

4

2 回答 2

2

PrimeFaces ajax 组件只能与其他 Primefaces 组件一起使用。我不相信您可以将它作为这样的复合组件的 clientBehavior 插入并期望它能够工作。您将不得不使用f:ajax.

附带说明一下,从 PrimeFaces 3.0 开始,该p:spinner组件已被引入,因此您的复合组件虽然令人印象深刻,但实际上不再需要了。:)

于 2012-08-23T12:35:06.073 回答
1

正如@maple_shaft 所说,我无法将 p:ajax 传递给复合组件。Primefaces 有一个微调器组件,但不幸的是它仍然不好(不支持国际化并显示额外的十进制数字,例如 0.06666666669 而不是 0.07),我没有足够的时间等待更正。我需要在这个组件中使用 p:ajax 的情况很少见,通常只是为了获得像validationFailed 这样的参数。所以,我用一个丑陋的解决方法解决了这个问题:

<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);"/>
于 2012-08-23T18:18:47.913 回答