单击 commandLink 时,primefaces 对话框出现后消失

joi*_*ice 0 jsf dialog primefaces

我有这个代码:

<h:form>
        <h:commandLink value="Créer un compte" onclick="dlg3.show();"/>
</h:form>

<p:dialog id="modalDialoog" widgetVar="dlg3" draggable="false" resizable="false" dynamic="true" header="Inscription">
<center>
<p:panel id="xyzBody">
<h:form id="inscri-f">
        <h:panelGrid id="loginPan" columns="2" bgcolor="White">

         <h:outputText value="Nom d'utilisateur :" />
         <p:inputText id="username" value="#{demandeBean.login}"></p:inputText>

         <h:outputText value="Mot de passe :" />
         <p:password id="pwd" value="#{demandeBean.pwd}"/>

         <h:commandButton value="Envoyer demande" update=":inscri-f:cr" 
                 actionListener="#{demandeBean.envoi_dde}"></h:commandButton>

         <h:commandButton value="Retour" action="page1?faces-redirect=true"></h:commandButton>

          <p:outputPanel id="cr"> 
            <h:outputText rendered="#{demandeBean.saved}" value="#{demandeBean.message}"/>
          </p:outputPanel>
                </h:panelGrid>
       </h:form>
       </p:panel>
       </center>
       </p:dialog>
Run Code Online (Sandbox Code Playgroud)

我的问题是当我单击 commandLink 时显示“Créer un compte”对话框并且它很快消失。

Lui*_*oza 6

发生这种情况是因为<h:commandLink>在将数据发送到服务器的表单上执行提交,服务器将处理请求,服务器将生成响应并将其发送给客户端,从而在浏览器中获得刷新行为。

简单修复(对于这种情况),return false;在末尾添加onclick以停止form提交。

<h:commandLink value="Créer un compte" onclick="dlg3.show(); return false;"/>
Run Code Online (Sandbox Code Playgroud)

正如 BalusC 评论中所述<form>,开始时没有 a 会更容易,所以只需使用普通的<a>

<a onclick="dlg3.show();">Créer un compte</a>
Run Code Online (Sandbox Code Playgroud)