Question

I'm using Java 1.6, Spring 3.4, Spring Webflow 2.3.2 and Tomcat 7. I'm trying to debug a JSP page which uses EL expressions like:

<c:if test="${myObject.myThing == SomeClass.ENUMVALUE.myvalue}"  >

The myObject object is passed in as the Webflow model object. I have a breakpoint set on this line and I am able to reach it and break on it, but anything I try to "watch" or "evaluate" gives me an error message. I get either

${myObject.myThing == SomeClass.ENUMVALUE.myvalue}:  Invalid Expression

myObject.myThing:  Type is unknown for 'myObject'

(MyCorrectType) myObject:  Cannot find local variable 'myObject'

How the heck can I find this model object? What is it contained in by the time it reaches the JSP page?

Was it helpful?

Solution

The answer turned out to be that it will be in the org.apache.catalina.connector.Request object (In my particular case, it was buried several levels deep inside wrapper objects.)

If you are using a debugger, like the one in Intellij (which I use), you can get the value of an individual attribute (like the Webflow model object) by evaluating the expression request.getAttribute("attributeName"). Note that this may return a Java Object type, and you may have to cast it to the correct type.

For example, in my case, I was able to find the value of the value I wanted using this expression:

((MyObject)(request.getAttribute("myObject"))).getMyThing()

I hope this helps somebody.

OTHER TIPS

In IDEA 2016.2 request in JSP debug doesn't work anymore:(

It is possible to get attribute as

_jspx_page_context.request.getAttribute("...")

(inside tag as parentTag.requestContext.request.getAttributeNames())

It's also possible add in project dependency on jasper with provided scope:

    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>jasper</artifactId>
        <version>6.0.47</version>
        <scope>provided</scope>
    </dependency>

and use auto completion:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top