2011-12-30 72 views
0

我正在嘗試使用jsf進行登錄。 我想在用戶註冊時隱藏登錄面板。 我用jsf ajax做了這個。PrimeFaces Ajax

當我試圖用primefaces做到這一點。我失敗了。

我在jsf ajax中像這樣。

    <h:form id="register"> 
         <table style="width: 49%; margin-right: auto; margin-left: auto;"> 
          <tr> 
           <td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            All fields are required.</td> 
          </tr> 
          <tr> 
           <td class="style2" style="height: 51px">Username</td> 
           <td style="width: 17px; height: 51px;">:</td> 
           <td class="style3" style="height: 51px"><h:inputText 
             id="regusername" style="width:155px;height:24px;" 
             value="#{userRegister.regUser.username}"> 

            </h:inputText></td> 
          </tr> 
          <tr> 
           <td class="style2" style="height: 51px">Name</td> 
           <td style="width: 17px; height: 51px;">:</td> 
           <td class="style3" style="height: 51px"><h:inputText 
             id="regname" style="width:155px;height:24px;" 
             value="#{userRegister.regUser.name}"> 

            </h:inputText></td> 
          </tr> 
          <tr> 
           <td class="style2" style="height: 51px">Mail</td> 
           <td style="width: 17px; height: 51px;">:</td> 
           <td class="style3" style="height: 51px"><h:inputText 
             id="regmail" style="width:155px;height:24px;" 
             value="#{userRegister.regUser.mail}"> 

            </h:inputText></td> 
          </tr> 
          <tr> 
           <td class="style2" style="height: 51px">Password</td> 
           <td style="width: 17px; height: 51px;">:</td> 
           <td class="style3" style="height: 51px"> 



           <h:inputSecret 
             id="regpassword" style="width:155px;height:24px;" 
             value="#{userRegister.regUser.password}"> 

            </h:inputSecret></td> 
          </tr> 
          <tr> 
           <td>&nbsp;</td> 
           <td>&nbsp;</td> 
           <td class="style3"><h:commandButton 
             style="width:76px;height:26px" value="Clear" type="reset"> 

            </h:commandButton> &nbsp; <h:commandButton style="width:75px;height:26px" 
             value="Register" action="#{userRegister.register()}" 
             method="post"> 

             <f:ajax execute="regname regusername regpassword regmail" 
              render="registermessage" /> 

            </h:commandButton></td> 
          </tr> 
          <tr> 
           <td colspan="3"><h:outputText id="registermessage" 
             value="#{userRegister.message}"></h:outputText></td> 
          </tr> 
         </table> 
        </h:form> 

       </h:panelGroup> 
       <h:panelGroup rendered="#{userLogin.isLoggedin()== true}" 
        layout="block"> 
        You are already loggedin !!  
     </h:panelGroup> 

當我嘗試這個在這樣primefaces:

<p:panel id ="registerPanel" header="User Registration" align="center" 
     style="text-align:center;"> 
     <table style="width: auto; margin: auto;"> 
      <tr> 
       <td style="text-align: right;"><h:outputLabel for="regname" 
         value="Name Surname : * &nbsp;" /></td> 
       <td style="text-align: left"><p:inputText id="regname" 
         value="#{userRegister.regUser.name}" size="40" required="true" 
         label="Name and Surname"> 
         <f:validateLength minimum="2" /> 
        </p:inputText> <p:watermark for="regname" value="Name Surname" /></td> 
      </tr> 
      <tr> 
       <td style="text-align: right" colspan="2"><p:message 
         for="regname" /></td> 
      </tr> 

      <tr> 
       <td style="text-align: right;"><h:outputLabel 
         for="regusername" value="Username : * &nbsp;" /></td> 
       <td style="text-align: left"><p:inputText id="regusername" 
         value="#{userRegister.regUser.username}" size="40" 
         required="true" label="Username"> 
         <f:validateLength minimum="3" /> 
        </p:inputText> <p:watermark for="regusername" value="Username" /></td> 
      </tr> 
      <tr> 
       <td style="text-align: riht" colspan="2"><p:message 
         for="regusername" /></td> 
      </tr> 

      <tr> 
       <td style="text-align: right;"><h:outputLabel for="regmail" 
         value="E-Mail : * &nbsp;" /></td> 
       <td style="text-align: left"><p:inputText id="regmail" 
         value="#{userRegister.regUser.mail}" size="40" required="true" 
         label="Mail"> 
         <f:validateLength minimum="2" /> 
        </p:inputText> <p:watermark for="regmail" value="[email protected]" /></td> 
      </tr> 

      <tr> 
       <td style="text-align: right" colspan="2"><p:message 
         for="regmail" /></td> 
      </tr> 
      <tr> 
       <td style="text-align: right;"><h:outputLabel for="paswword" 
         value="Password : * &nbsp;" /></td> 
       <td style="text-align: left"><p:password id="regpassword" 
         value="#{userRegister.regUser.password}" size="40" 
         required="true" label="Password"> 
         <f:validateLength minimum="5" /> 
        </p:password> <p:watermark for="regpassword" value="Password" /></td> 
      </tr> 
      <tr> 
       <td style="text-align: left" colspan="2"><p:message 
         for="regpassword" /></td> 
      </tr> 
      <tr> 
       <td style="text-align: right" colspan="2"> 

       </td> 
      </tr> 
      <tr> 
       <td style="text-align: right" colspan="2"> 
       <p:commandButton value="Clear" image="ui-icon ui-icon-arrowrefresh-1-w" 
     type="reset"/> 
     &nbsp;&nbsp; 
     <p:commandButton value="Register" image="ui-icon ui-icon-disk" 
     action="#{userRegister.register()}" method="post"> 

     <f:ajax 
              render="registerpaneli" /> 

     </p:commandButton> 
       </td> 
      </tr> 

     </table> 

- >

</h:panelGroup> 

我registraion面板斜面隱伏。

什麼問題?

回答

3

取出

<p:commandButton ....> 
    <f:ajax render="what-ever"> 
</p:commandButton> 

通過

<p:commandButton update="what-ever" ../> 

此外,你可以閱讀Primefaces' Documentits demo

因爲在Primefaces中,大多數組件都與Ajax兼容,尤其是<p:commandButton/>,因爲它默認打開了Ajax。

1

在PrimeFaces中,<p:commandButton>已經具有內置的ajax功能。你不需要使用<f:ajax>。實際上,<f:ajax>不能與PrimeFaces一起使用。如果您確實需要使用它,則必須改用<p:ajax>

要解決你的問題,我想你應該改變你的按鈕,像這樣:

<p:commandButton value="Register" actionListener="#{userRegister.register}" update="registerPanel" />