0

我有一个删除确认对话框:

  <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>

您会注意到deleteActionConfirmed按钮和deleteActionConfirmedLink链接具有完全相同的操作、流程、更新和完成属性。但是,链接按预期工作,按钮什么也不做。查看生成的标记:

<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>

您可以看到没有为按钮生成 onclick,其中有链接。我错过了什么还是这是primefaces中的错误?如果是错误,除了使用带有样式的链接使它们看起来像按钮之外,还有其他解决方法吗?

我在 tomcat 6.0.32(servlet 2.5,el 2.1)上使用 mojarra 2.1.14 和 primefaces 3.4.2。

4

1 回答 1

3

啊……简单的错误。的 type 属性p:commandButton决定了行为。看来,通过设置type='button'我已经把它变成了(取自primefaces用户指南):

按按钮

按钮用于执行自定义 javascript 而不会导致 ajax/非 ajax 请求。创建一个按钮集类型为“按钮”。

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

切换类型提交解决了这个问题。经验教训...如果使用按钮,type='button'会导致组件忽略任何服务器端action

于 2013-01-04T19:29:22.057 回答