0

I'm currently working on a CRUD form and is now working on the last part which should be the most easiest - delete. But I want to show a dialog before the user can do the actual deletion. And this is where I'm having problem with Primefaces 3.4. For some reason I cannot set the action in the button inside the p:dialog, ajax=false failed. So here's what I did:

<p:column headerText="#{msgs['action.delete']}"
                    styleClass="a-center">
    <p:commandButton icon="ui-icon-trash"
        oncomplete="confirmation.show()">
        <f:setPropertyActionListener
            target="#{marketingCodeBean.marketingCode}" value="#{code}"></f:setPropertyActionListener>
    </p:commandButton>
</p:column>

The Dialog:

<p:confirmDialog id="confirmDialog"
                message="#{msgs['message.marketingCode.confirmDelete']}"
                header="#{msgs['common.confirmDelete']}" severity="alert"
                widgetVar="confirmation">
    <p:commandButton id="confirm" value="#{msgs['common.yes']}"
        oncomplete="confirmation.hide()" update=":form:mktgCodeTable"
        actionListener="#{marketingCodeBean.remove}" />
    <p:commandButton id="decline" value="#{msgs['common.no']}"
        onclick="confirmation.hide()" type="button" />
</p:confirmDialog>

I'm aware that the actionListener should not be use for business action, but I can't think of a workaround given the datatable and the dialog. Any idea on how I can make ajax=false in p:commandButton inside p:confirmDialog?

czetsuya
  • 4,143
  • 13
  • 48
  • 91

1 Answers1

1

Once rendered, the dialog's HTML output is by some onload JavaScript relocated to end of HTML <body> in order to achieve the best cross-browser compatible overlay/positioning. However, this thus means that if it was placed inside a <form>, it would not be in a <form> anymore and synchronous (non-ajax) requests would then not work anymore. This is not exactly an action vs actionListener issue.

The <p:dialog> (and <p:confirmDialog> as you seem to be actually using) should have its own <h:form> component.

<h:form>
    <p:dataTable>
        ...
    </p:dataTable>
</h:form>
...
<p:confirmDialog>
    <h:form>
        ...
    </h:form>
</p:confirmDialog>
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • You're right I forgot to create a separate form for the p:confirmDialog and included it in the main form. Thanks again. But I wonder why it won't work with a single form? – czetsuya Jan 07 '13 at 02:58
  • Because the HTML output of the dialog is by JavaScript relocated to end of HTML ``, causing it not be inside any `
    ` anymore.
    – BalusC Jan 07 '13 at 10:23