I have a <h:dataTable> which has a <p:commandLink> within it.
I need to fetch some data from the database when <p:commandLink>
is clicked and display it within a pop-up for which I am using a <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>
I need to capture the data of the row which is clicked and get data from the database. My bean and controller classes are as follows:
@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);
}
}
The <p:dialog> includes a file called sample.xhtml which has references
to SampleClass. So I used rendered property in <p:dialog> to avoid
NullPointer Exception on loading my xhtml page.Also, sample of type SampleClass is inserted into the
sessionMap only after the controller method getData() is executed on clicking
the <p:commandLink>.
The problem is that the pop-up never gets displayed even after the method
getData() is executed and sample is inserted into the SessionMap.
I have used update=:form:dialog to update the dialog after the <p:commandLink>
is clicked. But it seems that the rendered property of the dialog never gets
updated. So i cannot see the <p:dialog>.
Am I missing something?