0

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user2471366
  • 73
  • 12
  • Uh, where are you updating the dialog's content? I'm not seeing that in the code posted so far. If you aren't updating the dialog's content, then it won't be updated.. – BalusC Jul 08 '13 at 13:39
  • Opps. I thought that when the dialog box was open, the f:attribute would update automatically based on what item.item is at that point in time. What's the best way to do this? With an ajax request? – user2471366 Jul 08 '13 at 16:03
  • No... You just specify that the usual way in ``. – BalusC Jul 08 '13 at 16:06

1 Answers1

3

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • When I do this, I get an error: "Cannot find component with identifier "dialogId". Where am I supposed to set the dialogId? I've tried setting the id of p:dialog and f:attribute to "dialogId" with no avail. – user2471366 Jul 08 '13 at 20:14
  • It was just exemplary. If you already do not know how to reference components by client ID, head to this answer: http://stackoverflow.com/a/8644762/ – BalusC Jul 08 '13 at 22:04
  • Thanks! That cleared up a lot. I started using JSF fairly recently, and I had no idea that you couldn't just use the client ID directly. – user2471366 Jul 09 '13 at 15:52
  • 1
    JSF is easier to understand if you keep in mind that it's basically a HTML/CSS/JS code generator. If you understand basic HTML/CSS/JS, then JSF is in turn easier to understand. – BalusC Jul 09 '13 at 16:04