2011-08-31 42 views
0

我與我的第一個JSF的Hello World的工作,但是這是不工作... 我使用JBoss應用服務器6個+ Jbosstools Eclipse插件 我的web.xml:jsf 2中的helloworld無法正常工作?

<?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_3_0.xsd" version="3.0"> 
    <display-name>PesianJ</display-name> 

    <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.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> 
</web-app> 

我的網頁:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:ui="http://java.sun.com/jsf/facelets"> 
<head> 
<title>hello world</title> 
</head> 

<h:body> 

<h:form> 

<table> 

<tr> 
<td>Name:</td> 
<td> 
<h:inputText label="first name" id="fname" value="#{userBean.firstName}" required="true"/> 
<h:message for="fname"/> 
</td> 
</tr> 

<tr> 
<td>Family:</td> 
<td> 
<h:inputText label="last name" id="lname" value="#{userBean.lastName}" required="true"/> 
<h:message for="lname"/> 
</td> 
</tr> 

<tr> 
<td>Sex:</td> 
<td> 
<h:selectOneRadio label="sex" id="sex" value="userBean.sex" required="true"> 
<f:selectItem itemLabel="Male" itemValue="male"/> 
<f:selectItem itemLabel="Female" itemValue="female"/> 
</h:selectOneRadio> 
<h:message for="sex"/> 

<h:inputText id="date" label="Date Of Birthday" value="#{userbean.date}" > 
<f:convertDateTime pattern="MM-dd-yy"/> 
(mm-dd-yy) 
<h:message for="date"/> 
</td> 
</tr> 

</table> 
<h:commandButton value="register" action="confirm" /> 
</h:form> 

</h:body> 

</html> 

和例外,我給的是:

07:26:45,939 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/PesianJ].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception: java.lang.NullPointerException 
    at com.sun.faces.lifecycle.RestoreViewPhase.notifyAfter(RestoreViewPhase.java:288) [:2.0.3-] 
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110) [:2.0.3-] 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) [:2.0.3-] 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) [:2.0.3-] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final] 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final] 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.Final] 
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final] 
    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final] 
    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final] 
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final] 
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final] 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final] 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final] 
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final] 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final] 
    at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final] 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final] 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final] 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final] 
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final] 
    at java.lang.Thread.run(Unknown Source) [:1.6.0_26] 

編輯: 我的臉,配置:

<?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"> 


</faces-config> 

itry http://localhost:8080/app/register.jsf 我給瀏覽器excption和eclipse堆棧跟蹤控制檯。其他信息不是必須的,請幫助我! 非常感謝

+0

您標記了MyFaces,但堆棧跟蹤顯示您正在使用Mojarra。你現在在使用什麼JSF實現?你的webapp的'/ WEB-INF/lib'中有沒有JSF庫?你是否意識到JBoss帶有自己的JSF庫?它可能會與你在webapp中放置的那些相沖突,而不在'web.xml'中設置必要的JBoss特定的上下文參數,它應該告訴它使用WAR捆綁的JSF impl。 – BalusC

+0

有人告訴我,當我使用jboss 6時,我不應該將它們添加到lib文件夾中,所以我sid'nt添加任何東西。它不是真的? – sara

+0

好的。那你爲什麼要標記MyFaces?你知道MyFaces是什麼嗎? – BalusC

回答

1

按在我的評論回答你的/WEB-INf/lib包含:

JSTL和標準,它們全部由默認的Eclipse IDE把5共文件..

JBoss已經附帶JSTL。它可能與這些文件相沖突。刪除JSTL和標準JAR文件並重試。