【liferay】2、可配置portlet

定义:edit和config模式一般没有使用,对于使用editor和config等模式的portlet,我们可以将他们称为可配置portlet。

 

我们先新建一个portlet项

 

 

 

 

 

 添加可配置的控制元素,设置为我们前面添加的类

 

 

 

 

 这里一定要注意,如果class填错了,那么就会报错,报 object is not an instance of declaring class的错误

 

 

 在action和portlet之间数据共享,我们借助PortletPreferences对象来实现

 我们在action中获取设置在这个里面的信息

 

 

当执行对应的配置action的时候,设置对应的值进入PortletPreferences中

 

 这个时候,我们写下config页面展示

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>

<portlet:defineObjects />

<!-- 获取根目录 -->
<%
	String rootPath = renderRequest.getContextPath();
	String title = "可配置式portlet";
	String link = "http://www.baidu.com";
%>

<liferay-portlet:actionURL portletConfiguration='true' var='test' />


<!-- 这里action可以是固定的<liferay-portlet:actionURL portletConfiguration="true"/> -->
<form action="${test }" name="<portlet:namespace />fm" id="<portlet:namespace />fm"
	method="post">
	<ul>
		<li><span>标题:</span> <input tabindex="1" type="text"
			name="<portlet:namespace />customjspConfig_page_title"
			id="<portlet:namespace />customjspConfig_page_title"
			value="<%=title%>" /></li>
		<li><span>链接地址:</span> <input
			id='<portlet:namespace />custom_page_link'
			name='<portlet:namespace />customjspConfig_page_link' type="text"
			value="<%=link%>" /></li>
		<li><input type="button" value="保存设置"
			οnclick="<portlet:namespace />saveConfig()"></li>
		<li>
			<input type="submit" value="直接提交" />
		</li>
	</ul>
</form>

<script type="text/javascript">

	function <portlet:namespace />saveConfig(){
	
		var from = document.getElementById('<portlet:namespace />fm');
		from.submit();
		
	}

</script>

  

 

最后我们在前台view输出一下我们的结果:

 

package com.xiaof.test2.portlet;

import java.io.IOException;

import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import com.liferay.portal.kernel.util.StringPool;
import com.liferay.util.bridges.mvc.MVCPortlet;

/**
 * 可配置式portlet
 */
public class CoudConfigPortle extends MVCPortlet {

    @Override
    public void doView(RenderRequest renderRequest,
            RenderResponse renderResponse) throws IOException, PortletException {
        //获取可配置的标题数据
        PortletPreferences preferences = renderRequest.getPreferences();
        
        String title = preferences.getValue("customjspConfig_page_title", StringPool.BLANK);
        String link = preferences.getValue("customjspConfig_page_link", StringPool.BLANK);
        
        System.out.println("title:" + title + ",link:" + link);
        
        renderRequest.setAttribute("title", title);
        renderRequest.setAttribute("link", link);
        
        super.doView(renderRequest, renderResponse);
    }

}

 

 

view.jsp页面

<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />


标题名为:${title }
连接是:<a href="${link }">这是一个新连接</a>

  

最后展示效果:

 

 我们进入这个portlet的配置页面

 

 

 

 

 修改对应的值:

 

 

 保存后刷新页面

 

 点击链接

 

 

 

转载于:https://www.cnblogs.com/cutter-point/p/8099200.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值