代码改变世界

How Oracle ADF Evaluates an EL Expression Without Specifying a Scope

2012-11-03 20:21  SimonLee  阅读(646)  评论(0编辑  收藏  举报

This article is about Unified EL(the spec is jsp.java.net/spec/jsp-2_1-fr-spec-el.pdf) and Oracle ADF.

it's a good habit to always specify a Scope for EL expressions in ADF or JSF, but how will it happen when not do this? Say set value to #{myValue}?

the short answer is: both JSF and ADF will search scopes from narrow to wider. If found then set the value. If not found JSF will create an object #{pageScope.myValue} while ADF will create an object #{requestScope.myValue}

If you want to know why please read ahead.

this class gives an answer for JSF:

 

javax.servlet.jsp.el.ScopedAttributeELResolver
Defines variable resolution behavior for scoped attributes.

This resolver handles all variable resolutions (where base is null. It searches PageContext.findAttribute() for a matching attribute. If not found, it will return null, or in the case of setValue it will create a new attribute in the page scope with the given name.

But ADF does NOT have a page scope.

ADF has viewScope, backingBeanScope, pageFlowScope, requestScope, sessionScope and applicationScope.

JSF has pageScope, requestScope, sessionScope, applicationScope.

they are NOT the same.

So problem comes when set a value to #{myValue} in ADF. Which scope to use when there's no pageScope? Oracle chooses the requestScope. They just chose it. Actually I found this by run a simple test ADF page. I haven't find any related topic or document about this choice, but if you know please tell me as well.

ADF scopes: http://docs.oracle.com/cd/E15523_01/web.1111/b31973/af_lifecycle.htm#ADFUI524

javax.servlet.jsp.el.ScopedAttributeELResolver: http://docs.oracle.com/cd/E17802_01/products/products/jsp/2.1/docs/jsp-2_1-pfd2/javax/servlet/jsp/el/ScopedAttributeELResolver.html