Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts tags and JSTL

 
James Falek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
</c:forEach>
</select>

However, when I try the following, I get an error:
<html:select property='sites'>
<htmlptions collection="${myBean.lists.sites}"/>
</html:select>
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
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Sahil
 
James Falek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the insight - unfortunate as it might be ;-(
Thanks again,
James
 
Andre Mermegas
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Rick Hightower
Author
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic