Friday Mar 28, 2008

It's late on a Friday and I've just solved a JSF headache, so I'm going to quickly write this up while it's still fresh in my mind (the solution, not the headache).

You may have stumbled onto this message if you're developing in JSF or just vanilla JSP:

#{..} is not allowed in template text

When you Google this phrase, you'll find various chunks of advice around versions of JSP, deferred expressions and the Unified Expression Language that comes with JSP 2.1. In particular, this reference appeared to have the definitive fix for my problem: either change the "#{" to "${", or backslash-escape the "#{" sequence, or change a setting to allow deferred syntax as literal. Now, any or all of these solutions might work for you, depending on your context; but I write this up because none of them worked for me.

What I have is a web application developed with JSF 1.1 that had used JSTL 1.1, but that then got deployed into a Java EE 5 environment which provides JSF 1.2 and JSTL 1.2. Many of you already know where this is going. But for my own future reference and possibly your amusement, I'm going to write it up anyway.

I changed all occurrences of #{ to ${, and knowing that Java EE 5 servers already supply the correct JSTL 1.2 version, I removed my webapp's private copies of jstl.jar and standard.jar (vestiges from when they were needed, with J2EE 1.4 servers), but now I get this error message:

According to TLD or attribute directive in tag file, attribute rendered does not accept any expressions

So the syntax change was a head-fake, at least in my case; I can't explain why. You are invited to chime in if you understand it. I was referred to one useful discussion that contains various suggested solutions and references various other threads, and it got me on the right track. Here's what I ended up doing: first, change the ${ back to #{, since really getting the incorrect JSTL version out of the way is the true fix. There is also an EL expression factory workaround discussed in that thread which was applied to my deployment descriptor.

But, here's where it gets interesting (as if it isn't already drop-dead compelling, right?) -- although removing the JSTL 1.1 stuff, applying the DD workaround and reverting back to #{ syntax should have cured all my problems, now I get an EL parsing error concerning this particular attribute construction:

text="#{dds.value.enabled?isnsMsg.deactivate_action:isnsMsg.activate_action}"

This is a boolean expression managing a text value that must change depending on the state of a given backing bean property; this had worked just fine in my JSF 1.1 deployment, but now it's no good. The error reads something like this:

Was expecting one of:
    "(" ...
    <IDENTIFIER> ...
    <NAMESPACE> <IDENTIFIER> "(" ...

Without belaboring the point - since I have a headache from all the different things I tried - I'll just admit it: I took the inelegant way out and used two panel-grouping blocks, each with its own rendered-if attribute, to fix this problem:

<ui:panelGroup rendered="#{dds.value.enabled}">
    <ui:hyperlink text="#{isnsMsg.deactivate_action}"/>
</ui:panelGroup>
                                               
<ui:panelGroup rendered="#{!dds.value.enabled}">
    <ui:hyperlink text="#{isnsMsg.activate_action}"/>
</ui:panelGroup>


Using JSTL IF and WHEN testing is just as ugly, but at least it fails to work. The JSTL expressions get evaluated too soon relative to the JSF lifecycle, i.e. the IF and WHEN always yield false since they're evaluated before the backing bean property gets its value set as needed.

I didn't do any research to understand why the inline boolean expression in JSF 1.1 caused a parsing error in JSF 1.2 (or maybe it's a JSP 1.2 vs JSP 2.0 thing...hey, probably it's JSTL 1.1 vs 1.2...isn't web-tier fun?). So while I've solved the immediate problem, I've left plenty of room for colleagues to elaborate and, frankly, to correct me where I'm misleading. Like I say, it's late on a Friday and sometimes I do as little as necessary to get from A to Z. If anyone has additional insights around what's discussed here, you are invited to share.

Monday Oct 01, 2007

Our son's 1st birthday is today. This is difficult to believe. How is it that all of these children I know are growing up so fast, while I don't age at all? At least my friends tell me I look the same as I ever did. Hmmm...maybe it's like my Dad once said about his girlfriend-at-the-time (settle down - he was single-at-the-time), "She looks pretty good to me, but you know my vision just isn't that good anymore...".

Aimee is taking him to bed now (our son, not my Dad; puh-leeze settle down), and he's waving buh-bye to me as they go upstairs. I'm reasonably certain this is the cutest kid ever. Judge for yourself, here's a candid shot:

Connor Michael Our boy's name is Connor. Connor Michael. He sports a keen fashion sense, no?

Connor lives with two Huskies (he's part of a pack...). Now, as Connor knows, Huskies are the kind of dog where you have to be in the mood for adventure. So, for example, whenever we go to some new dog park, their first move is to check the boundaries - hoping, as it were, not to find any. There was this time we entered a dog park via a double-lock gate...which would seem to add a certain sense of security...I mean, once you enter through a double-lock gate, what's the worst that could happen? Moments later, my smug self-assurance turns to horror: they've noticed the dog park lacks a fence on one side. A dog park...entered by a double-lock gate...but enclosed on only three sides. Lending new meaning to the sign outside the park: "Boulder County Open Space".

On the plus side, it was an opportunity for heart rate zones 4 and 5, if you catch my meaning. Since then, I do a perimeter sweep before entering unfamiliar dog parks - just some insurance that I'll leave with the same number of Huskies I came with.

So, "perimeter sweeps". That's what Connor does, it's what the Huskies do, and now it's what I do. Check the boundaries, find a way to get outside the box, but first confirm there is a box. Balance is essential for everyone's best interests.

More on double-lock gates later. It's my son's first birthday. Wow.

This blog copyright 2008 by Gary Horton