Identifying and solving javax.el.PropertyNotFoundE

2018-12-30 22:59发布

When trying to reference a managed bean in EL like so #{bean.entity.property}, sometimes a javax.el.PropertyNotFoundException: Target Unreachable exception is being thrown, usually when a bean property is to be set, or when a bean action is to be invoked.

There seem to be five different kinds of messages:

  1. Target Unreachable, identifier 'bean' resolved to null
  2. Target Unreachable, 'entity' returned null
  3. Target Unreachable, 'null' returned null
  4. Target Unreachable, ''0'' returned null
  5. Target Unreachable, 'BracketSuffix' returned null

What do they all mean? How are they caused and how should they be solved?

10条回答
不再属于我。
2楼-- · 2018-12-30 23:17

EL interprets ${bean.propretyName} as described - the propertyName becomes getPropertyName() on the assumption you are using explicit or implicit methods of generating getter/setters

You can override this behavior by explicitly identifying the name as a function: ${bean.methodName()} This calls the function method Name() directly without modification.

It isn't always true that your accessors are named "get...".

查看更多
浅入江南
3楼-- · 2018-12-30 23:20

I decided to share my solution, because although many answers provided here were helpful, I still had this problem. In my case, I am using JSF 2.3, jdk10, jee8, cdi 2.0 for my new project and I did run my app on wildfly 12, starting server with parameter standalone.sh -Dee8.preview.mode=true as recommended on wildfly website. The problem with "bean resolved to null” disappeared after downloading wildfly 13. Uploading exactly the same war to wildfly 13 made it all work.

查看更多
一个人的天荒地老
4楼-- · 2018-12-30 23:28

I decided to share my finding on this error after resolving it myself.

First of all, BalusC solutions should be taken seriously but then there is another likely issue in Netbeans to be aware of especially when building an Enterprise Application Project(EAR) using Maven.

Netbeans generates, a parent POM file, an EAR project, an EJB project and a WAR project. Everything else in my project was fine, and I almost assumed the problem is a bug in probably GlassFish 4.0(I had to install and plug it into Netbeans) because GlassFish 4.1 has a Weld CDI bug which makes the embedded GlassFish 4.1 in Netbeans 8.0.2 unusable except through a patch.

Solution:

To resolve the "Target Unreachable, identifier 'bean' resolved to null" error-

I Right-click the parent POM project, and select Properties. A Project Properties Dialog appears, click "Sources", you will be surprised to see the "Source/Binary Format" set to 1.5 and "Encoding" set to Windows 1250. Change the "Source/Binary Format" to 1.6 0r 1.7, whichever you prefer to make your project CDI compliant, and "Encoding" to UTF-8.

Do the same for all the other subprojects(EAR, EJB, WAR) if they are not already compartible. Run your project, and you won't get that error again.

I hope this helps someone out there having similar error.

查看更多
荒废的爱情
5楼-- · 2018-12-30 23:28

I had the same problem. The solution turned out to be much simpler. It appears that a datatable wants the method in the form of a getter, ie getSomeMethod(), not just someMethod(). In my case in the datatable I was calling findResults. I changed the method in my backing bean to getFindResults() and it worked.

A commandButton worked find without the get which served to make it only more confusing.

查看更多
深知你不懂我心
6楼-- · 2018-12-30 23:29

In my case, I commited a spell mistake in @Named("beanName"), it was suppose to be "beanName", but I wrote "beanNam", for example.

查看更多
余欢
7楼-- · 2018-12-30 23:29

I am using wildfly 10 for javaee container . I had experienced "Target Unreachable, 'entity' returned null" issue. Thanks for suggestions by BalusC but the my issue out of the solutions explained. Accidentally using "import com.sun.istack.logging.Logger;" instead of "import org.jboss.logging.Logger;" caused CDI implemented JSF EL. Hope it helps to improve solution .

查看更多
登录 后发表回答