从 2.2.1 升级后,我无法再在对话框组件内显示来自视图范围的支持 bean 的一些数据。对话框弹出,但来自 bean 的数据设置为空。
问题似乎是按钮的远程命令调用了一个 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>
包含 javascript 和对话框的 confirmOrder.xhtml:
<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 && 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 | 网络逻辑 10.3.3