2

如何使成功消息显示出来?我有以下代码,但只出现警告消息。我必须进行哪些更改才能在我的成功页面中显示成功消息?

用户bean.java

  public String Login() throws Exception {
     String status = "failure"; 
    current=userBo.validateUser(getLogin(),getPass()); 
    if(current!=null){ exist=false; status = "success"; 
    String message = "submitted successfully !!"; 
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(message)); }
     exist=true; return status; }

登录.xhtml:

<f:view>
                    <h:form>
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <th>Username</th>
                                <td><h:inputText value="#{user.login}"
                                        styleClass="login-inp" /></td>
                            </tr>
                            <tr>
                                <th>Password</th>
                                <td><h:inputSecret value="#{user.pass}"
                                        onfocus="this.value=''" styleClass="login-inp" /></td>
                            </tr>
                            <tr>
                                <th></th>
                                <!-- <td><input type="button" class="submit-login"  /> -->
                                <td><h:commandButton action="#{user.checkUser}"  styleClass="submit-login" />
                                <h:messages  globalOnly="true"  />
                                </td>
                            </tr>
                        </table>
                    </h:form>
                </f:view>

成功.xhtml:

 <h:form>
    <h:body>

        <h1>heyyyy ,y sucseded  !!!</h1> <br/><br/>

        <h:commandLink  action ="#{user.logout}" > disconnect </h:commandLink>

    </h:body>
    </h:form>

警告信息 :

Infos: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=null[severity=(INFO 0), summary=(submitted successfully !!), detail=(submitted successfully !!)]
4

2 回答 2

2

<h:messages globalOnly="true" />被放置在错误的视图中。您将其放置在 中login.xhtml,但您正在导航到success.xhtml成功而不是返回到login.xhtml。如果你把<h:messages globalOnly="true" />in success.xhtml,那么它将以你期望的方式显示。

于 2012-09-05T13:14:43.993 回答
0

在您的操作方法上,即 action="#{user.checkUser}" 返回一个字符串,该字符串将决定使用您的 faces-config.xml 文件显示哪个页面。

例如。<导航规则>

        < from-view-id>*< /from-view-id>                
            < navigation-case>
               <from-outcome>ReturnedString</from-outcome>
               <to-view-id>success.xhtml(path of your file)</to-view-id>
            <redirect/>
        </navigation-case>
    < /navigation-rule>

这肯定会奏效。

于 2012-09-05T13:27:43.623 回答