Derek Shen's Article - Does JSF still have problems with startup methods?

Hi,

I've been following this article as the base to learn JSF and the integration between Hibernate and Spring. The author mentioned about the workaround to startup methods in the JSF using init() (or whatever), and IoC, since JSF doesn't support this startup feature.

The article is from 2004, is there any enhancement or better approach on that? BTW, are the techniques used in this article a good path for who is still learning the whole architecture?

http://www.javaworld.com/javaforums/showflat.php?Cat=0&Number=10690&an=0&page=0#Post10690

I already took a look in the Appfuse, which is much better. However, this article is really good as well to get started on those technologies and architecture.

Regards.

[765 byte] By [Distillinga] at [2007-10-3 10:08:23]
# 1

"JSF bean management facility lacks of the life cycle management concept of the managed bean. Ideally, JSF should allow us to specify a starup (init) method - invoked after the constructor is called and all the attributes are set"

Please, I still need to know if I have to follow this workaround or there are better solutions.

Thanks.

Distillinga at 2007-7-15 5:28:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

This is still the case, at least with JSF 1.1.

See How do I know when a managed bean's properties have all been set? in the MyFaces FAQ (http://wiki.apache.org/myfaces/FAQ).

You may also want to look at the Shale View Controller (http://shale.apache.org/shale-view/index.html).

I haven't used JSF 1.2 but I think you may be able to use @PostConstruct and @PreDestroy annotations on managed beans with it.

guy.colemana at 2007-7-15 5:28:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Thank you very much for your clarification. I'll take a look in the references. Regards.
Distillinga at 2007-7-15 5:28:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hi,

I tried that solution but didn't work. It throws this error:

07:01:32,029 ERROR ApplicationImpl:870 - Can't set managed bean property: 'initialized'.

javax.faces.FacesException: Can't set managed bean property: 'initialized'.

at com.sun.faces.config.ManagedBeanFactory.setPropertiesIntoBean(ManagedBeanFactory.java:510)

I also created the method "public void setInitialized(boolean b)" in my classes declared in the managed beans.

Could you help me please?!

Thanks.

null

Distillinga at 2007-7-15 5:28:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Is there a root cause to that exception? Please post the full stack trace.
guy.colemana at 2007-7-15 5:28:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

There you go. I hope it can give you a clue:

Thanks. Regards.

07:01:32,029 ERROR ApplicationImpl:870 - Can't set managed bean property: 'initialized'.

javax.faces.FacesException: Can't set managed bean property: 'initialized'.

at com.sun.faces.config.ManagedBeanFactory.setPropertiesIntoBean(ManagedBeanFactory.java:510)

at com.sun.faces.config.ManagedBeanFactory.newInstance(ManagedBeanFactory.java:162)

at com.sun.faces.application.ApplicationImpl.createAndMaybeStoreManagedBeans(ApplicationImpl.java:863)

at com.sun.faces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:79)

at com.sun.faces.el.impl.NamedValue.evaluate(NamedValue.java:120)

at com.sun.faces.el.impl.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:238)

at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:155)

at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:136)

at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:123)

at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)

at javax.faces.component.UICommand.broadcast(UICommand.java:312)

at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:266)

at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:380)

at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)

at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)

at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)

at mypackage.Filter.doFilter(Unknown Source)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)

at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)

at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)

at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:1789)

at com.sun.faces.config.ManagedBeanFactory.setPropertiesIntoBean(ManagedBeanFactory.java:492)

... 33 more

Caused by: javax.faces.FacesException: Could not initialize XXXListBean

at mypackage.XXXListBean.setInitialized(Unknown Source)

... 39 more

Caused by: java.lang.NullPointerException

... 40 more

Distillinga at 2007-7-15 5:28:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
The root cause is at the bottom: java.lang.NullPointerException.What work are you doing in setInitialized()? Could it throw an NPE?
guy.colemana at 2007-7-15 5:28:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
I'm getting the information from the DAO and put in a list of beans or in a bean alone(backing bean). Using the init method works perfectly. I am sorry, what's NPE? You can see the complete source code in the article I sent.
Distillinga at 2007-7-15 5:28:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...