【问题标题】:primefaces dialog disappears after show up when click commandLink当单击 commandLink 时出现后,primefaces 对话框消失
【发布时间】:2013-06-08 15:20:14
【问题描述】:

我有这个代码:

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

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

【问题讨论】:

标签: jsf primefaces dialog


【解决方案1】:

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

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

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

正如 BalusC 评论中所述,没有&lt;form&gt; 开头会更容易,所以只需使用普通的&lt;a&gt;

<a onclick="dlg3.show();">Créer un compte</a>

【讨论】:

  • 或者只使用纯 HTML &lt;a&gt; 元素。然后你也可以摆脱整个表单。
【解决方案2】:

您也可以使用&lt;p:commandlink ...oncomplete="dlg3.show();" /&gt; 代替&lt;h:commandlink onclick =.... /&gt; 它将确保在 backing bean 中设置值

【讨论】:

  • 也有同样的问题。再次阅读PF手册,有一个解决方案,type="button"
猜你喜欢
  • 2013-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-19
  • 1970-01-01
  • 2019-05-15
  • 2016-04-24
  • 2016-10-25
相关资源
最近更新 更多