views:

192

answers:

1

We've got an app that makes heavy use of JSTL expressions and custom taglibs, which means our pageContext attributes could have been set just about anywhere. How do I go about determining where they originated? Consider something like:

<c:out value="${ myObject['SOME_KEY'] }" />

I need to know where myObject came from -- how did it make its way into the pageContext? I am using IDEA, so if there is a shortcut for determining that within the IDE, it would be most helpful.

EDIT:

I don't want to know about the scope, but in what physical file the attribute was actually set. Almost identical to the Find Usages... functionality in the right-click context menu of IDEA. If I'm three includes deep into a JSP that might be using taglibs and templating, an attribute set within the pageContext could have been set just about anywhere. I would like to find usages and instances of that attribute.

+1  A: 

The ${myObject} basically resolves to jspContext.findAttribute("myObject") which searches for the attribute in respectively the page, request, session and application scopes and returns the first non-null value it finds.

How smart you can make an IDE, it cannot know beforehand (during build/compile) in which scope it is been set. There are too much factors (visible as well as invisible) which needs to be taken into consideration. The only reliable way to find this out is doing it programmatically by accessing the desired scopes explicitly during runtime:

"myObject" is in:
<br>Page scope? ${not empty pageScope.myObject}
<br>Request scope? ${not empty requestScope.myObject}
<br>Session scope? ${not empty sessionScope.myObject}
<br>Application scope? ${not empty applicationScope.myObject}

The above example should return true for one of the scopes where it is actually been set.

BalusC