Sajad
Sajad

Reputation: 2363

p:dataTable no records found

I have a data table in a dialog.

When user clicked on the Detail link, the dialog with a data table should be displayed.

Here is the code:

<h:form>
   <h:dataTable value="#{messageBean.messagesList}" var="msg">

<h:column>
     <f:facet name="header">Detail</f:facet>
     <p:commandLink action="#{messageBean.fetchSelectedMessage(msg.msgId)}" value="#{msg.summary}" />
        </h:column>
   </h:dataTable>
</h:form>

And this is messageBean.fetchSelectedMessag(...):

@ManagedBean
@SessionScoped
public class MessageBean {

...
private List<Messages> messagesList;
private List<Messages> selectedMessage;

public void fetchSelectedMessage(String msgId) {
    String sql = "SELECT * FROM messages WHERE msgId=?";
    selectedMessage = jdbcTemplate.query(sql, new Object[]{msgId}, new BeanPropertyRowMapper<Messages>(Messages.class));
    System.out.println("fetched selected message== " + selectedMessage); //correct
    //open dialog sucucessfully
    RequestContext context = RequestContext.getCurrentInstance();
    context.execute("PF('dlg1').show();");
}
//getter/setters

Then this dialog should opens (and open successfully, but displays nothing)

<p:dialog widgetVar="dlg1" modal="true" height="100">
    <p:dataTable var="msg1" value="#{messageBean.selectedMessage}">

        <p:column headerText="id">
            <h:outputText value="#{msg1.msgId}"/>
        </p:column>

        <p:column headerText="to person">
            <h:outputText value="#{msg1.toPerson}"/>
        </p:column>

    </p:dataTable>

</p:dialog>

Why the dialog data table can't show any thing?

the selectedMessage is a list of messages type and is not null.

Upvotes: 0

Views: 758

Answers (1)

Sajad
Sajad

Reputation: 2363

You need to update the dialog after each click:

<p:commandLink ... process="@this" update=":msgForm:dlgPanel" onComplete="PF('dlg1').show();"/>

Upvotes: 1

Related Questions