primefaces效果不起作用

时间:2014-03-13 16:55:49

标签: java jsf primefaces

我正在使用JSF 2和PrimeFaces 4.0。当我运行new.xhtml文件时,它会给出以下异常:

Error Rendering View[/NewFile.xhtml]: java.lang.NullPointerException
    at org.primefaces.renderkit.OutcomeTargetRenderer.getTargetURL(OutcomeTargetRenderer.java:80) [:4.0]
    at org.primefaces.component.button.ButtonRenderer.buildOnclick(ButtonRenderer.java:93) [:4.0]
    at org.primefaces.component.button.ButtonRenderer.encodeMarkup(ButtonRenderer.java:53) [:4.0]
    at org.primefaces.component.button.ButtonRenderer.encodeEnd(ButtonRenderer.java:32) [:4.0]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [:2.1.1-FCS]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763) [:2.1.1-FCS]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759) [:2.1.1-FCS]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759) [:2.1.1-FCS]
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401) [:2.1.1-FCS]
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) [:2.1.1-FCS]
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) [:2.1.1-FCS]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [:2.1.1-FCS]
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [:2.1.1-FCS]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:410) [:2.1.1-FCS]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.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.1.0.Final]
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
    at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
    at java.lang.Thread.run(Unknown Source) [:1.7.0_17]

22:04:34,939 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/p1].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception: java.lang.NullPointerException
    at org.primefaces.renderkit.OutcomeTargetRenderer.getTargetURL(OutcomeTargetRenderer.java:80) [:4.0]
    at org.primefaces.component.button.ButtonRenderer.buildOnclick(ButtonRenderer.java:93) [:4.0]
    at org.primefaces.component.button.ButtonRenderer.encodeMarkup(ButtonRenderer.java:53) [:4.0]
    at org.primefaces.component.button.ButtonRenderer.encodeEnd(ButtonRenderer.java:32) [:4.0]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [:2.1.1-FCS]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763) [:2.1.1-FCS]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759) [:2.1.1-FCS]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759) [:2.1.1-FCS]
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401) [:2.1.1-FCS]
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) [:2.1.1-FCS]
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) [:2.1.1-FCS]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [:2.1.1-FCS]
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [:2.1.1-FCS]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:410) [:2.1.1-FCS]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.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.1.0.Final]
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
    at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
    at java.lang.Thread.run(Unknown Source) [:1.7.0_17]

我的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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>web</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>/faces/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>

我的xhtml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!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"
    xmlns:p="http://primefaces.org/ui">

<h:head>
<link type="text/css" rel="stylesheet" href="#{request.contextPath}/css/default.css" />
   <style type="text/css">
                .ui-widget{font-size:90% !important;}
                .ui-layout-unit-content{background-image:url('a.jpg');}
            </style>
 <h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />


</h:head>
<h:body>
    <h1>Hello World PrimeFaces</h1>
    <p:inputText /> 
 <p:button outcome="productDetail" value="Bookmark" icon="ui-icon-star"></p:button>
</h:body>
</html>

我已经面对这个问题一个星期,但我无法解决这个问题。

1 个答案:

答案 0 :(得分:1)

唯一需要做的就是在当前xhtml可用的同一目录中创建名为“productDetail.xhtml”的jsf页面(xhtml页面)。

执行上述操作会让您的代码正常工作,是的,请将您的代码放在h:body中,并使用h:form。否则会产生如下警告(如果javax.faces.PROJECT_STAGE设置为Development),

The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>