【问题标题】:onsuccess of remoteCommand not working properly after upgrade to Primefaces 3.5升级到 Primefaces 3.5 后远程命令无法正常工作
【发布时间】:2013-03-08 12:26:16
【问题描述】:

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

问题似乎是按钮的远程命令调用了一个 javascript,该 javascript 再次调用了对话框小部件上的 show 方法。渲染响应阶段在整个过程中被调用两次(恢复视图阶段只被调用一次)。第一次使用正确的值,第二次使用空值。

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

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

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

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

我有点不情愿删除 javascript。这是以前同事的代码,我在应用程序中找不到任何设置了javascript的数据参数的东西。我有点不确定原因是否代表我缺乏理解或可疑的代码。警报(数据。文本);返回未定义。

代码:

包含远程命令的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 |莫哈拉 2.1.19 | WebLogic 10.3.3

【问题讨论】:

  • 从这里的 onsuccess 方法返回 truefalse 来做什么?
  • 删除退货解决了这个问题。谢谢。
  • 我会添加一个答案。

标签: javascript primefaces


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-20
    • 1970-01-01
    • 2015-11-03
    • 2020-08-20
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多