`

liferay portlet上加print按钮

阅读更多

 

在Eclipse生成的代码上改装。

 

============使用MVCPortlet

在portlet.xml中,替换

<portlet-class>com.test.NewPortlet</portlet-class>

<portlet-class>com.liferay.util.bridges.mvc.MVCPortlet</portlet-class>

对初学而言,这样可以避免很多麻烦。使用MVCPortlet后,不需要写java代码,就能实现print页面。

 

============加jstl相关的jar文件

加jstl-1.2.jar和standard.jar到WEB-INF/lib下,便于项目中使用jstl。

 

============修改portlet.xml

把<value>/html/print.jsp</value>

改成<value>/html/view.jsp</value>

让print和view使用同一页面。

 

============加代码到view.jsp

<%@ page contentType="text/html; charset=UTF-8" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

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

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

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

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

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

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

 

<%@ page import="com.liferay.portal.kernel.util.HtmlUtil

,com.liferay.portal.kernel.portlet.LiferayPortletMode

,com.liferay.portal.kernel.language.LanguageUtil

" %>

<%---- 下面2个定义很有用,enable renderRequest, portletDisplay ----%>

<portlet:defineObjects />

<liferay-theme:defineObjects />

 

<%---- 初始化print相关参数 ----%>

<% 

String portletTitle = HtmlUtil.unescape(portletDisplay.getTitle());

boolean print = renderRequest.getPortletMode().equals(LiferayPortletMode.PRINT);

%>

 

<%---- 画print按钮,参考/portal-trunk/portal-web/docroot/html/portlet/journal_content/view.jsp ----%>

<c:if test="<%= print %>">

<div class="user-actions">

 <div class="print-action">

  <liferay-ui:icon

   image="print"

   label="<%= true %>"

   message='<%= LanguageUtil.format(pageContext, "print-x-x", 

       new Object[] {"aui-helper-hidden-accessible", portletTitle}) %>'

   url="javascript:print();"

  />

 </div>

</div>

 <aui:script>

  //print();

 </aui:script>

</c:if>

<%----   修改生成的代码为  ----%>

This is the <b>NewPortlet</b> portlet in <%=renderRequest.getPortletMode() %> mode.

============加样式到main.css,使print按钮居右

.user-actions {

  padding-bottom: 2.5em;

 

  .export-actions, .print-action, .locale-actions {

    float: right;

  }

 

  .print-action {

    margin-left: 1em;

  }

 

  .locale-separator {

    border-right: 1px solid #CCC;

    float: right;

    margin-right: 1em;

    padding: 0.8em 0.5em;

  }

}

 

 

 

春风得意

春风得意

 

note: why iteye? sina cannot paste code freely, iteye can.

  • 大小: 23.2 KB
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics