【发布时间】:2015-01-10 23:49:14
【问题描述】:
有一个非常相似的问题:Richfaces in netbeans with maven,即在 GlassFish 4 中部署 JSF 项目时出现问题。1
- 我尝试创建一个 JSF 项目:
- a) Maven 和 javax.faces-war-archetype 2.2 版和
- b) 作为 NetBeans 项目
- 我尝试使用:
- a) Primefaces 5 --> 有效
- b) Richfaces 4.3 --> 不工作
- 项目在
Glassfish 4.0和WildFly 8.1下运行正常
我在 netbeans 中得到的例外是:
警告:StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet 抛出异常 java.lang.IllegalStateException 在 com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java:705) 在 com.sun.faces.context.FacesContextImpl.getAttributes(FacesContextImpl.java:237) 在 org.richfaces.context.ExtendedPartialViewContext.setInstance(ExtendedPartialViewContext.java:55) 在 org.richfaces.context.ExtendedPartialViewContext.release(ExtendedPartialViewContext.java:64) 在 org.richfaces.context.ExtendedPartialViewContextImpl.release(ExtendedPartialViewContextImpl.java:424) 在 com.sun.faces.context.FacesContextImpl.release(FacesContextImpl.java:591) 在 javax.faces.webapp.FacesServlet.service(FacesServlet.java:665) 在 org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) 在 org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) 在 org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) 在 com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) 在 org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282) 在 com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) 在 com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) 在 org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201) 在 org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175) 在 org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) 在 org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) 在 org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) 在 org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) 在 org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) 在 org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) 在 org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) 在 org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561) 在 org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) 在 org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) 在 org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) 在 org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) 在 org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565) 在 org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545) 在 java.lang.Thread.run(Thread.java:745)
我将描述我在以 Maven 方式构建项目时所遵循的步骤:
这些是我创建的步骤:一个JSF 项目,其中NetBeans 8.0.1、GlassFish 4.1 使用RichFaces。项目是使用 maven archetype javax.faces-war-archetype ver 2.2 创建的。
- 新建项目->Maven->来自 Archetype 的项目
- 搜索 javax,因此可用 arhcetypes 中的唯一选项是
javax.faces-war-archetype-ver2.2。选择它。 - 输入位置名称等。我选择作为名称:
test_richfaces_with_archetype - 点击
Finish
创建项目的pom.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mydomain.myproject</groupId>
<artifactId>test_richfaces_with_archetype</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>${project.artifactId}</name>
<description>A simple project with war packaging that depends on JSF 2.2 and
javaee 6, in that order.</description>
<url>http://jsf-spec.java.net/</url>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<spec.snapshot.version>2.2</spec.snapshot.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>${spec.snapshot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>java.net-maven2-SNAPSHOT-repository</id>
<name>Java.net SNAPSHOT-Repository for Maven</name>
<url>https://maven.java.net/content/repositories/snapshots/</url>
<layout>default</layout>
</repository>
<repository>
<id>java.net-maven2-repository</id>
<name>Java.net Repository for Maven</name>
<url>https://maven.java.net/content/repositories/releases/</url>
<layout>default</layout>
</repository>
</repositories>
</project>
- 右键项目并选择
properties - 转到
Frameworks:您会看到JSF 2.2库已经为您选择了 - 转到
components选项卡并检查Richfaces - 单击确定,NeatBeans 将下载
Richfaces库并将它们放入您的localmaven 存储库
pom.xml 已更改,现在如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.com.mydomain.myproject</groupId>
<artifactId>test_richfaces_with_archetype</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>${project.artifactId}</name>
<description>A simple project with war packaging that depends on JSF 2.2 and
javaee 6, in that order.</description>
<url>http://jsf-spec.java.net/</url>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<spec.snapshot.version>2.2</spec.snapshot.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>${spec.snapshot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<version>4.3.3.Final</version>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<version>4.3.3.Final</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>java.net-maven2-SNAPSHOT-repository</id>
<name>Java.net SNAPSHOT-Repository for Maven</name>
<url>https://maven.java.net/content/repositories/snapshots/</url>
<layout>default</layout>
</repository>
<repository>
<id>java.net-maven2-repository</id>
<name>Java.net Repository for Maven</name>
<url>https://maven.java.net/content/repositories/releases/</url>
<layout>default</layout>
</repository>
<repository>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
<id>RichFaces-maven-lib</id>
<layout>default</layout>
<name>Repository for library RichFaces-maven-lib</name>
</repository>
</repositories>
</project>
welcomeRichfaces.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:rich="http://richfaces.org/rich"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Richfaces Welcome Page</title>
</h:head>
<h:body>
<rich:panel header="Welcome to Richfaces">
RichFaces is an advanced UI component framework for easily integrating Ajax capabilities into business applications using JSF. Check out the links below to lear more about using RichFaces in your application.
<ul>
<li><h:outputLink value="http://richfaces.org" >Richfaces Project Home Page</h:outputLink></li>
<li><h:outputLink value="http://showcase.richfaces.org" >Richfaces Showcase</h:outputLink></li>
<li><h:outputLink value="https://community.jboss.org/en/richfaces?view=discussions" >User Forum</h:outputLink></li>
<li><h:outputLink value="http://www.jboss.org/richfaces/docs" >Richfaces documentation...</h:outputLink>
<ul>
<li><h:outputLink value="http://docs.jboss.org/richfaces/latest_4_X/Developer_Guide/en-US/html_single/" >Development Guide</h:outputLink></li>
<li><h:outputLink value="http://docs.jboss.org/richfaces/latest_4_X/Component_Reference/en-US/html/" >Component Reference</h:outputLink></li>
<li><h:outputLink value="http://docs.jboss.org/richfaces/latest_4_X/vdldoc/" >Tag Library Docs</h:outputLink></li>
</ul>
</li>
</ul>
</rich:panel>
</h:body>
</html>
还有web.xml
<web-app version="3.0"
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-app_3_0.xsd">
<display-name>mojarra-regression-test</display-name>
<description>A simple regression test to make it easier to get your bug fixed. The only reason we need a web.xml is to set the PROJECT_STAGE to Develoment. If you have a web.xml, then you need to map the FacesServlet.</description>
<context-param>
<description>
Tell the runtime where we are in the project development
lifecycle. Valid values are:
Development, UnitTest, SystemTest, or Production.
The runtime will display helpful hints to correct common mistakes
when the value is Development.
</description>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Faces Servlet -->
<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>
<welcome-file-list>
<welcome-file>faces/main.xhtml</welcome-file>
</welcome-file-list>
</web-app>
此外,如果您单击依赖项节点中的加号,您将看到:
- javaee-api-6.0.jar
- javax.faces-api-2.2.jar
- richfaces-components-ui-4.3.3.Final.jar
- cssparser-0.9.5.jar
- guava-13.0.1.jar
- richfaces-components-api-4.3.3.Final.jar
- richfaces-core-api-4.3.3.Final.jar
- sac-1.3.jar
注意: 在我尝试编译(干净构建)项目时,番石榴库出现错误。我删除了存储库中已有的 google 文件夹,再次进行了干净构建。一切都重新下载并编译了项目。
- 右键
project,进入properties,选择run,从服务器列表中选择GlassFish。点击确定。 - 右键单击项目并选择运行。在这个阶段,您的浏览器将打开:
http://localhost:8080/test_richfaces_with_archetype。你会看到First name: Duke Last name: Java和一个提交按钮。 - 转至
main.xhtml更改它以向命令按钮元素添加操作:<h:commandButton value="submit" action="welcomeRichfaces"/>。保存main.xhtml. - 重新加载页面并单击按钮。欢迎的 Richfaces xhtml 应显示在您的浏览器中。
- 结束
【问题讨论】:
-
GlassFish 4.1 比较新,你用更新版本的 RichFaces 试过了吗?
-
@Makhiel 我尝试使用 Richfaces 4.5.1-SNAPSHOT 并且成功了!
标签: maven jsf netbeans primefaces richfaces