2017-03-21 107 views
0

我正在嘗試使用Jetty將其恢復到工作狀態的舊項目Spring Spring,並且它使用JSF 1.2,但我並不十分熟悉它。它也有我想要擺脫的ibm taglib庫,但我認爲這個問題是我錯過了庫的一部分,所以暫時我將它們添加到了項目中。JSF 1.2不能在JSP頁面中工作

我有和主要問題,因爲我填充用戶憑據(登錄&密碼)的頁面,控制器接收它們爲空值出於某種原因。感覺實際上我的登錄頁面內的所有#{}都沒有註冊到JSF。

確切的錯誤是

javax.faces.FacesException:# {aaController.login}:顯示java.lang.NullPointerException

對於依賴部分我有JSF的API,JSF -impl,jsf-ibm,用於jsf-libaries的odc-jsf。

我的web.xml文件看起來像這樣

<context-param> 
     <param-name>com.ibm.ws.jsf.JSP_UPDATE_CHECK</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>com.ibm.ws.jsf.LOAD_FACES_CONFIG_AT_STARTUP</param-name> 
     <param-value>true</param-value> 
    </context-param> 
<context-param> 
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 
    <param-value>server</param-value> 
</context-param> 
<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.DEFAULT_SUFFIX</param-name> 
    <param-value>.jsp</param-value> 
</context-param> 
    <context-param> 
     <param-name>com.ibm.faces.DISABLE_JWL_MULTIPART_CONTEXT</param-name> 
     <param-value>false</param-value> 
    </context-param> 
    <context-param> 
     <param-name>com.ibm.faces.RESOURCE_EXPIRE_MS</param-name> 
     <param-value>31536000000</param-value> 
    </context-param> 
    <context-param> 
     <param-name>com.ibm.faces.DATETIME_ASSIST_STRICTNESS</param-name> 
     <param-value>1</param-value> 
    </context-param> 
    <context-param> 
     <param-name>com.ibm.faces.NUMBER_ASSIST_STRICTNESS</param-name> 
     <param-value>1</param-value> 
    </context-param> 
    <context-param> 
     <param-name>com.ibm.faces.USE_UNENCODED_CONTEXT_PATH</param-name> 
     <param-value></param-value> 
    </context-param> 
    <context-param> 
     <param-name>com.ibm.faces.JS_RESOURCE_SERVLET_CACHE</param-name> 
     <param-value>false</param-value> 
    </context-param> 
    <context-param> 
     <param-name>com.ibm.faces.ENCODING_MAPPING</param-name> 
     <param-value>converter.properties</param-value> 
    </context-param> 
    <context-param> 
     <param-name>com.ibm.faces.USE_HXCLIENT_FULL</param-name> 
     <param-value>false</param-value> 
    </context-param> 
    <context-param> 
     <param-name>com.ibm.faces.MAX_REQUEST_CONTENT_SIZE</param-name> 
     <param-value>0</param-value> 
    </context-param> 

<context-param> 
    <param-name>com.sun.faces.numberOfLogicalViews</param-name> 
    <param-value>100</param-value> 
</context-param> 
<context-param> 
    <param-name>com.sun.faces.numberOfViewsInSession</param-name> 
    <param-value>100</param-value> 
</context-param> 
<context-param> 
    <param-name>com.sun.faces.displayConfiguration</param-name> 
    <param-value>false</param-value> 
</context-param> 
<listener> 
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class> 
</listener> 
<filter> 
    <display-name>AaFilter</display-name> 
    <filter-name>AaFilter</filter-name> 
    <filter-class>orgmanager.AaFilter</filter-class> 
    <init-param> 
     <param-name>loginpage</param-name> 
     <param-value>/orgmanagerWeb/faces/Login.jsp</param-value> 
    </init-param> 
    <init-param> 
     <param-name>logoutpage</param-name> 
     <param-value>/orgmanagerWeb/faces/Logout.jsp</param-value> 
    </init-param> 
