Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jason Roscoe
Trying to use JSTL forEach to display content
September 30, 2010 8:09 AM
Answer

Jason Roscoe

Rank: Junior Member

Posts: 76

Join Date: October 23, 2008

Recent Posts

I have a JSP portlet that creates a list of banners in the bean. Here is the code:
 1
 2public void doView(RenderRequest req, RenderResponse res)
 3        throws IOException, PortletException {
 4    System.out.println("inside doView");
 5   
 6    String saveALotGroupId = PropertiesFilesCache.getProperty(
 7            "save-a-lot.properties", "group.id", "No_Save_A_Lot_Group_Id_Property");                   
 8    SaveALotHomepageBanners banner = null;
 9    List<SaveALotHomepageBanners> bannerList = new ArrayList<SaveALotHomepageBanners>(100);
10    try {
11        List<JournalArticle> journalArticlesList = JournalArticleLocalServiceUtil.getArticles(Long.parseLong(saveALotGroupId));
12        if (journalArticlesList != null) {
13            System.out.println("articles is not null: " + journalArticlesList.size());
14            Iterator<JournalArticle> journalArticlesIterator = journalArticlesList.iterator();
15            while (journalArticlesIterator.hasNext()) {
16                System.out.println("inside articlesIterator");
17                JournalArticle journalArticle = journalArticlesIterator.next();
18                String articleType = journalArticle.getType();
19                System.out.println("articleType: " + articleType);
20                if (articleType.equalsIgnoreCase("save-a-lot-slider")) {
21                    String articleId = journalArticle.getArticleId();
22                    System.out.println("articleId: " + articleId);
23                    boolean articleApproved = journalArticle.getApproved();
24                    if (articleApproved) {
25                        JournalArticle article = JournalArticleLocalServiceUtil.getArticle(Long.parseLong(saveALotGroupId), articleId);
26                        String image = JournalContentUtil.getValue(article, "image");
27                        System.out.println("image: " + image);
28                        String imageAltText = JournalContentUtil.getValue(article, "image-alt-text");
29                        System.out.println("imageAltText: " + imageAltText);
30                        String imageLink = JournalContentUtil.getValue(article, "image-link");
31                        System.out.println("imageLink: " + imageLink);
32                        String imageLinkWindow = JournalContentUtil.getValue(article, "image-link-window");
33                        System.out.println("imageLinkWindow: " + imageLinkWindow);
34                        String order = JournalContentUtil.getValue(article, "order");
35                        System.out.println("order: " + order);
36                           
37                        banner = new SaveALotHomepageBanners();
38                        banner.setImage(image);
39                                                banner.setImageAltText(imageAltText);
40                        banner.setImageLink(imageLink);
41                        banner.setImageLinkWindow(imageLinkWindow);
42                        banner.setOrder(order);
43                        bannerList.add(banner);
44                    }
45                }
46            }
47        }
48            
49    } catch(Exception e) {
50        _log.error(e);
51    }
52       
53    req.setAttribute("banners", bannerList);            
54    include(viewJSP, req, res);       
55}

In my JSP, I am trying to use the <c:forEach> JSTL tag to loop through each list item and display it. JSP code below:
 1
 2<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 3
 4<portlet:defineObjects />
 5
 6<div id="save-a-lot-rotator" class="save-a-lot-rotator">
 7    <ul>
 8        <c:forEach var="banners" items="${banners}">
 9            <li><a href="<c:out value="${banners.imageLink}">"><img src="<c:out value="${banners.image}">" alt="<c:out value="${banners.imageAltText}">" /></a></li>
10        </c:forEach>
11    </ul>
12    <ul class="number_slideshow_nav">
13        <li><a href="#">1</a></li>
14        <li><a href="#">2</a></li>
15        <li><a href="#">3</a></li>
16        <li><a href="#">4</a></li>
17    </ul>
18    <div style="clear: both"></div>
19</div>

What is getting displayed in the source code when viewing the page in the browser is:

<c:forEach var="banners" items="${banners}">
<li><a href="<c:out value="${banners.imageLink}">"><img src="<c:out value="${banners.image}">" alt="<c:out value="${banners.imageAltText}">" /></a></li>
</c:forEach>

How can I get this working?

Thanks!!
Felix Ashirov
RE: Trying to use JSTL forEach to display content
September 30, 2010 8:58 AM
Answer

Felix Ashirov

Rank: Regular Member

Posts: 128

Join Date: February 26, 2010

Recent Posts

It seems that you haven't declared the JSTL-taglib usage in your JSP

1<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Jelmer Kuperus
RE: Trying to use JSTL forEach to display content
September 30, 2010 9:19 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

also add

<%@ page isELIgnored ="false" %>
Jason Roscoe
RE: Trying to use JSTL forEach to display content
September 30, 2010 10:10 AM
Answer

Jason Roscoe

Rank: Junior Member

Posts: 76

Join Date: October 23, 2008

