ofbiz视图层研究

本文首先感谢网上的Ofbiz的博客!!! 

从宏观来看:
Apache OFBiz中的Widget和Decorator是ofbizView层的技术,是Apache OFBiz的一大特色

Decorator:
decorator-screen两种写法:
定义的地方:
<decorator-section-include name="body"/>

应用的地方:
<decorator-screen name="main-decorator">(相同文件内的引用)
<decorator-screen name="main-decorator" location="component://hellosix/widget/hellosix/CommonScreens.xml">(引用外部文件)

Widget:
Widgets中的元素:
效果:查找样例
代码:<container><label style="head1">${uiLabelMap.${titleProperty}}</label></container>

platform-specific 元素:
<platform-specific><html><html-template location="component://hello/webapp/hello/includes/header.ftl"/></html></platform-specific>

Widgets与安全:
OFBIZ在一个.bsh文件中使用UserLogin和一个 "security" 对象来检查这些权限。如果你使用widget你还可以使用如下的标签:
<condition>
<if-has-permission>
<check-permission>
<widgets>
<fail-widgets>
OFBIZ允许我们直接在widget里核查权限而不是使用FTL,并设置了一个通过核查时的widget和没有通过核查的widget.



来自网上的资料:

• (1) ofbizView层技术
Apache OFBiz中的Widget和Decorator是ofbizView层的技术,是Apache OFBiz的一大特色。使用widget可以将很多零散的页面部分拼合成一张页面。这样每张页面的公共部分只需创建一次,创建新页面时只要创建不同的部分即可。
Widget是用xml文件表示的,存放的位置是app\widget\XxxxScreen.xml,零散的页面碎片通常存放在app\webapp\app\下和app\webapp\app\includes\下,app\webapp\app\存放的是不同的页面部分,app\webapp\app\includes\下存放的是相同的页面部分。Widget示例代码如下:
<screen name="hello">
<section>
<widgets>
<platform-specific><html><html-template location="component://hello/webapp/hello/includes/header.ftl"/></html></platform-specific>
<platform-specific><html><html-template location="component://hello/webapp/hello/hello.ftl"/></html></platform-specific>
<platform-specific><html><html-template location="component://hello/webapp/hello/includes/footer.ftl"/></html></platform-specific>
</widgets>
</section>
</screen>

代码中可以看到news页面由header.ftl,main.ftl,footer.ftl这三部分组成。这三部分的路径都在代码中明确给出,这样的话当用户请求页面hello时,ofbiz就会根据代码中给出的路径找到页面的不同部分,将它们组合起来再返回一张完整的页面的用户。
当View比较复杂,页面太多时,这样在XML里定义每一张页面时,XML的代码量也是非常大的,而且不利于维护。Decorator是一个页面模板,该模板也是一个screen元素,模板名通常叫CommonDecorator,和widget定义在相同的XML文件中。当模板定义后每一个页面的定义就不用像上面这样将所有的部分都列出来了,可以只用列出和其它页面不同的部分。示例代码:
<screen name="CommonDecorator">
<section>
<widgets>
<platform-specific><html><html-template location="component://hello2/webapp/hello2/includes/header.ftl"/></html></platform-specific>
<decorator-section-include name="body"/>
<platform-specific><html><html-template location="component://hello2/webapp/hello2/includes/footer.ftl"/></html></platform-specific>
</widgets>
</section>
</screen>
<screen name="news">
<section>
<widgets>
<decorator-screen name="CommonDecorator">
<decorator-section name="body">
<platform-specific><html><html-template location="component://hello2/webapp/hello2/news.ftl"/></html></platform-specific>
</decorator-section>
</decorator-screen>
</widgets>
</section>
</screen>
模板页面和普通页面是一样的XML元素,但在其中有一句话不同:<decorator-section-include name="body"/>,该句话所在的位置就是使用了该模板的页面需要添加自己内容的位置,在示例代码中,模板定义了HTML头和脚,使用该模板需要添加的部分就是主体部分。模板中可以添加内容的位置用<decorator-section-include name="body"/>标示,应该可以有多个位置可以被添加,不同的位置用name参数区分。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值