【发布时间】:2013-10-11 12:48:47
【问题描述】:
我有一个<h:dataTable>,其中有一个<p:commandLink>。
我需要在<p:commandLink> 时从数据库中获取一些数据
单击并在我使用<p:dialog>的弹出窗口中显示它。
<h:form id="form">
<h:dataTable width="80%" value="#{controller.items}" var="a" binding="#{bean.table}"
rendered="#{not empty controller.items}">
<h:column>
<h:outputText value="#{a.date}" />
</h:column>
<h:column>
<h:outputText value="#{a.name}" />
</h:column>
<h:column>
<p:commandLink value="View" action="#{controller.getData()}"
update=":form:dialog" oncomplete="w_dialog.show();return false;">
</p:commandLink>
</h:column>
</h:dataTable>
<p:dialog header="Test" widgetVar="w_dialog" width="600px" height="500px"
id="dialog" modal="true" draggable="true" appendToBody="true" rendered="#{sessionScope.sample ne null}">
<ui:include src="sample.xhtml"/>
</p:dialog>
</h:form>
我需要捕获被点击的行的数据并从数据库中获取数据。 我的bean和控制器类如下:
@Named
@SessionScoped
public class Bean implements Serializable
{
private HtmlDataTable table;
// getters and setters
}
@Named
@SessionScoped
public class Controller implements Serializable
{
@Inject
private Bean bean;
public void getData(){
bean.getTable().getRowData();
SampleClass sample=new SampleClass();
// fetches data from database and populates it within sample instance
FacesContext context = FacesContext.getCurrentInstance();
context.getExternalContext().getSessionMap()
.put("sample", sample);
}
}
<p:dialog> 包含一个名为 sample.xhtml 的文件,其中包含引用
到SampleClass。所以我在<p:dialog> 中使用了rendered 属性来避免
NullPointer Exception 在加载我的 xhtml 页面时。此外,SampleClass 类型的 sample 被插入到
sessionMap 仅在控制器方法getData() 执行后单击
<p:commandLink>。
问题是即使在方法之后弹出窗口也不会显示
getData() 被执行,sample 被插入到 SessionMap 中。
我使用update=:form:dialog 更新<p:commandLink> 之后的对话框
被点击。但似乎对话框的 rendered 属性永远不会得到
更新。所以我看不到<p:dialog>。
我错过了什么吗?
【问题讨论】:
标签: jsf-2 primefaces dialog