Liferay7 BPM门户开发之25: Liferay7应用程序配置(APPLICATION CONFIGURATION)
首先有几个概念需要明确。
1、第一个概念是这里的应用程序配置不是写XML之类的配置文件,是类似字典的类型化配置
这意味着应用程序配置不只是一个字符串键值对的列表。值还可以有类型,如整数列表,字符串列表,一个网址,甚至可以使用自己的自定义类型。
2、第二个概念是模块性。在Liferay 7 中,应用程序是模块化的,组件只是一个有@组件注释的类,通常是一组属性提供元数据。
3、第三个概念是在不同的范围内具有相同的应用程序的能力有不同的配置。如果您的应用程序需要在不同的范围支持不同的配置,应用程序作用范围可以有:
- System: 所有的应用程序范围;
- Virtual Instance: 虚拟实例级别;
- Site: 站点级别,即每个站点不同的配置;
- Portlet Instance: Portlet实例级别,即每个Portlet实例都有不同配置;
实例
编写应用程序配置接口
package com.liferay.docs.exampleconfig; import aQute.bnd.annotation.metatype.Meta; @Meta.OCD(id = "com.liferay.docs.exampleconfig.ExampleConfiguration")
public interface ExampleConfiguration { @Meta.AD(
deflt = "blue",
required = false
)
public String favoriteColor(); @Meta.AD(
deflt = "red|green|blue",
required = false
)
public String[] validColors(); @Meta.AD(required = false)
public int favoriteNumber(); }
Meta.AD 和 Meta.OCD是OSGi Metatype 的格式。更多信息见:
http://bnd.bndtools.org/chapters/210-metatype.html
MVCPortlet的实现
先添加@Component注解, configurationPid即应用程序配置接口
@Activate和@Modified是一个标准格式写法
package com.liferay.docs.exampleconfig; import java.io.IOException;
import java.util.Map; import javax.portlet.Portlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse; import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Modified; import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet; import aQute.bnd.annotation.metatype.Configurable; @Component(
configurationPid = "com.liferay.docs.exampleconfig.ExampleConfiguration",
immediate = true,
property = {
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.instanceable=true",
"javax.portlet.security-role-ref=power-user,user",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.resource-bundle=content.Language"
},
service = Portlet.class
)
public class ExampleConfigPortlet extends MVCPortlet { @Override
public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {
//设置renderRequest的属性,把className写到key
renderRequest.setAttribute(
ExampleConfiguration.class.getName(), _configuration); super.doView(renderRequest, renderResponse);
} public String getFavoriteColor(Map colors) {
return (String) colors.get(_configuration.favoriteColor());
} @Activate
@Modified
protected void activate(Map<String, Object> properties) {
_configuration = Configurable.createConfigurable(
ExampleConfiguration.class, properties);
} private volatile ExampleConfiguration _configuration; }
jsp
<%@ 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/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> <%@ page import="com.liferay.docs.exampleconfig.ExampleConfiguration" %> <%@ page import="com.liferay.portal.kernel.util.GetterUtil" %> <portlet:defineObjects /> <liferay-theme:defineObjects /> <p>
<b>Hello from the Example Configuration portlet!</b>
</p> <%
ExampleConfiguration configuration = (ExampleConfiguration) GetterUtil.getObject(
renderRequest.getAttribute(ExampleConfiguration.class.getName())); String favoriteColor = configuration.favoriteColor();
%> <p>Favorite color: <span style="color: <%= favoriteColor %>;"><%= favoriteColor %></span></p>
界面:

我暂时还想不出这种写法的好处是啥?
为啥不用枚举,静态类,或者XML的属性文件,就是为了有作用范围? 有知道答案的客官请点醒我。
这种注解+元数据+接口的写法实在是太奇特了。
在liferay自身的设置,也是应用这种配置方法,
比如UI设置,如图:

还有一个更复杂的例子:
https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/implementing-configuration-actions
Liferay7 BPM门户开发之25: Liferay7应用程序配置(APPLICATION CONFIGURATION)的更多相关文章
- Liferay7 BPM门户开发之37: Liferay7下的OSGi Hook集成开发
hook开发是Liferay客制扩展的一种方式,比插件灵活,即可以扩展liferay门户,也能对原有特性进行更改,Liferay有许多内置的服务,比如用hook甚至可以覆盖Liferay服务. 可作为 ...
- Liferay7 BPM门户开发之34: liferay7对外服务类生成(RestService Get Url)
在liferay7中开发不依赖Service Builder的对外服务类,非常简洁,只需要2点注解: 在类的前部定义: @ApplicationPath("/PathXXX") 方 ...
- Liferay7 BPM门户开发之22: Liferay7模型监听器(Model Listeners)
Model Listeners实现ModelListener接口,用于持久化时的AOP处理 一些使用场景: Audit Listener: 在一个独立而分离的数据库,做信息更新的审计: Cache C ...
- Liferay7 BPM门户开发之24: Liferay7应用程序安全
整理中...... Resources, Roles, and PermissionsPortal Access Control List (PACL) Custom SSO Providers Au ...
- Liferay7 BPM门户开发之1:Liferay7开发环境准备
liferay sdk下载 \IDE下载 \ Tomcat 安装细节不在此赘述 网上有很多. 只讲核心关键坑点 进入2016年,从Liferay6.2.5 ga6版本开始,到7.0 ga3,在ivy环 ...
- Liferay7 BPM门户开发之17: Portlet 生命周期
Portlet 生命周期 init() =〉 render() =〉 processAction() =〉 processEvent() =〉 serveResource() =〉destroy() ...
- Liferay7 BPM门户开发之10: 通用流程实现从Servlet到Portlet(Part1)
开发目的: 实现通用流程自动化处理(即实现不需要hardcode代码的bpm统一处理后台,仅需要写少量前端html form代码和拖拽设计BPM定义) 既可独立运行或可依托于Liferay或依托其它门 ...
- Liferay7 BPM门户开发之12:acitiviti和liferay用户权限体系集成
写到第12章才出现Liferay的内容,希望可以厚积薄发. 我们的目标是不使用不维护Activiti的用户组织架构,只维护Liferay的体系,这样的好处是非常明显的,即不用做组织架构的同步工作. 原 ...
- Liferay7 BPM门户开发之32: 实现自定义认证登陆(定制Authentication Hook)
第一步:修改liferay-hook.xml <?xml version="1.0"?> <!DOCTYPE hook PUBLIC "-//Lifer ...
随机推荐
- 深入浅出PF 学习笔记---通过资源文件设置按钮的Style及通过x:null设置不受Style影响
<Window x:Class="WpfStudy2018.StyleButton" xmlns="http://schemas.microsoft.com/win ...
- 求树的重心 poj 1655
题目链接:https://vjudge.net/problem/POJ-1655 这个就是找树的重心,树的重心就是树里面找一个点,使得以这个点为树根的所有的子树中最大的子树节点数最小.题目应该讲的比较 ...
- 【python中二叉树的实现】python中二叉树的创建、三种方式递归遍历和非递归遍历
代码如下: # coding=utf-8 class myNode(object): def __init__(self, data=-1, lchild=None, rchild=None): se ...
- 【网络编程】time_wait状态产生的原因,危害,如何避免
转自:https://blog.csdn.net/u013616945/article/details/77510925 做略微修改 仅供个人学习 1. time_wait状态如何产生? 在tcp ...
- sqlplus中设定行大小、页大小、字符列格式、数字列格式、清屏
sqlplus虽然是DBA们最为经常使用的Oracle客户端工具,但是它在输出结果格式化上不是很好,如折行.分页不好等,所以一般启动sqlplus后多少都要做些设置,如linesize.pagesiz ...
- React-router4 第六篇 No Match 404
https://reacttraining.com/react-router/web/example/no-match react-router-dom 又一个新属性 Switch 在Switch 的 ...
- ubuntu中的环境变量
写这句话,给自己提个醒吧,添加路径(所谓的环境变量):系统会去相应的目录中找可执行文件,到时候只要输入命令名字,可以不用输入完整的路径
- 用nodejs搭建类似于C++的服务器后台.类似网易pomelo
实际的情况,用nodejs跑业务,非常的快,只要用好其无阻塞和回调这两点,处理速度真的是杠杠的. 从年初开始,我用nodejs搭建了类似C++的服务器后台,也想和做同样的事情的朋友分享,本服务平台因为 ...
- BZOJ5017 [SNOI2017]炸弹 - 线段树优化建图+Tarjan
Solution 一个点向一个区间内的所有点连边, 可以用线段树优化建图来优化 : 前置技能传送门 然后就得到一个有向图, 一个联通块内的炸弹可以互相引爆, 所以进行缩点变成$DAG$ 然后拓扑排序. ...
- maven pom.xml文件 仓库搜索服务
POM(Project Object Model),即项目对象模型,是 Maven 工程的基本工作单元,是一个 XML 文件,包含了项目的基本信息,用于描述项目如何构建.声明项目依赖 等等 Maven ...