</filter> 
<filter-mapping> 
    <filter-name>AaFilter</filter-name> 
    <url-pattern>/faces/Jsp/*</url-pattern> 
</filter-mapping> 
<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>/faces/*</url-pattern> 
</servlet-mapping> 
<servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>*.faces</url-pattern> 
</servlet-mapping> 
<welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.htm</welcome-file> 
    <welcome-file>index.jsp</welcome-file> 
    <welcome-file>default.html</welcome-file> 
    <welcome-file>default.htm</welcome-file> 
    <welcome-file>default.jsp</welcome-file> 
</welcome-file-list> 
<jsp-config> 
    <taglib> 
     <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri> 
     <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location> 
    </taglib> 
</jsp-config> 

<error-page> 
    <error-code>500</error-code> 
    <location>/error.jsp</location> 
</error-page> 

<jsp-config> 
    <taglib> 
     <taglib-uri>http://www.ibm.com/jsf/html_extended</taglib-uri> 
     <taglib-location>/WEB-INF/tld/html_extended.tld</taglib-location> 
    </taglib> 
</jsp-config> 

faces-config.xml中的重要部分看起來像這樣:

<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_1_2.xsd" 
      version="1.2"> 

<application> 
    <message-bundle>Messages</message-bundle> 
    <state-manager>com.ibm.faces.application.DevelopmentStateManager</state-manager> 
    <property-resolver>com.ibm.faces.databind.SelectItemsPropResolver</property-resolver> 
    <variable-resolver>com.ibm.faces.databind.SelectItemsVarResolver</variable-resolver> 
</application> 
<factory> 
    <faces-context-factory>com.ibm.faces.context.AjaxFacesContextFactory</faces-context-factory> 
    <render-kit-factory>com.ibm.faces.renderkit.AjaxRenderKitFactory</render-kit-factory> 
</factory> 

<managed-bean> 
    <managed-bean-name>aaController</managed-bean-name> 
    <managed-bean-class>orgmanager.aaController</managed-bean-class> 
    <managed-bean-scope>session</managed-bean-scope> 
    <managed-property> 
     <property-name>role</property-name> 
     <property-class>java.lang.String</property-class> 
     <value>INTERNAL</value> 
    </managed-property> 
</managed-bean> 

    <navigation-rule> 
    <from-view-id>/Login.jsp</from-view-id> 
    <navigation-case> 
     <from-outcome>ok</from-outcome> 
     <to-view-id>/Jsp/ManagerFrontpage.jsp</to-view-id> 
     <redirect /> 
    </navigation-case> 
</navigation-rule> 
<navigation-rule> 
    <navigation-case> 
     <from-action>#{aaController.logout}</from-action> 
     <from-outcome>ok</from-outcome> 
     <to-view-id>/Logout.jsp</to-view-id> 
     <redirect /> 
    </navigation-case> 
</navigation-rule> 

我的Login.jsp看起來是這樣的加標籤

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> 
<%@ taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%> 
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<HTML> 
<HEAD> 
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<META name="GENERATOR" content="IBM Software Development Platform"> 
<META http-equiv="Content-Style-Type" content="text/css"> 
<LINK href="theme/Master.css" rel="stylesheet" type="text/css"> 
<TITLE>Organisation Manager</TITLE> 
<LINK rel="stylesheet" href="theme/standardiwsadpan.css" 
     type="text/css"> 
<LINK rel="stylesheet" type="text/css" href="theme/stylesheet.css" 
     title="Style"> 

</HEAD> 
<f:view> 
<BODY> 

<h:form styleClass="form" id="loginform"> 

    <TABLE border="0" class="SisaankirjausTaulukko"> 
     <TBODY> 
     <TR> 
      <TD colspan="2" align="center" class="Mustalihavoitu">Organisation manager</TD> 

     </TR> 
     <TR> 
      <TD colspan="2" height="5"><IMG border="0" src="kuvat/tyhja.gif"></TD> 

     </TR> 

     <TR> 
      <TD class="Mustalihavoitu">Login</TD> 
      <TD><h:inputText styleClass="inputText" tabindex="1" id="kayttajatunnus" size="8" 
          value="#{aaController.loginView.login}"></h:inputText></TD> 
     </TR> 
     <TR> 
      <TD class="Mustalihavoitu">Password</TD> 
      <TD><h:inputSecret styleClass="inputText" tabindex="2" id="password" size="8" 
           value="#{aaController.loginView.password}"></h:inputSecret></TD> 
     </TR> 
     <TR> 
      <TD colspan="2" height="5"><IMG border="0" src="kuvat/tyhja.gif"></TD> 

     </TR> 
     <TR> 
      <TD colspan="2" align="right"><hx:commandExButton type="submit" 
                  value="Sign in" styleClass="submit-button90" 
                  id="button1" action="#{aaController.login}" 
                  tabindex="3"></hx:commandExButton></TD> 
     </TR> 
     </TBODY> 
    </TABLE> 
</h:form> 
</BODY> 

我的控制器看起來像這樣:

public class AaController extends BaseController { 
public static final int ROLE_INTERNAL = 1; 
public static final int ROLE_EXTERNAL = 2; 

private loginView loginView = new loginView(); 
private int role; 

public String login() throws OrgHallintaException { 
    String result = null; 
    AaFasadi aaFasadi = new AaFasadi(); 
    log.info("Loggin in"); 


    if (aaFasadi.login(loginView.getLogin(), loginView.getPassword())) { 

     if (aaFasadi.getEnviroment().trim().equals("PRODUCTION")) { 
      loginView.setEnviroment("  "); 
     } else { 
      loginView.setEnviroment(aaFasadi.getEnviroment()); 
     } 
     result = "ok"; 

    } else { 
     result = "error"; 
    } 

    return result; 
} 

public String logout() { 
    AaFasadi aaFasadi = new AaFasadi(); 
    aaFasadi.logout(); 
    return "ok"; 
} 

public loginView getloginView() { 
    return loginView; 
} 

public Kayttaja getUser() { 
    return AaFasadi.getUser(); 
} 

}

和控制器中調用的類看起來像這樣

public class AaFasadi { 

private String enviroment=""; 

private static final String USER_SESSION_KEY = "orgmanager.User"; 

public static User getUser() { 
    ServletRequest req = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();      
    return getUser(req); 
} 

public static User getUser(ServletRequest req) {   
    HttpServletRequest request = (HttpServletRequest) req; 

    User user = (User) request.getSession(true).getAttribute(USER_SESSION_KEY); 

    return user; 

} 

public boolean login(String LoginName, String password) throws OrgHallintaException { 

    User user = null; 

    try {   
      PersonelLoginTask personelLoginTask = new PersonelLoginTask(); 
      PersonelLoginView personelLoginView = toimihenkiloSisaankirjausTehtava.execute(LoginName.toUpperCase(), password); 

     if (personelLoginView != null) { 
      if (personelLoginView.getEnviroment().trim().equals("PRODUCTION")) 
       personelLoginView.setEnviroment("  "); 
      User = new DefaultUserImpl(personelLoginView); 
      Enviroment = personelLoginView.getEnviroment(); 
      } 

    } catch (TehtavanHallintaException e) { 
     System.out.println("User " + Usertunnus + " Login failed " + e); 
    } 


    if (User != null) { 

     ServletRequest req = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();      
     HttpServletRequest request = (HttpServletRequest) req;   
     request.getSession(true).setAttribute(User_SESSION_KEY, User); 

     return true; 
    } else { 
     return false; 
    } 
} 

public void logout() { 
    ServletRequest req = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();      
    HttpServletRequest request = (HttpServletRequest) req;   
    request.getSession(true).removeAttribute(User_SESSION_KEY); 
    request.getSession().invalidate();    
} 



public String getEnviroment() { 
    return enviroment; 
} 

public void setEnviroment(String ymparisto) { 
    this.enviroment = enviroment; 
} 

}

由於某種原因,我的Login.jsp頁面aaController.loginView.login & aaController.loginView.password根本不起作用,它們返回空值,我不知道爲什麼。 loginView在它的類中有正確的Get和Set方法。我的JSF配置有問題嗎?

我loginview看起來像這樣

public class loginView extends BaseView { 

private String login; 
private String password; 
private String Enviroment; 
private Date date = new Date(System.currentTimeMillis()); 




public String getlogin() { 
    return login; 
} 
public void setlogin(String login) { 
    this.login = login; 
} 
public String getpassword() { 
    return password; 
} 
public void setpassword(String password) { 
    this.password = password; 
} 

public String getEnviroment() { 
    return Enviroment; 
} 

public void setEnviroment(String Enviroment) { 
    this.Enviroment = Enviroment; 
} 


public void setDate(Date date) { 
    this.date = date; 
} 

}

+0

你的bean的範圍是什麼?看起來像'loginView'類嗎?你可以在bean中使用兩個單獨的字段來登錄,而不是使用loginView類嗎? – Omar

+0

嗨奧馬爾。我添加了loginView來顯示。 aaController的範圍是Session。我應該改變它嗎? – Oliver

+0

我也有這個問題,當我進入Login.jsp頁面的登錄輸入字段的值「#{aaController.loginView.login}」顯示在字段上。這是否應該正常發生? – Oliver

回答

0

好答案是很愚蠢的,但我終於找到了它。我使用的是web.xml模式版本2.4,但它需要2.5才能工作。