Recent Posts

Felix Ashirov:
It seems that you haven't declared the JSTL-taglib usage in your JSP

1<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

I've already tried adding that to the page, and when I try to go to the page with that in it, I get the below Exception. I have checked the web.xml file in ext-web, and it does have the jstl tld's referenced there, which is why I thought I didn't need it in my page. also, as an fyi, we are currently on Liferay 5.1.2.

web.xml:
1
2<taglib>
3    <taglib-uri>http://java.sun.com/jstl/core_rt</taglib-uri>
4    <taglib-location>/WEB-INF/tld/c-rt.tld</taglib-location>
5</taglib>

Exception:
ERROR Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116)
at org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:315)
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:148)
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:420)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:476)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1426)
at org.apache.jasper.compiler.Parser.parse(Parser.java:133)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:687)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:590)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:505)
at com.liferay.portlet.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:302)
at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:122)
at com.riteaid.SaveALotHomepageBannerRotator.include(SaveALotHomepageBannerRotator.java:89)
at com.riteaid.SaveALotHomepageBannerRotator.doView(SaveALotHomepageBannerRotator.java:76)
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.sun.portal.portletcontainer.appengine.filter.FilterChainImpl.doFilter(FilterChainImpl.java:121)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:69)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:96)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:687)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:590)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:505)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:575)
at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:646)
at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:414)
at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1383)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:687)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:590)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:505)
at com.liferay.portal.util.PortalImpl.renderPortlet(PortalImpl.java:2433)
at com.liferay.portal.util.PortalUtil.renderPortlet(PortalUtil.java:785)
at com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil.processPortlet(RuntimePortletUtil.java:171)
at com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil.processPortlet(RuntimePortletUtil.java:104)
at com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil.processTemplate(RuntimePortletUtil.java:295)
at com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil.processTemplate(RuntimePortletUtil.java:196)
at org.apache.jsp.html.portal.layout.view.portlet_jsp._jspService(portlet_jsp.java:810)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:687)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:590)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:505)
at com.liferay.portal.action.LayoutAction.includeLayoutContent(LayoutAction.java:277)
at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:450)
at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:189)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:164)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:443)
at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:708)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:687)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:403)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:144)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:132)
at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:117)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:132)
at com.liferay.portal.servlet.filters.compression.CompressionFilter.processFilter(CompressionFilter.java:141)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:132)
at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:282)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:132)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:74)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:132)
at com.liferay.portal.servlet.filters.layoutcache.LayoutCacheFilter.processFilter(LayoutCacheFilter.java:395)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:132)
at com.riteaid.portal.servlet.filters.SecureAccessFilter.processFilter(SecureAccessFilter.java:193)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:132)
at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:199)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:687)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:403)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.doFilter(VirtualHostFilter.java:264)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:132)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:74)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:132)
at com.riteaid.portal.servlet.filters.LogoutFilter.processFilter(LogoutFilter.java:136)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Jelmer Kuperus
RE: Trying to use JSTL forEach to display content
September 30, 2010 10:30 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

Add the following lines to docroot/WEB-INF/liferay-plugin-package.properties

portal-dependency-jars=\
jstl-api.jar,\
jstl-impl.jar



Your jsp should look like this


<%@ page isELIgnored ="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<c:out value="${1+1}"/>
Jason Roscoe
RE: Trying to use JSTL forEach to display content
September 30, 2010 11:00 AM
Answer

Jason Roscoe

Rank: Junior Member

Posts: 76

Join Date: October 23, 2008

Recent Posts

I still got the exact same error. Here is my code:

JSP file:
 1
 2<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 3<%@ page isELIgnored ="false" %>
 4<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 5
 6<portlet:defineObjects />
 7
 8<div id="save-a-lot-rotator" class="save-a-lot-rotator">
 9    <ul>
10        <c:forEach var="banners" items="${banners}">
11            <li><a href="<c:out value="${banners.imageLink}">"><img src="<c:out value="${banners.image}">" alt="<c:out value="${banners.imageAltText}">" /></a></li>
12        </c:forEach>       
13    </ul>
14    <ul class="number_slideshow_nav">
15        <li><a href="#">1</a></li>
16        <li><a href="#">2</a></li>
17        <li><a href="#">3</a></li>
18        <li><a href="#">4</a></li>
19    </ul>
20    <div style="clear: both"></div>
21</div>

liferay-plugin-package.properties:
 1
 2name=Banner Rotator
 3module-group-id=liferay
 4module-incremental-version=1
 5tags=
 6short-description=
 7change-log=
 8page-url=http://www.liferay.com
 9author=Liferay, Inc.
10licenses=MIT
11portal-dependency-jars=\
12jstl-api.jar,\
13jstl-impl.jar
Felix Ashirov
RE: Trying to use JSTL forEach to display content
September 30, 2010 10:15 PM
Answer

Felix Ashirov

Rank: Regular Member

