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 附件
152350 查看
平均 (11 票)
满分为 5,平均得分为 2.63636363636364。
评论
讨论主题回复 作者 日期
It is mostly incomplete, the link to aui is... Jaber C. Mourad 2010年4月20日 上午3:05
Hi, I want to set an error message in an... Puj Z 2010年4月27日 上午10:03
http://issues.liferay.com/browse/LPS-12402 Denis Signoretto 2010年9月22日 上午2:54
What is the way to create my own personalized... David Millán 2010年5月4日 上午9:11
Hey All, I just committed (r53825) an ant task... Raymond Augé 2010年5月25日 下午8:08
is there a alloy ui components for jsf(1 or 2) ... arron wu 2010年7月7日 下午6:57
I means the jsf component for facletes! arron wu 2010年7月7日 下午6:59
I think it is very difficult to document all... David García González 2011年3月17日 上午8:13

It is mostly incomplete, the link to aui is broken...
在 10-4-20 上午3:05 发帖。
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.
在 10-4-27 上午10:03 发帖。
What is the way to create my own personalized ui taglib?
在 10-5-4 上午9:11 发帖。
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.
在 10-5-25 下午8:08 发帖。
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?
在 10-7-7 下午6:57 发帖。
I means the jsf component for facletes!
在 10-7-7 下午6:59 发帖以回复 arron wu
http://issues.liferay.com/browse/LPS-12402
在 10-9-22 上午2:54 发帖以回复 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.
在 11-3-17 上午8:13 发帖。