This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 215703 - java.lang.NullPointerException from getAsObject() when updating data in JSF page with Join Table EJB
Summary: java.lang.NullPointerException from getAsObject() when updating data in JSF p...
Status: VERIFIED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: JSF (show other bugs)
Version: 7.2
Hardware: All All
: P2 normal (vote)
Assignee: Martin Fousek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-18 16:13 UTC by heckler
Modified: 2012-09-05 11:09 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
changes to workaround the issue in generated sources (715 bytes, text/plain)
2012-07-19 07:40 UTC, Martin Fousek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description heckler 2012-07-18 16:13:23 UTC
User-Agent:       Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11
Build Identifier: NetBeans IDE 7.2 RC1 (Build 201206272359)

When attempting to save updated values on a generated "Edit" JSF page that uses an entity EJB created from a join table in the database, the following error occurs:

java.lang.NullPointerException
	at com.mbcc.controller.CustomerController$CustomerControllerConverter.getAsObject(CustomerController.java:204)

Line 204 is:

return controller.ejbFacade.find(getKey(value));

getKey(value) returns Integer 1 in my test scenario...and the record is in the underlying table.

Changing the class declaration to
@ManagedBean(name="customerController")
similar to how it was generated in 7.1.2 and resolving the imports fixes the problem. Switching it back to a generated EJB again produces the NullPointerException.

This behavior doesn't seem to occur when editing/saving single-table entities.

Reproducible: Always

Steps to Reproduce:
1. Create tables in database (MySQL in my test case), including a join table.
2. Generate entities from database.
3. Create JSF pages from entities.
4. Run, edit "joined" items/entities, save, boom.  :-)
Actual Results:  
- Stack Trace

java.lang.NullPointerException
	at com.mbcc.controller.CustomerController$CustomerControllerConverter.getAsObject(CustomerController.java:204)
	at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:171)
	at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:202)
	at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:319)
	at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
	at javax.faces.component.UIInput.validate(UIInput.java:960)
	at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
	at javax.faces.component.UIInput.processValidators(UIInput.java:698)
	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
	at javax.faces.component.UIForm.processValidators(UIForm.java:253)
	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
	at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)
	at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
	at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
	at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
	at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
	at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
	at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
	at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
	at java.lang.Thread.run(Thread.java:722)

Expected Results:  
...was successfully updated.
(This happens once you change from EJB to ManagedBean.)

Understand the move to EJB and want it to work. Thanks much! Anything I can do to help resolve, please let me know.
Comment 1 Martin Fousek 2012-07-19 07:38:21 UTC
Thanks heckler, that's really good catch. I updated the bug status a little bit and marked as P2 since it's a regression. :/ In addition to the reported steps, there is need to have enabled CDI in the project where are JSF pages generated.

Now to the problem... As far as I (according google) understand this could be caused by JSF-CDI integration issue. This problem should be resolved in next JSF spec version but until that we are probably facing similar problem to this one:
http://www.java.net/external?url=http://dominikdorn.com/2010/04/cdi-weld-manual-bean-lookup/

The Converter is created (and managed then) by JSF lifecycle, so it probably cannot resolve CDI and its injections properly. I'm attaching piece of code which can be used as workaround in generated sources. Except attached converter enhancements, there is needed to annotate facades as Named beans to be discoverable by CDI BeanManager.

All this code changes are quite big especailly to WA single annotation. I propose that I will bring back ManagedBean for CDI projects until these scenarios will work. Make it sense, David? (btw. I updated ManagedBeans to Named before since more users complain about that it looks obsolete in CDI-times and it looked to be allright)
Comment 2 Martin Fousek 2012-07-19 07:40:15 UTC
Created attachment 122183 [details]
changes to workaround the issue in generated sources

Sorry I forgot to attach the converter's changes.
Comment 3 heckler 2012-07-19 14:54:18 UTC
Makes perfect sense, Martin. Thanks for getting to the bottom of this so quickly and for providing the workaround code. Really appreciate NetBeans and all your team does!

All the best,
Mark
Comment 4 Martin Fousek 2012-07-20 15:02:18 UTC
Fixed in web-main #85471526855a.
Comment 5 Martin Fousek 2012-07-20 15:11:49 UTC
(In reply to comment #3)
> Makes perfect sense, Martin. Thanks for getting to the bottom of this so
> quickly and for providing the workaround code. Really appreciate NetBeans and
> all your team does!

Thanks for your kind words. I brought back the generation of ManagedBeans - you should get the fix in patch1 of NetBeans 7.2. Thanks again for reporting!
Comment 6 Quality Engineering 2012-07-20 20:35:56 UTC
Integrated into 'main-golden', will be available in build *201207201847* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/85471526855a
User: Martin Fousek <marfous@netbeans.org>
Log: #215703 - java.lang.NullPointerException from getAsObject() when updating data in JSF page with Join Table EJB
Comment 7 David Konecny 2012-07-22 20:29:49 UTC
(In reply to comment #1)
> I propose that I will bring back ManagedBean for CDI projects until these
> scenarios will work. Make it sense, David? (btw. I updated ManagedBeans to
> Named before since more users complain about that it looks obsolete in
> CDI-times and it looked to be allright)

Sorry for late response. I agree with your problem resolution Martin. I remember we had a discussion about about whether to use CDI or ManagedBeans. Was there an issue requesting it or have we discusses it offline?
Comment 8 Martin Fousek 2012-07-23 05:36:20 UTC
(In reply to comment #7)
> Sorry for late response. I agree with your problem resolution Martin. I
> remember we had a discussion about about whether to use CDI or ManagedBeans.
> Was there an issue requesting it or have we discusses it offline?

Our offline discussion was related to:
http://netbeans.org/projects/www/lists/netcat/archive/2012-04/message/117

Which comes a month later after fixing:
issue #203986, issue #204613

Anyway I'll comment into #203986 and let's wait for JSF2.2 - what it will solve. ;)
Comment 9 Martin Fousek 2012-08-02 15:13:39 UTC
Jirko could I ask you for the verification please? Thanks in advance...
Comment 10 Jiri Skrivanek 2012-08-03 06:45:52 UTC
Verified in NetBeans IDE Dev (Build 201208030001) with the following steps:
- create java web project with CDI enabled targeting GlassFish server
- Generate entities from database (include all tables from sample DB)
- Create JSF pages from entities.
- run project
- edit and save an item from Customer table
Comment 11 Martin Fousek 2012-08-03 07:53:00 UTC
Thanks Jirko for the verification.

Transplanted into release72 branch:
releases #bde0e190768a : #215703 - java.lang.NullPointerException from getAsObject() when updating data in JSF page with Join Table EJB
releases #34e4a1649f64 : included patch1 related changes - #215703
Comment 12 Quality Engineering 2012-09-01 11:05:36 UTC
Integrated into 'releases', will be available in build *201209010822* or newer. Wait for official and publicly available build.
Changeset: http://hg.netbeans.org/releases/rev/bde0e190768a
User: Martin Fousek <marfous@netbeans.org>
Log: #215703 - java.lang.NullPointerException from getAsObject() when updating data in JSF page with Join Table EJB
(transplanted from 85471526855a0de5c5578ae8d653ba91569d34aa)