Posts: 128

Join Date: February 26, 2010

Recent Posts

Try to add JSTL jars into your project so it would be deployed within your application war.
Download here
Jelmer Kuperus
RE: Trying to use JSTL forEach to display content
October 1, 2010 4:22 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

That's what adding portal-dependency-jars does, it will ensure that liferay adds the jstl jars to the portlet classpath at deploytime
Jason Roscoe
RE: Trying to use JSTL forEach to display content
October 1, 2010 4:30 AM
Answer

Jason Roscoe

Rank: Junior Member

Posts: 76

Join Date: October 23, 2008

Recent Posts

That's what I thought too, but it doesn't seem to be doing that, as I still get the exception above with portal-dependency-jars set.

I did put the jstl jars in my lib folder for my portlet, and now I am getting the below error:

ERROR Servlet.service() for servlet savealothomepagebannerrotatorportlet threw exception
org.apache.jasper.JasperException: /view.jsp(11,5) The end tag "&lt;/c:forEach" is unbalanced

Is there something wrong with my forEach code:
1
2<c:forEach var="banners" items="${banners}">
3    <li><a href="<c:out value="${banners.imageLink}">"><img src="<c:out value="${banners.image}">" alt="<c:out value="${banners.imageAltText}">" /></a></li>
4</c:forEach>

I'd like to get it working without having to have the jars in my portlets lib directory, but is there also something wrong with my forEach code?

Thanks!!
Jelmer Kuperus
RE: Trying to use JSTL forEach to display content
October 1, 2010 4:46 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

You do not close your c:out tag


1 <c:out value="${banners.imageAltText}">


should be

1<c:out value="${banners.imageAltText}"/>
Jason Roscoe
RE: Trying to use JSTL forEach to display content
October 1, 2010 5:03 AM
Answer

Jason Roscoe

Rank: Junior Member

Posts: 76

Join Date: October 23, 2008

Recent Posts

Duh, my mistake, sorry for that.

It's working now, but I still have the jstl jars in my portlets lib directory.
Felix Ashirov
RE: Trying to use JSTL forEach to display content
October 1, 2010 5:09 AM
Answer

Felix Ashirov

Rank: Regular Member

Posts: 128

Join Date: February 26, 2010

Recent Posts

Well, it should not be a problem if it works. In practise I never use "portal-dependency-jars" property because of unstable behavior.

In my opinion, application should be packaged with all depencies (except of Liferay API impl). This is more reliable.
Jelmer Kuperus
RE: Trying to use JSTL forEach to display content
October 1, 2010 6:54 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

Well i am not sure about the unstable part considering the portlets in liferay's own plugin repository make heavy use of it

Jelmer-Kuperuss-MacBook:portlets jelmerkuperus$ find . -name "liferay-plugin-package.properties" -exec grep portal-dependency-jars {} \; | wc -l
54


However if you want your portlet to be independent of liferay, then adding it to the classpath is what you want to do. if not, then this is a nice way to save a few kb
Felix Ashirov
RE: Trying to use JSTL forEach to display content
October 1, 2010 7:12 AM
Answer

Felix Ashirov

Rank: Regular Member

Posts: 128

Join Date: February 26, 2010

Recent Posts

In my practice few kb does not save my time installing into some Liferay Portal servers (we are supporting 5 Liferay portals installed onto different application servers: Glassfish, Tomcat etc).
Mohamed Rizwanuzaman
RE: Trying to use JSTL forEach to display content
March 27, 2012 6:20 AM
Answer

Mohamed Rizwanuzaman

Rank: New Member

Posts: 20

Join Date: December 16, 2009

Recent Posts

HI JElmer,

I had tried to use the jstl tag for looping a list.
this is my code

List<Employee> employeeList = DepartmentLocalServiceUtil.getDepartmentEmployees(departmentId);
<c:forEach var="myValue" items="${employeeList}" >
<c:out value="${myValue.employeeName}"></c:out>
</c:forEach>


And i have include the c.tld and jstl.jar in liferay-plugin-package.properties but its not working ,
Below is the error i facing
 1
 213:13:57,455 ERROR [render_portlet_jsp:154] org.apache.jasper.JasperException: /view.jsp (line: 42, column: 0) According to TLD or attribute directive
 3 in tag file, attribute items does not accept any expressions
 4        at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
 5        at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:408)
 6        at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:149)
 7        at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1235)
 8        at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:870)
 9        at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539)
10        at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
11        at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
12        at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
13        at org.apache.jasper.compiler.Node$Root.accept(Node.java:475)
14        at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
15        at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1790)
16        at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:217)
17        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
18        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
19        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
20        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
21        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
22        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
23        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)


kindly let me know the solution to use the jstl tag.

Thanks in advance


Regards,
Rizwan
Jelmer Kuperus
RE: Trying to use JSTL forEach to display content
March 28, 2012 2:40 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

You are probably using

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

Instead of

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>