升级到Primefaces 3.5后,remoteCommand无法正常工作

时间:2013-03-08 12:26:16

标签: javascript primefaces

从2.2.1升级后,我无法再从对话框组件中的视图范围的支持bean中显示某些数据。弹出对话框,但bean中的数据设置为null。

问题似乎是按钮的remotecommand调用javascript,再次调用对话框小部件上的show方法。渲染响应阶段被调用两次直到进程(恢复视图阶段仅被调用一次)。第一次使用正确的值,第二次使用空值。

如果我更改onsucess属性以直接显示对话框:

<p:remoteCommand name="lazyload" onsuccess="confirmdialog.show();"
update=":confirm"  > 

对话框正确显示值。如果我改为使用onsuccess属性中的handleConfirm脚本并注释掉“return true;”从javascript对话框也显示值。渲染阶段现在只调用一次。

关于为什么会引发额外渲染阶段的任何想法都将受到高度赞赏。

我有点不愿意删除javascript。这是前同事的代码,我在应用程序中找不到javascript的data参数设置。我有点不确定是因为缺乏对我的理解还是愚蠢的代码。警报(data.text);返回undefined。

代码:

包含远程命令的BuyProduct.xhtml:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:fn="http://java.sun.com/jsp/jstl/functions"
    xmlns:comp="http://java.sun.com/jsf/composite/components">


    <ui:include src="/confirmOrder.xhtml"/>

    <h:form>
        <p:commandButton disabled="#{productsearch.hasCP == false}" 
        onclick="if(canhide == false) {return false;} if(submitelement!=this||cansubmit==false) { cansubmit = false; submitelement=this; lazyload(); return false;} cansubmit = false; submitelement=null; canhide=false; loading.show(); return true;"
            ajax="false" value="${msgs.order}"
            actionListener="#{cp.PerformSearch}"
            action="/services/cPReply.xhtml">
            <f:setPropertyActionListener value="#{confirmorder.targetGateway}" target="#{cp.gateway}" />
            <f:setPropertyActionListener value="#{productsearch.code}" target="#{cp.code}" />
            <f:setPropertyActionListener value="#{productsearch.registerId}" target="#{cp.registerId}" />
        </p:commandButton>
        <p:remoteCommand name="lazyload" onsuccess="return handleConfirm(data);" update=":confirm"  >  
                <f:setPropertyActionListener value="#{productsearch.cPGW.gateway_id}" target="#{confirmorder.gatewayId}" />
                <f:setPropertyActionListener value="CP" target="#{confirmorder.serviceName}" />

        </p:remoteCommand>

confirmOrder.xhtml包含javascript和对话框:

<ui:composition 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:c="http://java.sun.com/jsp/jstl/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:fn="http://java.sun.com/jsp/jstl/functions">

    <script>
        var cansubmit = false;
        var submitelement = null;

        function handleConfirm(data)
        {
            if(data.getElementsByTagName("error") != null &amp;&amp; data.getElementsByTagName("error")[0] != null) {
                sessiontimeout.show();
                return false;
            }
            else {

                    confirmdialog.show();
            }

            return true;
        }

    </script>


    <p:dialog header="${msgs.buyProducts}" widgetVar="confirmdialog" id="confirmdialogiden"
        modal="true" resizable="false" width="700" dynamic="true">
        <h:panelGrid id="confirm">
            <f:view beforePhase="#{confirmorder.beforePhase}" afterPhase="#{confirmorder.afterPhase}">
            <ui:debug hotkey="x"></ui:debug>
            <h:panelGrid id="noProductSelected" rendered="#{confirmorder.size==false}">
                ${msgs.noProductSelected}
                </h:panelGrid>
            <h:panelGrid id="productSelected" columns="2" rules="cols" rendered="#{confirmorder.size}" >
                    <h:panelGrid width="400" id="productSelectedSub">

                        <b>${msgs.products}</b>

                        <p:dataList value="#{confirmorder.products}" var="car">
                #{car.product_description}, #{car.price_nok}  
                        </p:dataList>

                        <p:separator /> 
                        <b>${msgs.amount} </b>
                        <h:outputText id="total" value="#{confirmorder.sum} " />
                    </h:panelGrid>

            </h:panelGrid>
        </h:panelGrid>
      </:dialog>

Primefaces 3.5 | Mojarra 2.1.19 | Weblogic 10.3.3

1 个答案:

答案 0 :(得分:0)

在这种情况下,您应该从return中删除onsuccess个值。返回false将取消默认DOM更新过程,因此我认为这是您的问题。