本页包含8张图片,默认未加载,显示所有图片
andy liu 发布于 1年前,共有 1 条评论
在开始介绍之前,让我们先体验一下SimpleFramework Portal
图:demo演示
SimpleFramework为基于JavaEE技术体系开放架构的组件化Web应用开发框架,其最大的技术优势之一就是开放的组件架构,Web应用开 发者不仅可以利用现有组件,实现Web应用的快速构建,而且按照SimpleFramework的组件规范即可随需定制应用组件,或基于现有组件构建复合 应用组件,从而实现开发过程的组件化,以及业务的组件化。
SimpleFramework Portal是SimpleFramework的重量级组件之一,它为用户提供了快速开发Portal应用简单且行之有效的方法。
图:Portal组件流程
以Liferay为例:
| 比较项 | SimpleFramework |
Liferay |
| Portlet规范 | N | Y |
| Porlet容器 | N | Y |
| 个性化 | Y | Y |
| 轻量级 | Y | Y |
| 组件化 | Y | Y |
| AJAX支持 | Y | Y |
| Paglet(Widget) | Y | N |
| HTTP Client仿真 | Y | N |
| 内容组装 | 同步,异步 | 同步,异步 |
| 业务实现(类) | HandleClass | Servlet/Porlet API |
| 内容组件定制 | SimpleFramework组件 Javascript 框架/组件 JSP、Taglib、Template等 |
Javascript框架及组件 JSP、Taglib、Template等 |
图:开发流程
文件index.xml:
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.simpleframework.net/xsd/default/simple.xsd">
<components>
<layout name="demoLayout" containerId="demoLayout" showMenu="true">
</layout>
</components>
</page>
文件index.jsp:
<%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>
<div id="demoLayout"></div>
“选项”是SimpleFramework Portal的一个业务扩展接口。
文件demo_option.xml:
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.simpleframework.net/xsd/default/simple.xsd">
<components>
<propEditor name="hellowordOptionEditor" containerId="hellowordOptionEditor">
<field label="定义业务">
<component type="textButton" name="_hello_word">
<event name="click">$Actions['helloDict']();</event>
</component>
</field>
</propEditor>
<tree name="HelloTree">
<treenode text="北京" id="你好北京!" />
<treenode text="世界" id="你好世界" />
<treenode text="上地" id="上地,你好" />
<treenode text="总经理">
<treenode text="副经理" id="HI,副经理" />
<treenode text="开发经理" id="HI,开发经理" />
<treenode text="产品经理" id="HI,产品经理" />
</treenode>
</tree>
<dictionary name="helloDict" bindingId="_hello_word" title="Simple Hello 字典">
<tree ref="HelloTree" />
<jsSelectCallback>
<![CDATA[
if (selects.length > 0 && !selects[0].branch.hasChildren()) {
$('_hello_word').value = selects[0].id;
return true;
}
]]>
</jsSelectCallback>
</dictionary>
</components>
</page>
文件demo_option.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div id="hellowordOptionEditor"></div>
<div style="text-align: right; margin-top: 6px;">
<input type="button" id="customOptionSave" value="确定" onclick="__layout_option_save();" /> <input
type="button" value="取消" onclick="__layout_option_close();" />
</div>
类HelloWordModuleHandle:
public class HelloWordModuleHandle extends AbstractLayoutModuleHandle {
public HelloWordModuleHandle(final PageletBean pagelet) {
super(pagelet);
}
@Override
protected String[] getDefaultOptions() {
return defaultOptions;
}
// 实现 layout中的 pagelet[应用设置]功能
@Override
public IForward getPageletOptionContent(final ComponentParameter compParameter) throws Exception {
return new UrlForward("/demo_option.jsp");
}
// 获得 Pagelet 需要显示的内容
@Override
public IForward getPageletContent(ComponentParameter compParameter) throws Exception {
return new TextForward(getPagelet().getOptionProperty("_hello_word"));
}
private static String[] defaultOptions = new String[] { "_hello_word= SimpleHelloWord" };
}
在Servlet启动时注册该PageLet模块,参见web.xml的定义。
类HelloWordRegistry:
public class HelloWordRegistry extends HttpServlet {
private static final long serialVersionUID = -7941207277562361975L;
@Override
public void init(final ServletConfig config) throws ServletException {
super.init(config);
LayoutModuleRegistryFactory.regist(HelloWordModuleHandle.class, "HelloWord",
"HelloWord-demo", "信息", "/my/hello.gif", "发布 Helloword");
}
}
图:已注册的PageLet模块
图:在Portal中展示的PageLet模块
图:选项设置(一)
图:选项设置(二)
图:设置选项后的运行结果
本文中示例详见 [SimpleFramework Portal组件示例下载],导入Eclipse即进行本地体验。