Posts Tagged ‘JEE6’

JSF Error – Target Unreachable, identifier ‘MyBacking’ resolved to null

Friday, July 16th, 2010

My JSF application was throwing the following error message:


Target Unreachable, identifier 'MyBacking' resolved to null

All of my other backing beans were working so It was kind of perplexing and I could not immediately pinpoint the error source.
To cut a long story short, it turns out that the ManagedBean annotation requires the name attribute like so:


@ManagedBean(name = "MyBacking")
@RequestScoped
public class MyBacking {
[...]

This is kind of odd since the class name and the defined attribute name are equal.

My environment:

Netbeans 6.9
Mojarra 2.0.2
EclipseLink, version: Eclipse Persistence Services – 2.0.0.v20091127-r5931
GlassFish Server 3

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;
				

Differences between TopLink and EclipseLink

Monday, March 22nd, 2010

The default persistence manager in Netbeans Release 6.8 has changed from TopLink to EclipseLink and I will list error messages and differences that I find as I go along.

1.
ErrorMessage

Exception [EclipseLink-8034] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Error compiling the query [findUserByEmail: SELECT u FROM theuser u WHERE u.email = :email]. Unknown entity type [theuser].
at org.eclipse.persistence.exceptions.JPQLException.entityTypeNotFound(JPQLException.java:483)

Solution
EclipseLink is case sensitive. If your entity is named “TheUser” (yes, it is a dumm name for an entity) your named query should be:
@NamedQueries({
@NamedQuery(
name="findUserByEmail",
query="SELECT u FROM TheUser u WHERE u.email = :email"
)
})

and not ...SELECT u FROM theuser....