OFBIZ - 实例开发(二)

注意:
- 系统环境Microsoft Windows 7
- 此版本适用于ofbiz 16.11.02
- OFBIZ目录hot-deploy文件夹,目的是让开发者扩展开发自己的组件存放处,这里我开发一个Hello World例子组件
- 通过OFBIZ实例(一),继续更新改进这个实例;
+ 动态获取数据库Person表的数据列表显示;




1.在hot-deploy/hello/webapp/hello/WEB-INF/web.xml 添加
<context-param>
<param-name>commonDecoratorLocation</param-name>
<param-value>component://hello/widget/CommonScreens.xml</param-value>
</context-param>

2.在hot-deploy/hello/widget 新建HelloMenus.xml

- HelloMenus.xml主要作用是装饰屏幕菜单列表;
<?xml version="1.0" encoding="UTF-8"?>
<menus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/widget-menu.xsd">
<menu name="HelloAppBar" title="HelloApplication" extends="CommonAppBarMenu" extends-resource="component://common/widget/CommonMenus.xml">
<menu-item name="person" title="Person">
<link target="person" />
</menu-item>
</menu>
</menus> 


3.在hot-deploy/hello/widget/CommonScreens.xml 中添加

- CommonScreens.xml : 类似于母版引用
<screen name="CommonHelloDecorator">
<section>  
<widgets>  
<include-menu location="component://hello/widget/HelloMenus.xml" name="HelloAppBar"/> 
<!--导入菜单装饰-->
<decorator-section-include name="body"/>
<!--decorator-section-include : 页面主体部分占位装饰-->
</widgets>  
</section>
</screen>


4.在hot-deploy/hello 新建groovyScripts文件夹;
- 在hot-deploy/hell/groovyScripts 新建Person.groovy文件;
context.persons = delegator.findList("Person", null, null, null, null, false); 

<!--findList方法参数详解-->
<!--entityName - String : 实体类名称-->
<!--entityCondition - EntityCondition : 这个类主要是包含一些约束的查询条件-->
<!--fieldsToSelect - Set<String> : 字段集合-->
<!--orderBy - List<String> : ASC或DESC-->
<!--findOptions  - EntityFindOptions : 这个类包含比如:maxRows、limit之类的查询选项-->
<!--useCache - boolean : true抓取相关联其它表数据,false不抓取-->

5.在hot-deploy/hello 新建template文件夹;
- 在hot-deploy/hello/template 新建Person.ftl文件
<#if persons?has_content>  
 <h2>Some of the people who visited our site are:</h2>  
 <br>  
 <ul>  
<#list persons as person>  
 <li>${person.firstName?if_exists} ${person.lastName?if_exists}</li>  
</#list> 
<!--遍历persons列表集合,显示每个person对象-->
 </ul>  
</#if>

6.在hot-deploy/hello/widget/HelloScreens.xml 中添加;
<screen name="person">  
<section>  
<actions>  
<script location="component://hello/groovyScripts/Person.groovy"/> 
</actions>  
<widgets>  
<decorator-screen name="CommonHelloDecorator" location="${parameters.commonDecoratorLocation}">  
<!--decorator-screen - location : 是指向通用(母版)屏幕装饰文件-->
<!--decorator-screen - name : 是指向通用(母版)屏幕装饰文件下具体的装饰标签-->
<decorator-section name="body">  
<!--decorator-section : 指定页面主体占位部分设置-->
<platform-specific>  
<html>  
<html-template location="component:///hello/template/Person.ftl"/> 
<!--指定具体的模版文件内容-->
</html>  
</platform-specific>  
</decorator-section>  
</decorator-screen>         
</widgets>  
</section>  
</screen>

7.在hot-deploy/hello/webapp/hello/WEB-INF/controller.xml 中添加;

<request-map uri="person">
  <security https="true" auth="true"/>
  <response name="success" type="view" value="person"/>
</request-map>

<view-map name="person" type="screen" page="component://hello/widget/HelloScreens.xml#person"/>


8.启动项目:cmd ->cd ofbiz项目目录下-> gradlew ofbiz
- 访问地址:https://localhost:8443/hello/control/person 账号:admin 密码:ofbiz
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值