zlinks
zlinks

Reputation: 1067

JSF & Richfaces/Primefaces - Maven - Netbeans 8.0.1 - Glassfish 4.1

Have a very similar problem with this: Richfaces in netbeans with maven, i.e. there is a problem when the JSF project is deployed in GlassFish 4.1

  1. I tried creating a JSF project with:
    • a) Maven and javax.faces-war-archetype ver 2.2 and
    • b) as a NetBeans project
  2. I tried using:
    • a) Primefaces 5 --> works
    • b) Richfaces 4.3 --> doesn't work
  3. Project runs fine with Glassfish 4.0 and WildFly 8.1

The exception I get in netbeans is :

Warning: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception java.lang.IllegalStateException at com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java:705) at com.sun.faces.context.FacesContextImpl.getAttributes(FacesContextImpl.java:237) at org.richfaces.context.ExtendedPartialViewContext.setInstance(ExtendedPartialViewContext.java:55) at org.richfaces.context.ExtendedPartialViewContext.release(ExtendedPartialViewContext.java:64) at org.richfaces.context.ExtendedPartialViewContextImpl.release(ExtendedPartialViewContextImpl.java:424) at com.sun.faces.context.FacesContextImpl.release(FacesContextImpl.java:591) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:665) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545) at java.lang.Thread.run(Thread.java:745)

I will describe the steps I followed when building the project the Maven way: These are the steps that I followed to create: A JSF project, with NetBeans 8.0.1 , GlassFish 4.1 that uses RichFaces. Project is created using maven archetype javax.faces-war-archetype ver 2.2.

  1. New Project->Maven->Project from Archetype
  2. Search for javax thus only option in available arhcetypes is javax.faces-war-archetype - ver2.2. Choose it.
  3. Put location name etc. I choose as name: test_richfaces_with_archetype
  4. Click Finish

The pom.xml of the created project is:

<?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>
  1. Right click project and choose properties
  2. Go to Frameworks: you will see that the JSF 2.2 library is already chosen for you
  3. Go to components tab and check Richfaces
  4. Click OK and NeatBeans will download the Richfaces libraries and put them to your local maven repository

The pom.xml has changed and is now like:

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

The welcomeRichfaces.xhtml is

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

And the 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>

Also if you click the plus sign in the dependencies node you will see:

Note: in my case there was an error with the guava library when I was trying to compile (clean-build) the project. I deleted the google folder that I already had in my repository , did a clean-build again. Everything was re-downloaded and the project compiled.

  1. Right click project , go to properties , choose run and choose GlassFish from the server list. Click OK.
  2. Right click project and choose Run. At this stage you browser will open at: http://localhost:8080/test_richfaces_with_archetype. You will something like First name: Duke Last name: Java and a submit button.
  3. Go to main.xhtml alter it in order to add an action to the command button element: <h:commandButton value="submit" action="welcomeRichfaces"/>. Save the main.xhtml.
  4. Reload the page and click the button. The welcome richfaces xhtml should be displayed in your browser.
  5. END

Upvotes: 3

Views: 3326

Answers (1)

Myluco
Myluco

Reputation: 59

I had the same problem with Wildfly 8.2. My solution was to "downgrade" jsf. Please, see Upgrad to Wildfly 8.2 with error

Upvotes: 1

Related Questions