Monday, March 29, 2010

JSTL madness

I was working on a Java webapp that uses JSTL v1.2 when I hit this JSTL issue. It took me some time to find a work around. Here is the issue: I had a bean that exposes a property called "name". When I tried to output name in jsp using <c:out value="${myBean.name}" /> I always get my webapp context name. Then I came across this article where I saw "The expression language unifies the treatment of dot (.) and bracket ([]) operators. Therefore, ${customer.name} is equivalent to ${customer["name"]}." I tried <c:out value="${myBean["name"]}" /> and got the correct value in jsp. Still not sure why ${myBean.name} didn't work and ${myBean["name"]} worked.