Search code examples
jsfjsf-2primefacesdialogmaster-detail

Dialog not updating after populating model in action method


I am using a primefaces dialog box. I have a list of items, and whenever I choose an item, I want the dialog box to display that item name. However, this is not happening. Rather than displaying the item name, the dialog is not displaying any name at all. I've posted my code below.

       <h:form>
         <h:dataTable binding="#{table}" value="#{item.itemList}" >
          <h:column>
            <h:link value="#{item.itemList[table.rowIndex]}" outcome="item">
              <f:param name="itemName" value="#{item.itemList[table.rowIndex]}" />
            </h:link>
          </h:column>
          <h:column>
            <p:commandButton action="#{item.setItem(item.itemList[table.rowIndex])}" id="showDialogButton" 
                             type="link" value="Delete" onclick="dlg.show()" />
          </h:column>
        </h:dataTable>
        <br />
        <p:dialog header="Item" widgetVar="dlg" resizable="false">
          <!-- I've also tried Item: #{item.item} -->
          <p>Item: <f:attribute name="contentId" value="#{item.item}"/> </p>
          <p:commandButton id="submitButton" value="Yes" action=
              "#{item.deleteItem}" oncomplete="dlg.hide();">
          </p:commandButton>
          <p:commandButton id="cancelButton" value="Cancel" oncomplete="dlg.hide();" />
        </p:dialog>

      </h:form>

My getters and setters are just generic getters and setters.


Solution

  • You forgot to update the dialog before opening.

    <p:commandButton ... update="dialogId" />
    

    I also suggest to use oncomplete instead of onclick to open the dialog.

    See also: