0

I have a delete confirmation dialog:

  <p:confirmDialog id="deleteConfirmDialog"
    header="#{i18n['confirm-deletion']}"
    widgetVar="pnp_delete_confirmDialog" closeable="false"
    appendToBody="true">
    <f:facet name="message">
      <h:outputFormat id="deleteConfirmMessage"
        value="#{i18n['confirm-subscription-deletion']}">
        <f:param value="#{subscriptions.deleteSelected.title}" />
      </h:outputFormat>
    </f:facet>
    <h:form id="pnpConfirmDeleteForm">
      <p:commandButton id="deleteActionConfirmed"
        action="#{subscriptions.delete}" value="#{i18n['delete']}"
        type="button" process="@this" update=":pnpEditForm :pnpExistingForm"
        oncomplete="pnp_delete_confirmDialog.hide()" />
      <p:commandLink id="deleteActionConfirmedLink"
        action="#{subscriptions.delete}" process="@this"
        update=":pnpEditForm :pnpExistingForm"
        oncomplete="pnp_delete_confirmDialog.hide()">#{i18n['delete']}</p:commandLink>
      <p:commandButton id="deleteActionCancelled" value="#{i18n['cancel']}"
        type="button" onclick="pnp_delete_confirmDialog.hide()" />
    </h:form>
  </p:confirmDialog>

You will notice that the deleteActionConfirmed button and the deleteActionConfirmedLink link have the exact same action, process, update, and oncomplete attributes. However, the link works as expected and the button does nothing. Looking at the generated markup:

<form enctype="application/x-www-form-urlencoded"
  action="/primefaces-quickstart/xhtml/pnp-configuration.xhtml" method="post"
  name="pnpConfirmDeleteForm" id="pnpConfirmDeleteForm">
  <input type="hidden" value="pnpConfirmDeleteForm" name="pnpConfirmDeleteForm">
  <button type="button"
    class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
    name="pnpConfirmDeleteForm:deleteActionConfirmed"
    id="pnpConfirmDeleteForm:deleteActionConfirmed" role="button"
    aria-disabled="false">
    <span class="ui-button-text">Delete</span>
  </button>
  <a
    onclick="PrimeFaces.ab({source:'pnpConfirmDeleteForm:deleteActionConfirmedLink',process:'pnpConfirmDeleteForm:deleteActionConfirmedLink',update:'pnpEditForm pnpExistingForm',oncomplete:function(xhr,status,args){pnp_delete_confirmDialog.hide();}});return false;"
    class="ui-commandlink" href="#"
    id="pnpConfirmDeleteForm:deleteActionConfirmedLink">Delete</a>
  <button type="button" onclick="pnp_delete_confirmDialog.hide();"
    class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
    name="pnpConfirmDeleteForm:deleteActionCancelled"
    id="pnpConfirmDeleteForm:deleteActionCancelled" role="button"
    aria-disabled="false">
    <span class="ui-button-text">Cancel</span>
  </button>
  <input type="hidden" autocomplete="off"
    value="7076449462381240234:-2976764560029615800" id="javax.faces.ViewState"
    name="javax.faces.ViewState">
</form>

You can see that there is no onclick generated for the button, where there is for the link. Am I missing something or is this a bug in primefaces? If a bug, is there a workaround other than using links with styles to make them look like buttons?

I am using mojarra 2.1.14 with primefaces 3.4.2 on tomcat 6.0.32 (servlet 2.5, el 2.1).

Lucas
  • 11,997
  • 7
  • 62
  • 114

1 Answers1

3

ARGH... Simple mistake. The type attribute of the p:commandButton determines the behavior. It appears that by setting type='button' I have turned it into a (taken from the primefaces user guide):

Push Buttons

Push buttons are used to execute custom javascript without causing an ajax/non-ajax request. To create a push button set type as "button".

<p:commandButton type="button" value="Alert" onclick="alert(‘Prime’)" />

Switching type to submit fixed this issue. Lesson learned... If using buttons, type='button' causes the component to ignore any server side action.

Lucas
  • 11,997
  • 7
  • 62
  • 114
  • 1
    Or just remove the `type` attribute. It defaults to the right one already. – BalusC Jan 04 '13 at 19:56
  • @BalusC, that is actually what I did. Thanks for the input. Just seems weird that the `action` attribute gets ignored if `type='button'`. Would be nice if it either detected that action was present and automatically changed type to submit, or logged a warning or threw an exception indicating that its not gonna do what you are trying to do... – Lucas Jan 04 '13 at 20:04
  • Report to PF guys if necessary. – BalusC Jan 04 '13 at 20:06