我有一个<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. 所以我使用rendered属性<p:dialog>来避免
加载我的NullPointer Exceptionxhtml 页面。此外,只有在单击.sampleSampleClassgetData()<p:commandLink>
getData()问题是即使在方法执行并sample插入到 SessionMap之后,弹出窗口也永远不会显示
。
单击后,我习惯于update=:form:dialog更新对话框。<p:commandLink>但似乎rendered对话框的属性永远不会更新。所以我看不到<p:dialog>.
我错过了什么吗?