aspose file tools*
The moose likes JSP and the fly likes Nested JSP Expressions not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Nested JSP Expressions not working" Watch "Nested JSP Expressions not working" New topic
Author

Nested JSP Expressions not working

Paul Cooper
Greenhorn

Joined: Jan 30, 2006
Posts: 9
Newbie to the JavaRanch, though I've found a few solutions here before, so I thought I'd register.....

Been working through a custom simple tag using JSP 2.0, and after gleaning the proper way to configure my server to support JSP 2.0 and expressions, I've run into an issue I can't find a solution too.

The following tag code partially works:


My custom tag receives the protocol object (so I know that expressions are indeed working on this page), but the initial embedded custom tag evaluates as text (I see <pf id param='protocolIds'/> as the name of my control.

Also, the following code produces the same result: .

But this code, located one line above the previous failing line, works just fine, so the <pf> tag IS evaluating somewhere:

Anyone have any suggestions? I'm stumped.

-TR1
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

If you check the 'disable smiles' checkbox when you post, your tags will look a bit less sarcastic.

Your problem is that you are passing a custom tag as the attribute of another custom tag and expecting it to be evaluated. No can do.

In the following:



The value of the name attribute, <pf:pid param='protocolIds'/> is a string that is passed to the custom action as is.

The short of it: you can't use custom tags as attributes to custom tags.
[ January 30, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Cooper
Greenhorn

Joined: Jan 30, 2006
Posts: 9
Sorry about the smilies, and thanks for the reply. It explains why the <c:set> code didn't work either. So how do you get around this???

This particular case, the <pf:pid> tag generates the name of a framework template, which varies depending on the template currently being used. How else can I assign this value? That's why I tried the <c:set> tag, but of course it's the same problem. I'd really like to avoid hard-coding the template into the JSP. I can do it, but it ain't pretty.

-TR1
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Avoiding hard-coding in the JSP is a good thing to aspire to!

Whatever value the tag emits for you can be made available to the JSP -- and in a way that is tag attribute-friendly -- by creating a bean with a property that returns the value, or by creating an EL-function that you can use in the attribute value.

In either case, you would use the EL to reference the bean or function. In JSP 2.0, EL expressions can be used in any tag attribute that accepts run-time expressions.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1027
There are limited workarounds to this sort of thing.
1 - nest the value inside the tag. The <c:set> tag can be used like this:
<c:set var="checkboxName"><pf:pid param='protocolIds'/></c:set>

Obviously this will only work for one attribute.
But presumably you could rewrite the <premis:checkbox> tag to work like this.

2 - save the value in an attribute somewhere, and pass the attribute, or the name of the attribute to the tag.
<c:set var="checkboxName"><pf:pid param='protocolIds'/></c:set>
<premis:checkBox name="${checkBoxName}" object="${protocol}"/>

3: Shift the logic for the lookup of the name from a custom tag to a JSP tag function.
<premis:checkBox name="${myfn:lookup('protocolIds')}" object="${protocol}"/>

4: Put the logic for the lookup into the <premis:checkBox> function. Not as nice, but if it is your own tag library, you can do what you like with it. Maybe provide another attribute lookupName. If you provide "name" it uses the name as is. If you provide "lookupName" attribute, it looks up that value like the pf:pid tag does.

There are a few solutions off the top of my head.

Good luck,
evnafets
Paul Cooper
Greenhorn

Joined: Jan 30, 2006
Posts: 9
Bear,

You are the man, if there were any "Duke Dollars" (and maybe I've just committed my second faux pas on this site by mentioning those words) to give out, you'd get them all. I chewed on your last answer, googled some more, then the lightbulb went on, and my custom tag now works perfectly.

Thanks to this site for being here. I joined because it seemed like every time I did a search for something Java-problem-related, I'd find this site in the first twenty links.....

Here's a smiley, just because .....

-TR1
Paul Cooper
Greenhorn

Joined: Jan 30, 2006
Posts: 9
Darn it, Stephan, I missed seeing your reply until after I'd posted back to Bear. You've given me good food for thought. The <pf> tag I'm calling is a custom tag for a library I don't get source to (proprietary, I know, but "better minds" than mine decided this was the way to go). Your second suggestion was an extension of the first, and works perfectly. But Bear's comments made me start thinking about encapsulating more of the UI logic in the object being passed back in the request.

I've struggled with the new JSP stuff because I like to declare constants for all my UI controls in the servlet code, then reference the constants in the JSPs, but you can't put scriptlets inside expressions or tags.....so I couldn't use my constants. Now I'm thinking I should have getUIComponentName() methods that return the constant value, so I get the benefit of the constants, and can still use expressions.

Again, thanks for being here....this really helped move my project along.

-TR1
[ January 30, 2006: Message edited by: Paul Cooper ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Originally posted by Paul Cooper:
then reference the constants in the JSPs


Paul,

this JavaRanch Journal article was meant for you!
Paul Cooper
Greenhorn

Joined: Jan 30, 2006
Posts: 9
Bear, you are not just a bear amongst men, you are a BEAR amongst men. Thanks for the link to that article.....I'll cherish it always!!!

 
 
subject: Nested JSP Expressions not working