0

I have this code :

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

my problem is when I click commandLink "Créer un compte" dialog is shown and it disappears quickly.

joice
  • 53
  • 4
  • 11
  • 1
    This has been answered [here](http://stackoverflow.com/questions/13395844/open-pconfirmdialog-on-clicking-of-pcommandlink) – Csaba Jun 08 '13 at 15:32

2 Answers2

6

This happens because <h:commandLink> executes a submit on the form that will be send the data to the server, the server will process the request, the server will generate a response and send it to client, thus getting the refresh behavior in browser.

Easy fix (for this scenario), add return false; at the end of the onclick to stop the form submission.

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

As stated in BalusC comment, it would be easier to not have a <form> to begin with, so just using a plain <a>:

<a onclick="dlg3.show();">Créer un compte</a>
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
-1

You can also use <p:commandlink ...oncomplete="dlg3.show();" /> instead of <h:commandlink onclick =.... /> It will ensure setting values in backing bean

  • That has the same problem. Read the PF manual again, sine there is a solution, something with `type="button"` – Kukeltje Jul 31 '16 at 08:02