2012-05-24 31 views
1

我在tomcat 6上有一個帶有mojara EL 2.2的JSF 2.0,並在開發過程中讓它工作了一段時間。 我最近添加了一個用於登錄(基本東西)的命令按鈕的表單,它在doLogin操作中檢查託管bean中的用戶名和密碼。基本的JSF 2和tomcat 6的動作結果導航isue

public String doLogin(){ 
     FacesMessage message = null; 
     if((username.equals("user"))&&(password.equals("pass"))) 
       return "testpage.xhtml"; 
     else 
      message = new FacesMessage("Invalid username or password"); 

     FacesContext.getCurrentInstance().addMessage(null, message); 

     return null; 
    } 

的問題是,它通過doLogin後返回「testpage.xhtml」同一頁面displayed.Even雖然我有所有的XHTML在的WebContent的根文件。

在Tomcat中的控制檯我得到:

The ELResolvers for JSF were not registered with the JSP container. 

使用EL 2.2做工精細傳遞參數。

我在Facelets中使用JSF。可以給我一些建議

回答

0

隱式導航是自JSF 2.0以來引入的。在舊的JSF 1.x中,您需要在faces-config.xml中定義<navigation-rule>或在URL上明確調用ExternalContext#redirect()

此問題表明您的JSF 2.0 Web應用程序在JSF 1.x後備模式下運行。確保您的faces-config.xml已聲明符合JSF 2.0規範版本。

<?xml version="1.0" encoding="UTF-8"?> 

<faces-config 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" 
    version="2.0"> 

    <!-- Config here. --> 

</faces-config> 

EL解析器警告與此無關。這是由Tomcat 6使用Glassfish的EL 2.2引起的,您將無法在.jsp頁面中使用EL(如果您僅使用Facelets,這應該不成問題)。如果您想擺脫此警告,請使用JBoss EL代替Glassfish EL。 JBoss EL是一個增強的EL 2.1實現,而Glassfish EL是EL 2.2實現。

0

我不確定,B'coz我沒有看到其他代碼。

如果您沒有在faces-config.xml中設置特定的導航規則。 $ SUB-directory1中/ testpage.xhtml的

默認值是$ SUB-directory1中/ testpage

0

在翻譯成隱式導航JSF 2.0 testpage圖。請在這裏更改您的代碼,

public String doLogin(){ 
     FacesMessage message = null; 
     if((username.equals("user"))&&(password.equals("pass"))) { 
      return "testpage"; 
     } else { 
      message = new FacesMessage("Invalid username or password"); 
      FacesContext.getCurrentInstance().addMessage(null, message); 
     } 
    return null; 
}