簡體   English   中英

primefaces commandbutton ajax 以非ajax方式提交作品

[英]primefaces commandbutton ajax submit works as a non-ajax submit

我正在使用 primefaces 3.5,我想使用 p:commandButton 和 ajax 更新 object 的 de 值,但是當我單擊 p:commandButton 時,表單完全作為非 ajax 提交提交。 我嘗試使用 immediate=true, ajax="true" (但我讀到此選項是默認選項) partial-submit="true" 但什么也沒有,按鈕刷新所有頁面而不僅僅是 asignarUA 組件。

注意:這是一個 liferay (6.2 CE) portlet。

這是代碼的一部分:

<html xmlns="http://www.w3.org/1999/xhtml"  
xmlns:h="http://java.sun.com/jsf/html"  
xmlns:f="http://java.sun.com/jsf/core"  
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<h:form>
    <p:commandButton onclick="asignarUADlg.show()" update=":asignarUA" title="Asignar" value="Asignar">
    <f:setPropertyActionListener value="#{solicitud }" target="#{mailboxView.solicitud}"/>
    </p:commandButton>                                                
</h:form>


<p:dialog id="asignarUA" widgetVar="asignarUADlg" modal="true" header="Asignar Unidades Administrativas" width="530" showEffect="fade" hideEffect="fade">
    <h:form enctype="multipart/form-data">
        <h:outputLabel for="dependencia" value="Dependencia: " />
        <h:outputText value="#{mailboxView.solicitud.nombreDependencia}" rendered="#{not empty mailboxView.solicitud}" />
        <p:separator />

        <p:commandButton value="Enviar" ajax="false" actionListener="#{mailboxView.asignar}" update=":messages2"/>
        <p:commandButton value="Cancelar" onclick="asignarUADlg.hide()" type="button"/>
    </h:form>
</p:dialog>
</h:body>
</html>

您的第一個p:commandButton顯示對話框,然后立即將其再次隱藏。 這也導致頁面閃爍,我認為您已將此閃爍誤認為是非ajax提交。 當您單擊p:commandButton ,將調用dialog.show()並顯示該對話框。 然后運行update=":dialogId"代碼*,並將ajax請求發送到服務器以重新呈現對話框。 由於服務器不知道客戶端上已調用dialog.show() ,因此服務器認為對話框仍應處於默認狀態:隱藏。 因此,返回的部分響應會將對話框重置為初始狀態,並再次隱藏對話框。

解決方案是更新對話框的內容,而不是整個對話框。 對於您的特定示例,您應該在第二個h:form添加一個id ,並通過Asignar按鈕對其進行更新:

<h:form>
    <p:commandButton onclick="asignarUADlg.show()" update=":dialogContent"
    title="Asignar" value="Asignar">

<!-- ... -->

<p:dialog id="asignarUA" widgetVar="asignarUADlg" modal="true"
    header="Asignar Unidades Administrativas" width="530" showEffect="fade" hideEffect="fade">
    <h:form id="dialogContent" enctype="multipart/form-data">

<!-- ... -->

* update屬性使p:commandButton呈現代碼以在其onclick屬性中發送ajax請求。 因此,ajax代碼實際上是在dialog.show()之后被調用。

嘗試

<p:commandButton onclick="asignarUADlg.show()" update=":asignarUA:dialogContent"
title="Asignar" value="Asignar">

我必須將PrimeFaces版本升級到5.3,並且可以正常工作。 我唯一需要更改的是process屬性:

<p:commandButton process="@this :dialogContent" update=":dialogContent" onclick="PF('asignarUADlg').show()" title="Asignar" value="Asignar">
    <f:setPropertyActionListener value="#{solicitud }" target="#{mailboxView.solicitud}"/>
</p:commandButton>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM