2012-01-01 80 views
0

我想在JSF 2.0中成功登錄時顯示導航欄。這是我的login.xhtml文件的一部分。 導航欄是Primefaces組件,您可以看到here如何在成功登錄時顯示navigationBar(primefaces)(JSF 2.0)

正如您所看到的,導航欄可以通過觸發方法topBar.show() 來顯示。但是,如何在成功登錄後觸發它?

<h:form> 
    <p:messages showDetail="false" /> 
    <h:panelGrid columns="2"> 
     <h:outputLabel for="pseudo" value="#{i18n.Pseudo}" /> 
     <h:inputText id="pseudo" label="#{i18n.Pseudo}" required="true" value="#{loginController.grimpeur.login}" 
     maxlength="128" /> 
     <h:outputLabel for="password" value="#{i18n.Password}:" /> 
     <h:inputSecret id="password" value="#{loginController.grimpeur.password}" /> 
    </h:panelGrid> 
    <h:commandButton type="submit" action="#{loginController.processLogin}" value="#{i18n.Ok}" /> 
    <h:commandButton type="button" value="#{i18n.Password_forgotten}" onclick="dlg.show();" /> 
    </h:form> 

    <p:notificationBar position="top" effect="slide" widgetVar="loginBar" styleClass="top"> 
    <h:graphicImage value="#{loginController.grimpeur.login}/#{loginController.grimpeur.avatar}" width="80" height="70" 
     title="avatar" /> 
    <h:outputFormat id="logged_in_msg" value="#{i18n.Welcome_logged_in_user}" style="color:#FFCC00;font-size:36px;"> 
     <f:param value="#{loginController.grimpeur.login}" /> 
     <f:param value="#{i18n.Climbing}" /> 
    </h:outputFormat> 
    </p:notificationBar> 

回答

3

我認爲你可以用PrimeFaces v3.0.RC2的RequestContext來實現它。它應該是這樣的:

<p:notificationBar widgetVar="bar"> 
    <h:outputText value="You have successfully log in!" /> 
</p:notificationBar> 

<p:commandButton type="submit" actionListener="#{loginController.processLogin}" 
       value="#{i18n.Ok}" /> 

@ManagedBean 
@RequestScoped 
public class LoginController { 
    public void processLogin(ActionEvent actionEvent) { 
     boolean successful; 
     // process your login here 

     if (successful) { 
     RequestContext context = RequestContext.getCurrentInstance(); 
     context.execute("bar.show();"); 
     } 
    } 
} 
+0

感謝隊友,那做了工作;) – paissad 2012-01-01 12:02:42

+0

不客氣! :P – 2012-01-01 12:39:57