UI Taglib

(Redirected from Liferay UI Taglib)

The Liferay UI Taglib #

This is an unfinished attempt to document Liferay 5.2's UI taglib for JSP developers. I haven't found any current and extensive information about it, so I'm learning it the hard way. Any insight and additions from more skilled developers highly appreciated!

For introductory taglib reference, install the liferay-ui-taglib-demo-portlet from the community plugins. This provides editable examples for tags including user-display, Breadcrumb, calendar, captcha, icon and toggle-area. For complete information about taglibs, browse or search in the com.liferay.taglib.ui package under util-taglibs/src in the Liferay source code.

Developer background #

Check out Liferay Core Development Guidelines, especially Liferay UI Guidelines. Also interesting might be Introduction to Liferay for new developers, but this is mostly outdated.

UI setup #

The Liferay UI taglib contains custom user interface tags, e.g. for error reporting or i18n.

If you have the Liferay source download, the taglib definition is located in /util-taglib/src/META-INF/liferay-ui.tld. The java classes are in /util-taglib/src/com/liferay/taglib/ui, and the JSP fragments are in portal-web/docroot/html/taglib/ui

See also the Liferay wiki page "How to search for a taglib's code" for more information.

To use UI, add this import line into your JSP:

<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>

API reference #

error #

"error" shows user feedback if something went wrong. It is shown in the portlet, using the "portlet-msg-error" CSS class. Per default, this renders a red box with the error message.

Displaying the error requires (at least) two steps

  1. indicate that an error should be displayed using

com.liferay.portal.kernel.servlet.SessionErrors.add(PortletRequest portletRequest, String key)

  1. display a relevant message for this key on the JSP using

<liferay-ui:error message="message" key="key"/>

example

<%
	SessionErrors.add(renderRequest, "key");
%>

<liferay-ui:error message="this-is-an-error" key="key" />

key must be unique. There seem to be another way of displaying errors directly from an Exception. The syntax is

<liferay-ui:error exception="<%= Exception.class %>" message="message" />

, but I haven't gotten this to work.

message #

"message" displays a localized message for a key. The key can be one of the predefined keys from Liferay (see Language_xx.properties in /portal-impl/src/content), or a custom key introduced with a hook. The translation does not support formatting, i.e. you cannot add HTML into the Language_xx.properties file.

example

<liferay-ui:message key="no" />

will print "no" translated to your selected language. Some more information on i18n in Liferay

tags-summary #

this tag displays tag and/or category information for web content.

parameters:

  • className = name of class of resource to retrieve tags for
  • classPK = resource primary key
  • folksonomy (optional): true = show user created tags as well as categories, false = show only categories. default is false

example:

<liferay-ui:tags-summary 
   className="<%= JournalArticle.class.getName() %>" 
   classPK="<%=article.getResourcePrimKey()%>" 
   folksonomy="false" />

journal-article #

this tag displays a journal article using the template defined by the user.

parameters:

  • articleId = uniqueID of content article
  • groupId = group of user
  • showTitle = show title of article true or false
  • templateId = which of the defined templates for this journal article to use. Note that there is a bug (reported here) in liferay versions before 6.0.2 where templateId is ignored.

example:

<liferay-ui:journal-article 
  articleId="<%=menuIdString%>" 
  groupId="<%=groupId%>" />

breadcrumb #

This tag displays a series of links representing page hierarchy. It will display links or text depending on the displayStyle parameter. It does not display user navigation history. parameters:

  • displayStyle: 1 = links to pages in child-parent hierarchy. 2 = text but no links
  • portletURL:
  • selLayout:

example:

<liferay-ui:breadcrumb portletURL="<%=portletURL%>" selLayout="<%=selLayout%>" displayStyle="<%=displayStyle%>" />

tabs #

this tag displays a set of DHTML tabs.

example:

<liferay-ui:tabs 
     names="Welcome,Breadcrumb,Calendar,Captcha,Panel,Table,Icon,Input" 
     tabsValues="welcome,breadcrumb,calendar,captcha,panel,table,icon,input" 
     param="tab" 
     url="<%= portletURL %>"
/>

ratings #

see Adding Rating to a portlet

Related documents #

0 Attachments
105549 Views
Average (11 Votes)
The average rating is 2.63636363636364 stars out of 5.
Comments
Threaded Replies Author Date
It is mostly incomplete, the link to aui is... Jaber C. Mourad April 20, 2010 3:05 AM
Hi, I want to set an error message in an... Puj Z April 27, 2010 10:03 AM
http://issues.liferay.com/browse/LPS-12402 Denis Signoretto September 22, 2010 2:54 AM
What is the way to create my own personalized... David Millán May 4, 2010 9:11 AM
Hey All, I just committed (r53825) an ant task... Ray Augé May 25, 2010 8:08 PM
is there a alloy ui components for jsf(1 or 2) ... arron wu July 7, 2010 6:57 PM
I means the jsf component for facletes! arron wu July 7, 2010 6:59 PM
I think it is very difficult to document all... David García González March 17, 2011 8:13 AM

It is mostly incomplete, the link to aui is broken...
Posted on 4/20/10 3:05 AM.
Hi,

I want to set an error message in an action class.
This means I have access to ActionRequest. However, I believe we need RenderRequest for SessionErrors.add(req, "errorMessage", "my error")

When I use the ActionRequest for adding the error, the tag with "errorMessage" will be activated indeed, but the message is not shown properly. It is always a general error message from Liferay. Do you know what to do?
How can I get RenderRequest from ActionRequest or somehow pass the value?
I really appreciate any helps.
Posted on 4/27/10 10:03 AM.
What is the way to create my own personalized ui taglib?
Posted on 5/4/10 9:11 AM.
Hey All, I just committed (r53825) an ant task to generate the taglib docs along with the javadoc, and although it's pretty bare right now, it's a step in the right direction. At least you get a list of available attributes and a full list of tags to at least see what's available.

And please, if you wanted to contribute to that aspect of the documentation, we'd surely appreciate it.
Posted on 5/25/10 8:08 PM.
is there a alloy ui components for jsf(1 or 2) plan?
I develop components suite on extjs base on jsf1.2 and 2.0!
I want to know the alloy ui can run on jsf?
Posted on 7/7/10 6:57 PM.
I means the jsf component for facletes!
Posted on 7/7/10 6:59 PM in reply to arron wu.
http://issues.liferay.com/browse/LPS-12402
Posted on 9/22/10 2:54 AM in reply to Puj Z.
I think it is very difficult to document all the tags. The best way to start is looking the source code, inside the project util-taglibs/src and looking the source code of the demo portlet liferay-ui-taglib-demo-portlet.
Posted on 3/17/11 8:13 AM.