File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts tags and JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts tags and JSTL" Watch "Struts tags and JSTL" New topic

Struts tags and JSTL

James Falek

Joined: Dec 17, 2003
Posts: 6
Is it possible to use the JSTL expressons along with Struts tags? On a JSP page, I have a bean defined which contains a map of lists (with a Dynaform). I am able to successfully access the bean for non-struts items like the following:
<select name='sites' id='sites' >
<c:forEach items='${myBean.lists.sites}' var='siteName'>
<option value="<cut value='${siteName}'/>"> <cut value="${siteName}"/> </option>

However, when I try the following, I get an error:
<html:select property='sites'>
<htmlptions collection="${myBean.lists.sites}"/>
with the error stating:
Cannot find bean under name org.apache.struts.taglib.html.BEAN

Since the non-struts select works, I am wondering if something else is required to get Struts working with the JSTL expression language. I have also tried changing the options to the following:
<htmlptions collection="<cut value='${myBean.lists.sites}'/>"/>
Thank you.
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
Hi James,
There is a problem with nesting the jstl tags within the struts tags. Independently you can use them on a jsp page and it would not cause a problem but if you try to nest a jstl tag within a struts tag, the page would break. The reason is very historical, since jstl was written over struts tags, the jstl tags support them while as struts tags have no knowledge of the jstl syntax.

James Falek

Joined: Dec 17, 2003
Posts: 6
Thank you for the insight - unfortunate as it might be ;-(
Thanks again,
Andre Mermegas
Ranch Hand

Joined: Jun 20, 2001
Posts: 158
Actually, There is an extension to the struts-tags called struts-el, which allows you to resolve jstl expressions inside struts tags. It is in the contrib directory of your struts distribution.
it will allow you to do things like
<html-el:options collection="${myBean.lists.sites}"/>
[ December 17, 2003: Message edited by: Andre Mermegas ]

--=( Andre Mermegas )=--
Rick Hightower
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
I've used Struts EL tag lib on my last project. It is much more productive. You end up doing a lot less bean efine or c:set tags.
Once you use Struts EL, you will not go back to using regular Struts tags.

Rick Hightower is CTO of Mammatus which focuses on Cloud Computing, EC2, etc. Rick is invovled in Java CDI and Java EE as well. linkedin,twitter,blog
I agree. Here's the link:
subject: Struts tags and JSTL
jQuery in Action, 3rd edition