« How-to protect your ADF pages | Main | Partition form updates with partial form submit using af:subform with ADF »
Gotchas when using memory scope prefixes in EL to access managed beans
By frank.nimphius | March 9, 2010
Interesting post on the Oracle JDeveloper Oracle internal mailing list, answered by Andrew Robinson. Accessing a managed bean in a standard servlet scope like sessionScope or requestScope using the scope as a prefix fails if the bean instance does not exist. Thus, bean reference like #{sessionScope.myBean} may fail while #{myBean} always succeeds. The reason for this is that #{sessionScope….} and #{requestScope…} reference a Map in memory and not the JSF framework.
But why would you want to use the memory scope as a prefix? If you reference an attribute in memory scope, then the search goes from smallest scope to broader scope, which means that if – by accident – there exist two objects with the same name and you wanted to access the object in the broader scope, chances are you access the wrong object. So prefixing the expression puts you on the save side. This however is only good to use when you access objects that already exist in memory (wich could be a previously instantiated managed bean – of course)
Managed beans must be instantiated before they become available in the memory scope, which means they need to be accessed through JSF. Luckily, JSF does not allow to configure two managed beans with the same name in different scopes. So even without a scope prefix, there is no risk that application code accidentally accesses the wrong object.
Note however that using ADFc specific scope like viewScope and pageFlowScope, a prefix of “pageFlowScope” or “viewScope” is required in the EL reference.
Frank
Topics: ADF Faces RC, Taskflow | No Comments »
Comments are closed.
