参考:https://blog.csdn.net/lan861698789/article/details/7563280
摘自:http://blog.csdn.net/zhichao_boole/article/details/6801539
如果你已下载liferay source,标签库位于/util-taglib/src/META-INF/liferay-ui.tld。Java classes位于/util-taglib/src/com/liferay/taglib/ui。JSPfragments位于portal-web/docroot/html/taglib/ui。
可以参考liferay wiki page “How to search for a taglib's code”以获取更多的信息。
要使用UI,就需要在你的JSP中加入这条语句:
<%@ tagliburi="http://liferay.com/tld/ui"prefix="liferay-ui" %>
1 error
<liferay-ui: errorkey=””message=””/>
用于显示操作失败的信息。使用"portlet-msg-error" CSS class。默认情况下,在红框里显示错误信息。
显示错误,(至少)需要以下两步:
1. 在后台处理程序中通过SessionErrors.add(req,key)设置key的值:
com.liferay.portal.kernel.servlet.SessionErrors.add(PortletRequestportletRequest, String key)
2. message指定显示信息对应的资源文件中key的值。key值必须唯一。
<liferay-ui:errormessage="message"key="key"/>
示例:
- <% SessionErrors.add(renderRequest,"key"); %>
- <liferay-ui:errormessageliferay-ui:errormessage="this-is-an-error"key="key"/>
2 message
Key为在资源文件中配置的值
示例:
<liferay-ui:message key="Feed-add-Feed-Description"/>
3 tags-summary
4 journal-article
使用用户定义的模板显示journal article。
四个参数:
1. articleId = uniqueID of content article
2 .groupId = group of user
3. showTitle = show title of article trueor false
4 .templateId = which of the definedtemplates for this journal article to use. Note that there is a bug (reportedhere) in liferay versions before 6.0.2 where templateId is ignored.
示例:
<liferay-ui:journal-articlearticleId="<%=menuIdString%>" groupId="<%=groupId%>"/>
5 bread-crumb
6 tabs
Liferay中自带的Tab标签UI,可以根据其name属性显示相应的标签名,多个标签名字用逗号分割, 但逗号前后都不能有多余空格。param参数是是tabs1还是tabsn,命名规范是tabsx,是几级菜单的标识。url是每个对应的name名字的要跳转的页面,最大支持10个标签名。
- <liferay-ui:tabsnames=”add,update”param=”cur”url=”<%= %>”refresh=”<%= true%”>
- <c:iftest=”<%= %>”>
- <liferay-util:includepageliferay-util:includepage=””>
- <liferay-util:paramname=””value=””>
- </liferay-util:include>
- </c:if>
- </liefray-ui:tabs>
注:实际使用当中通过这种方式:
首先,从页面获取参数,也就是<liferay-ui:tabs 标签当中设置的param属性:
String cur=ParamUtil.getString(request,"cur","add");
第二个参数是设置的参数名,最后一个参数为你想要默认显示的页面。
其次定义url:
- PortletURL portletURL =renderResponse.createRenderURL();
- portletURL.setWindowState(LiferayWindowState.MAXIMIZED);
- portletURL.setParameter("struts_action","/ext/user/view");
然后定义liferay-ui:tabs标签:
- <liferay-ui:tabsnamesliferay-ui:tabsnames="uploadModelFile,uploadDataFile"param="cur"value="<%= cur%>"url="<%= portletURL.toString()%>"refresh="<%= true%>">
- <c:if test='<%= cur.equals("add") %>'>
- <liferay-util:includepage="/html/portlet/ext/user/add.jsp">
- </liferay-util:include>
- </c:if>
- <c:if test='<%= cur.equals("update") %>'>
- <liferay-util:includepage="/html/portlet/ext/user/update.jsp">
- </liferay-util:include>
- </c:if>
- </liferay-ui:tabs>
标签会传递相应的参数,然后选择显示要显示的页面。
另外,liferay的多tab页还可以通过下面这种方式实现:
首先定义url:
- PortletURL portletURL =renderResponse.createRenderURL();
- portletURL.setWindowState(LiferayWindowState.MAXIMIZED);
- portletURL.setParameter("struts_action","/ext/user/view");
然后定义liferay-ui:tabs标签:
- <liferay-ui:tabsnamesliferay-ui:tabsnames="add,update"url="<%= portletURL.toString()%>"refresh="<%= true%>">
- <liferay-ui:section>
- <liferay-util:includepage="/html/portlet/ext/user/add.jsp">
- </liferay-util:include>
- </liferay-ui:section>
- <liferay-ui:section>
- <liferay-util:includepage="/html/user/update.jsp">
- </liferay-util:include>
- </liferay-ui:section>
- </liferay-ui:tabs>
这样,就可以根据在names里面定义的顺序,显示所要显示的页面。
7 section
- <liferay-ui:section>
- <c:iftest=”<%= %>”>
- <liferay-util:includepage=””>
- <liferay-util:paramname=””value=””>
- </liferay-util:include>
- </c:if>
- </liferay-ui:section>
8 page-iterator
<liferay-ui:page-iteratorcurParam=””curValue=””delta=”” maxPages=””total=”” url=””/>
参数:(cur、curParam、total为必须参数)
1. curParam指定保存当前页码的参数名称;
2. curValue保存当前页码;
3. delta指定每页显示的记录数量;
4. maxPages指定Portlet正常模式下的显示的最大记录数;
5. total指定数据的总记录数;
6. url 指定翻页时的请求URL.
9 search-container
results- This is where you input the results. resultsshould be of type List. The important part is to make sure that your methodsupports some way to search from a beginning index to an end index in order toprovide a good performance pagination. Note how we usesearchContainer.getStart() for the first index and searchContainer.getEnd() forthe second index. As mentioned above, the searchContainer object is availablebecause it has been instantiated already. Some other methods you can use:
searchContainer.getStart() - gets starting index of current resultspage.
searchContainer.getResultsEnd() - gets ending index of currentresults page or index of last result (i.e. will return 3 if delta is 5 butthere are only 3 results).
searchContainer.getEnd() - gets last index of current results pageregardless of size of actually results (i.e. will return 5 if delta is 5 evenif there is only 3 results. Will throw out of bounds errors).
searchContainer.getCur() - gets number of current results page.
searchContainer.setTotal() - must be set so getResultsEnd() knowswhen to stop.
total- This is where you input the total number of itemsin your list
className - The type of Object in your List. In this case, we have a List ofUser objects.
keyProperty - Primary Key
modelVar - The name of the variable to represent your model. In this casethe model is the User object.
<liferay-ui:search-container-column-text> - Text column
name - Name of the column
value - Value of the column
href - the text in this coulmn will be a link the this URL
orderable - allows the user to order the list of items by this column
property - This will automatically look in the User object for the"firstName" property. It's basically the same thing asuser.getFirstName()
<liferay-ui:search-iterator/> - This is what actually iterates through anddisplays the List
示例:
- <liferay-ui:search-container
- delta="10"
- emptyResultsMessage="no-users-were-found"><liferay-ui:search-container-results
- results="<%=UserLocalServiceUtil.search(company.getCompanyId(),
- searchTerms.getKeywords(),searchTerms.getActiveObj(),userParams,
- searchContainer.getStart(),searchContainer.getEnd(),
- searchContainer.getOrderByComparator()); %>"
- total="<%=UserLocalServiceUtil.searchCount(company.getCompanyId(),
- searchTerms.getKeywords(),searchTerms.getActiveObj(),userParams);%>"/>
- <liferay-ui:search-container-row
- className="com.liferay.portal.model.User"
- keyProperty="userId"
- modelVar="user">
- <liferay-ui:search-container-column-text
- name="name"value="<%= user.getFullName()%>"/>
- <liferay-ui:search-container-column-text
- name="first-name"property="firstName"/>
- </liferay-ui:search-container-row>
- <liferay-ui:search-iterator/>
- t;/liferay-ui:search-container>
官网UI:http://docs.liferay.com/portal/6.1/taglibs/liferay-ui/tld-summary.html
由一个网址:
http://liferaydemystified.blogspot.com/2011/05/liferay-ui-taglib.html