Thursday, September 8, 2011

Another Way to Invoke Managed Bean Method

Typically we are calling managed bean methods through expression language in Oracle ADF. Depending on use case, it may by useful to know how to call managed bean method directly by acquiring instance of that bean.

My example contains session scope bean:


This bean implements collection of elements and contains one method to retrieve collection element by code - getElementName(String):


This method accepts parameter and returns value, how we would invoke such method from another bean? There are several options, one of them is to acquire managed bean instance and call method directly - AccessingBeanInstance.zip sample application for this post.

As we can see in this example, with JSFUtils helper method bean instance is being retrieved. If its first access, bean will not be instantiated yet, so we need to create new instance. Once instance is created, we can call custom method and store same instance in session scope - so it will be reused for future requests:


1 comment:

mahdi joafshani said...

Really helpful, thanks for the post.