HOME - Recent Changes - Search:

Academic Work


Personal

* pot de départ


dblp


(:twitter:)

-----

[ edit | logout ]
[ help | sandbox | passwd ]

Using JSTL in portlets

#############################

Contents

  • How to integrate JSTL support to your portlets?
    • This also includes how to add third-party JARs.
  • How to re-use those JARs that are included in Liferay?
  • Which JARs are available by default if you use the Liferay SDK?

Goal

You want to use JSTL tags in your (Liferay) portlets. For instance, you want to write the following JSP code:

<c:forEach var="i" begin="1" end="10" step="1">
    <c:out value="${i}" />
    <br />
</c:forEach>

Steps

Example JSP code:


<!--{start:calendar-portlet/view.jsp}-->
<%@ page session="false" %>
<%@ page import="javax.portlet.*"%>

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

<b>Calendar view</b>
<br />

<c:forEach var="i" begin="1" end="10" step="1">
    <c:out value="${i}" />
    <br />
</c:forEach>

<!--{end:calendar-portlet/view.jsp}-->

In WEB-INF/lib/, add the following JARs:

jstl-impl.jar  
jstl.jar

UPDATE: don't copy these JARs to the lib folder! There is a better solution that I explain at the end under the section Update.

In WEB-INF/tld/, add the following 8 files:

c-rt.tld
c.tld
fmt-rt.tld
fmt.tld
sql-rt.tld
sql.tld
x-rt.tld
x.tld

Edit your WEB-INF/web.xml to add the following 8 taglib entries:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  <taglib>
    <taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
    <taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/fmt-rt.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
    <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/c-rt.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
    <taglib-location>/WEB-INF/tld/sql.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/sql-rt.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
    <taglib-location>/WEB-INF/tld/x.tld</taglib-location>
  </taglib>

  <taglib>
    <taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
    <taglib-location>/WEB-INF/tld/x-rt.tld</taglib-location>
  </taglib>
</web-app>

Further readings


Update

I found an interesting post at http://www.robisoft.com/building-sdk-portlets/ . To sum it up: look at the tomcat/webapps/ROOT/WEB-INF/lib directory. The JARs that are located here are used by Liferay and you can also use them in your portlets by putting a reference to them! So it means that you don't have to copy them to your portlet's lib directory. Actually, if you copy them it can lead to problems if the two JAR files have different versions. So the best solution is the following:

  • Choose the JAR files in tomcat/webapps/ROOT/WEB-INF/lib that you need.
  • Edit the liferay-plugin-package.properties file in your portlet's directory by adding the chosen JARs.

A concrete example:

name=Parameters
module-group-id=liferay
module-incremental-version=1
tags=
short-description=
change-log=
page-url=http://www.liferay.com
author=Liferay, Inc.
licenses=MIT

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

The new thing is the portal-dependency-jars part.

