This page demonstrates the <wtfigo:displayObject> tag. This tag can be used to help you determine what properties of your bean are displayable using JSTL, what values exist, and what the JSTL EL syntax is to get at them. This is especially useful for nested, mapped, and indexed properties.
This example puts a sample bean (org.wtfigo.demo.SampleBean1) into the session and request scopes under the keys "mySessionScopeBean" and "myRequestScopedBean". The sample bean has various types of properties including scalar, mapped, and indexed properties.
First, here is what happens if you use the wrong name for the bean. See the demo
of <wtfigo:attributes/> to see how to make sure you've got the right key.
Output of <wtfigo:displayObject
name="unknownBean" />
WTFIGO:displayObject
The object named 'unknownBean' could not be found in any scope.
Try using the <wtfigo:attributes> tag to identify the known variables
With a bean that can be found, the name, scope, and class of the bean is displayed along with the
properties and values. This example also shows the EL that is used.
Output of <wtfigo:displayObject
name="myRequestScopedBean" showEL="true" />
WTFIGO:displayObject
Object name: 'myRequestScopedBean' was found in the REQUEST scope.
JSTL EL Usage: ${requestScope.myRequestScopedBean} or ${requestScope['myRequestScopedBean']}
ClassName: org.wtfigo.demo.pojo.SampleBean1
| Property | Type | Value | JSTL EL |
|---|---|---|---|
| date | java.util.Date | Thu Aug 21 10:28:59 PDT 2008 | ${requestScope.myRequestScopedBean.date} |
| intArray | int[] | [1,2,3,4,5] | ${requestScope.myRequestScopedBean.intArray} |
| list | java.util.List | [element1, element2, element3] | ${requestScope.myRequestScopedBean.list} |
| map | java.util.Map | {key1=value1, key3=value3, key2=value2} | ${requestScope.myRequestScopedBean.map} |
| sampleBean2 | org.wtfigo.demo.pojo.SampleBean2 | SampleBean2: string1=String1;string2=String2 | ${requestScope.myRequestScopedBean.sampleBean2} |
| string1 | java.lang.String | String1 | ${requestScope.myRequestScopedBean.string1} |
| string2 | java.lang.String | String2 | ${requestScope.myRequestScopedBean.string2} |
| stringArray | java.lang.String[3] | [one, two, three] | ${requestScope.myRequestScopedBean.stringArray} |
For nested objects, mapped, and indexed properties, the JSTL EL can get tricky. This example shows
the output to the depth of 2 layers
Note: Display needs to be improved and need to filter simple objects like Dates and Strings
Output of <wtfigo:displayObject
name="myRequestScopedBean3" showEL="true" depth="2" />
WTFIGO:displayObject
Object name: 'myRequestScopedBean3' was found in the REQUEST scope.
JSTL EL Usage: ${requestScope.myRequestScopedBean3} or ${requestScope['myRequestScopedBean3']}
ClassName: org.wtfigo.demo.pojo.SampleBean3
| Depth | Property | Type | Value | JSTL EL |
|---|---|---|---|---|
| 0 | sampleBean1 | org.wtfigo.demo.pojo.SampleBean1 | SampleBean1: string1=String1;string2=String2;map={key1=value1, key3=value3, key2=value2};sampleBean... | ${requestScope.myRequestScopedBean3.sampleBean1} |
| 1 | sampleBean1.date | java.util.Date | Thu Aug 21 10:28:59 PDT 2008 | ${requestScope.myRequestScopedBean3.sampleBean1.date} |
| 1 | sampleBean1.intArray | int[] | [1,2,3,4,5] | ${requestScope.myRequestScopedBean3.sampleBean1.intArray} |
| 1 | sampleBean1.list | java.util.List | [element1, element2, element3] | ${requestScope.myRequestScopedBean3.sampleBean1.list} |
| 1 | sampleBean1.map | java.util.Map | {key1=value1, key3=value3, key2=value2} | ${requestScope.myRequestScopedBean3.sampleBean1.map} |
| 1 | sampleBean1.sampleBean2 | org.wtfigo.demo.pojo.SampleBean2 | SampleBean2: string1=String1;string2=String2 | ${requestScope.myRequestScopedBean3.sampleBean1.sampleBean2} |
| 2 | sampleBean1.sampleBean2.string1 | java.lang.String | String1 | ${requestScope.myRequestScopedBean3.sampleBean1.sampleBean2.string1} |
| 2 | sampleBean1.sampleBean2.string2 | java.lang.String | String2 | ${requestScope.myRequestScopedBean3.sampleBean1.sampleBean2.string2} |
| 1 | sampleBean1.string1 | java.lang.String | String1 | ${requestScope.myRequestScopedBean3.sampleBean1.string1} |
| 1 | sampleBean1.string2 | java.lang.String | String2 | ${requestScope.myRequestScopedBean3.sampleBean1.string2} |
| 1 | sampleBean1.stringArray | java.lang.String[3] | [one, two, three] | ${requestScope.myRequestScopedBean3.sampleBean1.stringArray} |
| 0 | string1 | java.lang.String | String1 | ${requestScope.myRequestScopedBean3.string1} |
| 0 | string2 | java.lang.String | String2 | ${requestScope.myRequestScopedBean3.string2} |
| 0 | string3 | java.lang.String | String3 | ${requestScope.myRequestScopedBean3.string3} |