我有一个简单的表单,要求用户输入文本。然后,当用户单击链接时,将显示一个对话框,其中包含用户输入的值。我遇到的第一个问题是对话框没有显示。
另一个问题与更新有关。第一次显示表单时,HTML代码正确,且"#{dialogBean.location}
"当前值为空。
<form id="dialogForm" name="dialogForm" method="post" action="/tcmt-component/dialog.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="dialogForm" value="dialogForm">
<input type="hidden" autocomplete="off" value="-6424900608015567042:-9068630845666043913" id="javax.faces.ViewState" name="javax.faces.ViewState"></form>
与此同时,我检查Ajax调用的返回。#{dialogBean.location}
仍为空
<?xml version='1.0' encoding='UTF-8'?>
<partial-response><changes><update id="dialogForm:dialog"><![CDATA[<div id="dialogForm:dialog" style="display:none" title="Dialog">
Current Location:
我再次点击链接,这次#{dialogBean.location}
的值被设置为正确的值。
<?xml version='1.0' encoding='UTF-8'?>
<partial-response><changes><update id="dialogForm:dialog"><![CDATA[<div id="dialogForm:dialog" style="display:none" title="Dialog">
Current Location: MyLocation
Bean:
@ManagedBean
@SessionScoped
public class DialogBean implements Serializable {
private String location;
public void setLocation(String location) {
this.location = location;
}
public String getLocation() {
return location;
}
}
视图:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
</h:head>
<h:body>
<h:form id="initForm">
<h:inputText id="location" value="#{dialogBean.location}" />
<p:commandLink update="dialogForm:dialog" onclick="dlg.show()">
<h:outputText value="Show Dialog" />
</p:commandLink>
</h:form>
<h:form id="dialogForm">
<p:dialog id="dialog" header="Dialog" widgetVar="dlg" resizable="false">
Current Location: <h:outputText value="#{dialogBean.location}" />
<p:commandButton value="Close" oncomplete="dlg.hide();"/>
</p:dialog>
</h:form>
</h:body>
</html>
<<p> 解决方案/strong> 这似乎是一个更新对话框的primefaces问题。相反,我将对话框包装在一个面板中,更新工作:
<p:dialog header="Dialog" widgetVar="dlg" resizable="false">
<p:outputPanel id="dialogPanel">
Current Location: <h:outputText value="#{dialogBean.location}" />
<h:form id="dialogForm">
<p:commandButton value="Close" oncomplete="dlg.hide();"/>
</h:form>
</p:outputPanel>
</p:dialog>
<h:form id="initForm">
<h:inputText id="location" value="#{dialogBean.location}" />
<p:commandLink update="dialogPanel" onclick="dlg.show()">
<h:outputText value="Show Dialog" />
</p:commandLink>
</h:form>
尝试将对话框放在命令链接之前,如下所示:
<p:outputPanel id="panel">
<h:form id="dialogForm">
<p:dialog id="dialog" header="Dialog" widgetVar="dlg" resizable="false">
Current Location: <h:outputText value="#{dialogBean.location}" />
<p:commandButton value="Close" oncomplete="dlg.hide();"/>
</p:dialog>
</h:form>
</p:outputPanel>
<h:form id="initForm">
<h:inputText id="location" value="#{dialogBean.location}" />
<p:commandLink update="dialogForm:dialog" onclick="dlg.show()" update="panel">
<h:outputText value="Show Dialog" />
</p:commandLink>
</h:form>
另一个简单的解决方案是:如果你使用Primefaces 3.0(或更高版本),你可以为对话框添加动态属性,并将其设置为true。这是主面3.2的VDL动态模式允许对话框在显示之前获取内容,而不是在页面加载时获取内容,这有助于减少初始页面加载时间。默认为false
我最近几天一直有这个问题,在阅读了这篇文章之后,我只是通过从我的panelGrid|outputPanel
中删除'layout="block"'
来解决我的问题。我有update="pageContentPanel"
嵌入在我的CRUD表单页面,现在这个AJAX PPR工作得更好。我猜AJAX PPR(和PrimeFaces 3.0 M3)与span
标签比div
标签工作得更好。(
<ui:define name="pageContent">
<p:outputPanel id="pageContentPanel">
<p:outputPanel layout="block" rendered="#{pageNavigationController.isPageSelected('/pageContent_blank.xhtml')}">
<ui:include src="/pageContent_blank.xhtml"/>
</p:outputPanel>
<p:outputPanel layout="block" rendered="#{pageNavigationController.isPageSelected('/service/pf_Add.xhtml')}">
<ui:include src="/service/pf_Add.xhtml"/>
</p:outputPanel>
<p:outputPanel layout="block" rendered="#{pageNavigationController.isPageSelected('/service/pf_Browse.xhtml')}">
<ui:include src="/service/pf_Browse.xhtml"/>
</p:outputPanel>
<p:outputPanel layout="block" rendered="#{pageNavigationController.isPageSelected('/service/pf_Edit.xhtml')}">
<ui:include src="/service/pf_Edit.xhtml"/>
</p:outputPanel>
<p:outputPanel layout="block" rendered="#{pageNavigationController.isPageSelected('/service/pf_View.xhtml')}">
<ui:include src="/service/pf_View.xhtml"/>
</p:outputPanel>
</p:outputPanel>
</ui:define>