The mechanism is the following: "During the build, those jars are temporarily copied to the porlet lib area and deleted afterwards. During deployment, those jars are copied from Liferay’s lib folder to the deployed portlet lib folder." (http://www.robisoft.com/building-sdk-portlets/)


Appendix A

In Liferay 5.2.3, you can find the following JARs in tomcat/webapps/ROOT/WEB-INF/lib:

ant.jar
antlr.jar
aopalliance.jar
asm-attrs.jar
asm.jar
aspectj-rt.jar
aspectj-weaver.jar
axis-ant.jar
axis.jar
backport-concurrent.jar
bsf.jar
burlap.jar
c3p0.jar
casclient.jar
ccpp-ri.jar
cglib.jar
chardet.jar
commons-beanutils.jar
commons-codec.jar
commons-collections.jar
commons-configuration.jar
commons-dbcp.jar
commons-digester.jar
commons-discovery.jar
commons-email.jar
commons-fileupload.jar
commons-httpclient.jar
commons-id.jar
commons-io.jar
commons-lang.jar
commons-logging.jar
commons-math.jar
commons-pool.jar
commons-validator.jar
compass.jar
concurrent.jar
creolefilter.jar
crypt.jar
daim.jar
displaytag.jar
dom4j.jar
easyconf.jar
ecs.jar
ehcache.jar
freemarker.jar
freshcookies-security.jar
friki.jar
gif89.jar
gt-coverage.jar
gt-metadata.jar
hessian.jar
hibernate3.jar
htmlparser.jar
ical4j.jar
icq.jar
jabsorb.jar
jackrabbit-api.jar
jackrabbit-core.jar
jackrabbit-jcr-commons.jar
jackrabbit-spi-commons.jar
jackrabbit-spi.jar
jackrabbit-text-extractors.jar
jai_codec.jar
jai_core.jar
java-diff.jar
jaxen.jar
jaxrpc.jar
jazzy.jar
jcifs.jar
jcommon.jar
jcr.jar
jdom.jar
jena.jar
jericho-html.jar
jets3t.jar
jfreechart.jar
jgroups.jar
jodconverter.jar
jrcs-diff.jar
jsonrpc.jar
jspwiki.jar
jsr107cache.jar
jstl-impl.jar
jstl.jar
juh.jar
jurt.jar
liferay-icu4j.jar
liferay-rhino.jar
liferay-yuicompressor.jar
log4j.jar
lucene-highlighter.jar
lucene.jar
mirage-api.jar
msnm.jar
nekohtml.jar
odmg.jar
openid4java.jar
openxri-client.jar
openxri-syntax.jar
oro.jar
oscache.jar
pdfbox.jar
poi-contrib.jar
poi.jar
poi-scratchpad.jar
portal-client.jar
portal-impl.jar
portals-bridges.jar
portletbridge-core.jar
portletbridge-portlet.jar
quartz.jar
rdffilter.jar
ridl.jar
rome.jar
ruon-client.jar
saaj-api.jar
saaj-impl.jar
serializer.jar
simplecaptcha.jar
slf4j-api.jar
slf4j-log4j12.jar
soap.jar
spring.jar
spring-test.jar
spring-webmvc.jar
stax.jar
struts-el.jar
struts.jar
unoil.jar
urlrewrite.jar
util-bridges.jar
util-java.jar
util-taglib.jar
util-wsrp.jar
velocity.jar
velocity-tools.jar
wsdl4j.jar
wstx.jar
xalan.jar
xbean-spring.jar
xercesImpl.jar
xml-apis.jar
xmlsec.jar
xpp3.jar
xstream.jar

Appendix B

Here is the list of JARs that are available by default if you use the Liferay SDK:

commons-logging.jar
log4j.jar
util-bridges.jar
util-java.jar
util-taglib.jar

If you use the command ant all, the Liferay SDK will add these JARs to the resulting WAR file.

Cloud City


anime | bash | blogs | bsd | c/c++ | c64 | calc | comics | convert | cube | del.icio.us | digg | east | eBooks | egeszseg | elite | firefox | flash | fun | games | gimp | google | groovy | hardware | hit&run | howto | java | javascript | knife | lang | latex | liferay | linux | lovecraft | magyar | maths | movies | music | p2p | perl | pdf | photoshop | php | pmwiki | prog | python | radio | recept | rts | scala | scene | sci-fi | scripting | security | shell | space | súlyos | telephone | torrente | translate | ubuntu | vim | wallpapers | webutils | wikis | windows


Blogs and Dev.

* Ubuntu Incident
* Python Adventures
* me @ GitHub


Places

Debrecen | France | Hungary | Montreal | Nancy


Notes

full circle | km


Hobby Projects

* Jabba's Codes
* PmWiki
* Firefox
* PHP
* JavaScript
* Scriptorium
* Tutorials
* me @ GitHub


Quick Links


[ edit ]

View - Edit - History - Attach - Print *** Report - Recent Changes - Search
Page last modified on 2010 February 21, 22:52