Wednesday, January 18, 2012

ADF: Errors when prefix managed bean EL references with the scope name

As you can see in Oracle products documentation, managed beans can be referenced with scope prefix if they are defined in backingBeanScope, viewScope or pageFlowScope as these are custom ADFc scopes. Also requestScope and sessionScope are available.

<af:outputtext value="#{requestScope.MyBean.MyCityName}"/>


But accessing managed beans with expressions with scope prefix can potentially cause NPE errors.

For servlet scopes like request, session and application, using a prefix will cause NPE for when you access a managed bean that hasn't been instantiated before. So for all regular servlet scopes, don't use a prefix when accessing managed beans.

Scope prefixes doesn’t always work for beans in default Servlet scopes: requestScope, sessionScope, applicationScope. The prefix mechanism for servlet scopes bypasses JavaServer Faces managed bean facility:
  • Only looks for in-memory objects
  • Does not instantiate managed beans (it will cause NPE for when you access a managed bean that hasn't been instantiated before) 
  • Using this is only good idea if looking up memory attributes you know exist or you want to create
Scope prefixes works for ADF specific scopes: viewScope, pageFlowScope, backingBeanScope.
  • ADFc controller takes care of managed bean instantiation if configuration is available

No comments:

Post a Comment