liferay UI 标签

如果你已下载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: error key=””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:error message="message"key="key"/>

示例:

<% SessionErrors.add(renderRequest,"key"); %>
<liferay-ui:errormessage="this-is-an-error" key="key" />

 

2 message

<liferay-ui:messagekey=""/>

Key为在资源文件中配置的值

示例:

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

 

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-article articleId="<%=menuIdString%>"  groupId="<%=groupId%>" />

 

5 bread-crumb

 

6 tabs

Liferay中自带的Tab标签UI,可以根据其name属性显示相应的标签名,多个标签名字用逗号分割, 但逗号前后都不能有多余空格。param参数是是tabs1还是tabsn,命名规范是tabsx,是几级菜单的标识。url是每个对应的name名字的要跳转的页面,最大支持10个标签名。

<liferay-ui:tabs names=”add,update”param=”cur” url=”<%= %>” refresh=”<%= true%”>
      <c:if test=”<%= %>”>
      <liferay-util:includepage=””>
              <liferay-util:param name=””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:tabsnames="uploadModelFile,uploadDataFile" param="cur"value="<%= cur%>" url="<%= portletURL.toString()%>"refresh="<%= true%>">
   <c:if test='<%= cur.equals("add") %>'>
       <liferay-util:include page="/html/portlet/ext/user/add.jsp">
       </liferay-util:include>
   </c:if>
   <c:if test='<%= cur.equals("update") %>'>
       <liferay-util:include page="/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:tabsnames="add,update" url="<%= portletURL.toString()%>"refresh="<%= true%>">
   <liferay-ui:section>
      <liferay-util:include page="/html/portlet/ext/user/add.jsp">
       </liferay-util:include>
  </liferay-ui:section>
  <liferay-ui:section>
      <liferay-util:include page="/html/user/update.jsp">
       </liferay-util:include>
  </liferay-ui:section>
</liferay-ui:tabs>

这样,就可以根据在names里面定义的顺序,显示所要显示的页面。

 

7 section

<liferay-ui:section>
      <c:if test=”<%= %>”>
      <liferay-util:include page=””>
              <liferay-util:param name=””value=””>
      </liferay-util:include>
      </c:if>
</liferay-ui:section>

 

8 page-iterator

<liferay-ui:page-iterator curParam=””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 /> 
</liferay-ui:search-container>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值