2010-11-29 29 views
0

私たちは最初のJSFプロジェクトに取り組んでおり、いくつか問題があります。私たちは、ログイン機能を作っている、と私たちは、ログインボタンを押したときに、それはスロー:ナビゲーション・ケースがJSFで機能しない

  • 例外:IllegalArgumentException - nullの ソース

  • 場合NullPointerException - サーブレットの のServlet.serviceは()[ に直面しますパス とコンテキストでサーブレット] [/ JSF-空白]は例外

を投げたあなたはそれが働いていない理由を任意のアイデアを持っていますか?私たちに教えてください。

public class User 
{ 
    private long id; 
    private String username; 
    private String password; 

    public User() 
    { 
    } 

    public User(String username, String password) 
    { 
     this.username = username; 
     this.password = password; 
    } 

    public User(long id, String username, String password) 
    { 
     super(); 
     this.id = id; 
     this.username = username; 
     this.password = password; 
    } 

    public String getNextPage() 
    { 

     return "failure"; //or "admin" or "client" 
    } 

    public long getId() 
    { 
     return id; 
    } 

    public void setId(long id) 
    { 
     this.id = id; 
    } 

    public String getUsername() 
    { 
     return username; 
    } 

    public String getPassword() 
    { 
     return password; 
    } 

    public void setUsername(String username) 
    { 
     this.username = username; 
    } 

    public void setPassword(String password) 
    { 
     this.password = password; 
    } 
} 

当社login.jspページ:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%> 
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Login</title> 
</head> 
<body> 
<f:view> 
    <h:form> 
     Username: <h:inputText value="#{userBean.username}"></h:inputText> 
     <br /> 
     Password: <h:inputText value="#{userBean.password}"></h:inputText> 
     <br /> 
     <h:commandButton value="Login" action="#{userBean.getNextPage}" ></h:commandButton> 
    </h:form> 
</f:view> 
</body> 
</html> 

当社のfaces-config.xmlに:

<?xml version="1.0"?> 
<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"> 

    <managed-bean> 
     <managed-bean-name>userBean</managed-bean-name> 
     <managed-bean-class>data_layer.model.User</managed-bean-class> 
     <managed-bean-scope>session</managed-bean-scope> 
    </managed-bean> 

    <navigation-rule> 
     <from-view-id>/login.jsp</from-view-id> 
     <navigation-case> 
      <from-action>#{userBean.getNextPage}</from-action> 
      <from-outcome>admin</from-outcome> 
      <to-view-id>/admin.jsp</to-view-id> 
     </navigation-case> 
     <navigation-case> 
      <from-action>#{userBean.getNextPage}</from-action> 
      <from-outcome>failure</from-outcome> 
      <to-view-id>/failure.jsp</to-view-id> 
     </navigation-case> 
     <navigation-case> 
      <from-action>#{userBean.getNextPage}</from-action> 
      <from-outcome>client</from-outcome> 
      <to-view-id>/client.jsp</to-view-id> 
     </navigation-case> 
    </navigation-rule> 
</faces-config> 

当社のweb.xml:

ここ

は、ユーザー豆出ています

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    version="2.5"> 
    <servlet> 
     <servlet-name>Faces Servlet</servlet-name> 
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Faces Servlet</servlet-name> 
     <url-pattern>*.jsf</url-pattern> 
    </servlet-mapping> 

    <context-param> 
     <param-name>javax.faces.CONFIG_FILES</param-name> 
     <param-value>/WEB-INF/faces-config.xml</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.faces.PROJECT_STAGE</param-name> 
     <param-value>Development</param-value> 
    </context-param> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
     <!-- <welcome-file>index.html</welcome-file> --> 
    </welcome-file-list> 
</web-app> 

そして、我々のディレクトリ構造は次のとおりです。あなたは、JSF 1.xおよび2.xのJSFアプローチを alt text

答えて

3

インターミキシングをしています。 IDEがJSF 2.xのものを自動生成している間にJSF 1.xを対象とした古い本/チュートリアルから読んでいるのでしょうか?

JSF 2.0ではデフォルトでJSPがサポートされていません。従来のJSPは、より優れたテンプレート機能を提供するFaceletsによって引き継がれています。ビンテージJSPを再度使用するようにJSF 2.0を設定することはできますが、そうしないことを強くお勧めします。むしろlogin.xhtmllogin.jspを書き換える:

あなたは現在も get rid全体 faces-config.xmlのを持つことができるようJSF 2.0での問題、とは無関係の
<!DOCTYPE html> 
<html lang="en" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:ui="http://java.sun.com/jsf/facelets"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <title>Login</title> 
    </head> 
    <body> 
    <h:form> 
     Username: <h:inputText value="#{userBean.username}" /> 
     <br /> 
     Password: <h:inputText value="#{userBean.password}" /> 
     <br /> 
     <h:commandButton value="Login" action="#{userBean.getNextPage}" /> 
    </h:form> 
</body> 


Userクラスに次のjavax.faces.bean注釈を追加します。

@ManagedBean(name="userBean") 
@RequestScoped 
public class User { 
    // ... 
} 

新しい暗黙のナビゲーションを使用すると、結果はビューのファイル名として扱われ、デフォルトでとなります。あなたは既にそれをうまくやったので、ナビゲーションルールはまったく必要ありません。

関連する問題