0

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.

DavidS
  • 5,022
  • 2
  • 28
  • 55
Sajad
  • 2,273
  • 11
  • 49
  • 92
  • 1
    Usually the dialog has already been drawn on page load, it's just hidden, so you still need to AJAX update it if the model changes. Adding an `update` to your commandLink might fix it. – DavidS Jul 04 '15 at 15:54
  • @DavidS Like this? `update="PF('dlg1').show();"` – Sajad Jul 04 '15 at 15:58
  • 1
    No, the update attribute must match a component ID on the page. You will want to learn more about this, as it's an essential part of using AJAX with JSF. Here is an example http://stackoverflow.com/questions/14227681/primefaces-ajax-update-of-panel-from-another-form. – DavidS Jul 04 '15 at 16:02
  • And BalusC wrote a good guide here http://stackoverflow.com/questions/8634156/cannot-find-component-with-expression-foo-referenced-from-bar-fajax-con. – DavidS Jul 04 '15 at 16:04
  • @DavidS is right. Start with some basic jsf/ajax tutorials before diving into the deep – Kukeltje Jul 05 '15 at 08:47

1 Answers1

1

You need to update the dialog after each click:

<p:commandLink ... process="@this" update=":msgForm:dlgPanel" onComplete="PF('dlg1').show();"/>
Sajad
  • 2,273
  • 11
  • 49
  • 92