Posts Tagged ‘JavaEE’

How to register a ServletContextListener in JSF 2.0

Thursday, May 27th, 2010

In pre JSF 2.0 you were forced to use the WEB-INF/web.xml file to register your ServletContextListener



<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">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <listener>
        <listener-class>com.mycompany.myproject.MyServletContextListener</listener-class>
    </listener>
...
</web-app>

While you can still do this, in JSF 2.0 it is now possible to register your ServletContextListener or rather any of the following Listeners:

ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener, HttpSessionListener, HttpSessionAttributeListener

by using the @WebListener annotation.

So your listener implementation would look like the following:


@WebListener
public class MyServletContextListener implements ServletContextListener {
...
}

When registering my ServletContextListener I ran into the following error messages:


SCHWERWIEGEND: PWC1306: Startup of context /MyApp failed due to previous errors
SCHWERWIEGEND: PWC1305: Exception during cleanup after start failed
org.apache.catalina.LifecycleException: PWC2769: Manager has not yet been started
        at org.apache.catalina.session.StandardManager.stop(StandardManager.java:892)
        at org.apache.catalina.core.StandardContext.stop(StandardContext.java:5383)
        ...

SCHWERWIEGEND: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: java.lang.NullPointerException
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:5216)
        at com.sun.enterprise.web.WebModule.start(WebModule.java:499)
        ...

WARNUNG: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NullPointerException
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NullPointerException
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:932)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:912)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:694)
        ...

SCHWERWIEGEND: Exception while invoking class com.sun.enterprise.web.WebApplication start method
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NullPointerException
        at com.sun.enterprise.web.WebApplication.start(WebApplication.java:117)
        at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
        at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)
        at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236)

SCHWERWIEGEND: Exception while loading the app
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NullPointerException
        at com.sun.enterprise.web.WebApplication.start(WebApplication.java:117)
        at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
        at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)

This was a simple oversight on my part. In my Listener I wanted to use an EJB to add some data to the database using JPA. I forgot to use the @EJB annotation when defining the EJB attribute:


@EJB
private MyFacade myfacade;
				

Preview Release of JavaFX Composer

Thursday, December 17th, 2009

Just this week marked the release of Netbeans 6.8. Another release that has been worth waiting for with many great new features including full support of Java EE 6.

One of the things that followed after the release was the announcement in Netbeans newsletter Issue # 420 – Dec 15, 2009 that a preview release of JavaFX Composer was made. The release has been made very silently since none of the other major JavaFX blogs we are following has picked up the news. JavaFX Composer is a visual design tool or RAD (rapid application development) tool that has been much anticipated and will make the development of “business” applications using JavaFX more compelling for businesses.

We are very excited about the release and our first impression is very good. We hope to give the composer a more thorough test ride soon.

The JavaFX Composer is a Netbeans plugin and you can get it like this:

“The JavaFX Composer is a preview release and is available for NetBeans IDE 6.8 as a plugin from the NetBeans Update Center. (From the NetBeans IDE, go to Tools –> Plugins –> Available Plugins –> JavaFX.) ” (source Netbeans newsletter issue #420)

More information can be found here.

The other tool Sun is working on is the JavaFX Authoring Tool where no release date has yet been made public.