0

我正在使用使用 primefaces 的 jsf Web 应用程序,我已经在 xhtml 页面中使用 primefaces 实现了示例表单,并且我已经创建了一个 bean 类。

当我编译它时,我得到了这个异常

SEVERE: An exception occurred
javax.faces.FacesException: java.lang.NoSuchMethodError: org.primefaces.util.ComponentUtils.getValueToRender(Ljavax/faces/context/FacesContext;Ljavax/faces/component/UIComponent;)Ljava/lang/String;
    at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.wrap(ExceptionHandlerImpl.java:241)
    at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:156)
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:258)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NoSuchMethodError: org.primefaces.util.ComponentUtils.getValueToRender(Ljavax/faces/context/FacesContext;Ljavax/faces/component/UIComponent;)Ljava/lang/String;
    at org.primefaces.component.inputtext.InputTextRenderer.encodeMarkup(InputTextRenderer.java:77)
    at org.primefaces.component.inputtext.InputTextRenderer.encodeEnd(InputTextRenderer.java:51)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:543)
    at org.apache.myfaces.shared_impl.renderkit.html.HtmlGridRendererBase.renderChildren(HtmlGridRendererBase.java:315)
    at org.apache.myfaces.shared_impl.renderkit.html.HtmlGridRendererBase.encodeEnd(HtmlGridRendererBase.java:150)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:59)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43)
    at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:220)
    at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:144)
    at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:74)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:618)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
    at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1159)
    at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:263)
    at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
    ... 17 more

我的 sample.xhtml 页面是

<ui:composition template="/pages/layout.xhtml"
     xmlns="http://www.w3.org/1999/xhtml"
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:h="http://java.sun.com/jsf/html"
     xmlns:ui="http://java.sun.com/jsf/facelets"
     xmlns:p="http://primefaces.org/ui"
     xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:define name="content">
        <h:form id="form"> 
            <p:panel id="panel" header="New Person"> 
                <p:messages id="msgs"/>  
        <h:panelGrid columns="3">  
            <h:outputLabel for="firstname" value="Firstname: *" />  
            <p:inputText id="firstname" value="#{personBean.firstname}" required="true" label="Firstname">  
                <f:validateLength minimum="2" />  
            </p:inputText>  
            <p:message for="firstname" display="icon"/>  

            <h:outputLabel for="surname" value="Surname: *" />  
            <p:inputText id="surname" value="#{personBean.surname}" label="Surname" required="true">  
                <f:validateLength minimum="2" />  
                <p:ajax update="msgSurname" event="keyup" />  
            </p:inputText>  
            <p:message for="surname" id="msgSurname" display="icon"/>  

        </h:panelGrid>  

        <p:commandButton id="btn" value="Save" update="panel" actionListener="#{personBean.savePerson}"/>  
    </p:panel>  

</h:form>  
     </ui:define>
</ui:composition>

我的豆类是

package com.cation.action;

import javax.faces.application.FacesMessage;  
import javax.faces.context.FacesContext;  
import javax.faces.event.ActionEvent;  

public class PersonBean {  

    private String firstname;  

    private String surname;  

    public String getFirstname() {  
        return firstname;  
    }  
    public void setFirstname(String firstname) {  
        this.firstname = firstname;  
    }  

    public String getSurname() {  
        return surname;  
    }  
    public void setSurname(String surname) {  
        this.surname = surname;  
    }  

    public void savePerson(ActionEvent actionEvent) {  
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Welcome " + firstname + " " + surname + "!"));  
    }  
}  

我的 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>Cation</display-name>

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
      </context-param>
      <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
</context-param>
   <welcome-file-list>
        <welcome-file>faces/login.xhtml</welcome-file>
    </welcome-file-list>

     <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>*.jsf</url-pattern>
    </servlet-mapping>
    <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>
  <listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
  </listener>
</web-app>

谁能帮我解决这个问题。

4

0 回答 0