Dialog not updating after populating model in action method

十年热恋 提交于 2019-12-02 16:57:02

问题


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.


回答1:


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:

  • Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
  • How to show details of current row from p:dataTable in a p:dialog and update after save
  • Primefaces p:dialog doesn't always show up if update="dlg" in commandButton


来源:https://stackoverflow.com/questions/17527697/dialog-not-updating-after-populating-model-in-action-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!