Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL + custom tags

 
Jorge Blaz
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I want to pass a dynamic property to a custom tag. I'm using JSTL 1.0 + Jsp 1.2

I've tried this, but none of the above seem to work:

<mytag:city postalCode="<c ut value='${myCode}' />" />
<mytag:city postalCode="${myCode}" />

Any ideas of how to do this?. (the "myCode" variable is stored in page context)

Thanks in advance.
Jorge
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JSP 2.0 your second example will work just fine since the EL is evaluated by the JSP container.

Under JSP 1.2 you're kinda stuck because the EL is only interpreted by the JSTL tags.

Here are some options:

1) Evaluate the EL expression within your tag using the JSTL API. I've not done this (since I use JSP 2.0) so I don't know how hairy it is.

2) Do something like:


where you tell the tag how to look up the value in the scoped variables.

3) Punt back to scriptlet expressions:



4) Upgrade to Tomcat 5 and JSP 2.0/JSTL 1.1.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Btw, your topic title would better have been "EL and custom tags".
 
Jorge Blaz
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best option would be number 1, but it will be hard to find examples
of how to do this.

Options 3 and 4 are good but I must use JSP 1.2 and I try to avoid scriptlets by using JSTL and custom tags.

So, i will try to do it with option 2.

Thanks for the help Bear, and you're right, the title should have been better EL and custom tags.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic