joice
joice

Reputation: 53

primefaces dialog disappears after show up when click commandLink

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.

Upvotes: 0

Views: 4854

Answers (2)

Fahim Ashraf
Fahim Ashraf

Reputation: 1

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

Upvotes: -1

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85789

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>

Upvotes: 6

Related Questions