Syd*_*ney 9 jsf primefaces jsf-2
我有一个简单的表单,要求用户输入文本.然后,当用户单击该链接时,将显示一个对话框,其中包含用户输入的值.我遇到的第一个问题是对话框没有显示.
另一个问题涉及更新.首次显示表单时,HTML代码是正确的,当前值为#{dialogBean.location}空.
然后我点击链接,HTML代码是"错误的".这就是为什么我猜它没有显示:
<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>
Run Code Online (Sandbox Code Playgroud)
同时,我检查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:
Run Code Online (Sandbox Code Playgroud)
我再次点击链接,这次将值#{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
Run Code Online (Sandbox Code Playgroud)
豆子:
@ManagedBean
@SessionScoped
public class DialogBean implements Serializable {
private String location;
public void setLocation(String location) {
this.location = location;
}
public String getLocation() {
return location;
}
}
Run Code Online (Sandbox Code Playgroud)
风景:
<?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>
Run Code Online (Sandbox Code Playgroud)
解
似乎更新对话框是一个主要问题.相反,我将对话框包装在一个面板中,更新工作:
<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>
Run Code Online (Sandbox Code Playgroud)
尝试将对话框放在commandLink之前,如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
另一个简单的解决方案是:如果您使用 Primefaces 3.0(或更高版本),您可以将 dymaic 属性添加到对话框中。将其设置为 true。这是primefaces 3.2 的VDL 动态模式允许对话框在显示之前而不是在页面加载时获取其内容,这有助于减少初始页面加载时间。默认为假。
| 归档时间: |
|
| 查看次数: |
24794 次 |
| 最近记录: |