OFBIZ

来源:互联网 发布:java string contact 编辑:程序博客网 时间:2024/05/13 11:04
注意:
- 系统环境Microsoft Windows 7
- 此版本适用于ofbiz 16.11.02
- OFBIZ目录hot-deploy文件夹,目的是让开发者扩展开发自己的组件存放处,这里我开发一个Hello World例子组件


1.在hot-deploy/ 新建hello文件夹;


2.在hot-deploy/hello 新建ofbiz-component.xml;
- <?xml version="1.0" encoding="UTF-8"?>
<ofbiz-component name="hello" enabled="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
<!--加载当前组件-->
<resource-loader name="main" type="component"/>

<webapp name="hello" 
title="Hello World" 
server="default-server"
base-permission="OFBTOOLS" 
location="webapp/hello" 
mount-point="/hello"
app-bar-display="false" />
<!--name:WEB应用的名称-->
<!--title:网页的标题-->
<!--server:服务器使用-->
<!--base-permission:需要的权限-->
<!--location:项目指定的资源目录-->
<!--mount-point:指定的访问资源目录-->
</ofbiz-component>


3.在hot-deploy/hello 新建webapp文件夹(跟传统的Web项目一样);
- 在hot-deploy/hello/webapp 新建hello文件夹;
- 在hot-deploy/hello/webapp/hello 新建error文件夹;
+ 在hot-deploy/hello/webapp/hello/error 新建error.jsp;
<%@ page import="org.apache.ofbiz.base.util.*" %>
<html>
<head>
<title>OFBiz Message</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<% String errorMsg = (String) request.getAttribute("_ERROR_MESSAGE_"); %>
<body bgcolor="#FFFFFF">
<div align="center">
 <br/>
 <table width="100%" border="1" height="200">
<tr>
 <td>
<table width="100%" border="0" height="200">
 <tr bgcolor="#CC6666">
<td height="45">
 <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="4" color="#FFFFFF"><b>:ERROR MESSAGE:</b></font></div>
</td>
 </tr>
 <tr>
<td>
 <div align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><%=UtilFormatOut.replaceString(errorMsg, "\n", "<br/>")%></font></div>
</td>
 </tr>
</table>
 </td>
</tr>
 </table>
</div>
<div align="center"></div>
</body>
</html>

- 在hot-deploy/hello/webapp/hello 新建index.jsp;
<%response.sendRedirect("control/main");%>



- 在hot-deploy/hello/webapp/hello 新建js文件夹:这个目录作用存放页面需要的JS脚本资源存放;
- 在hot-deploy/hello/webapp/hello 新建css文件夹:这个目录作用存放页面需要的CSS样式资源存放;


4.在hot-deploy/hello 新建widget文件夹:这个目录作用创建表单、菜单、屏幕的一些资源存放;

- 在hot-deploy/hello/widget 新建HelloScreens.xml
<?xml version="1.0" encoding="UTF-8"?>
<screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://ofbiz.apache.org/Widget-Screen" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Screen http://ofbiz.apache.org/dtds/widget-screen.xsd">
<screen name="main">
<section>
<widgets>
<label text="Hello World!! :)"/>
</widgets>
</section>
</screen>
</screens>

- 在hot-deploy/hello/widget 新建CommonScreens.xml
注意:CommonScreens.xml文件内容有点多,这里我就不贴出来了,可以从组件example那里复制一份过来直接使用:example/widget/example/CommonScreens.xml


5.在hot-deploy/hello/webapp/hello 新建WEB-INF文件夹;

- 在hot-deploy/hello/webapp/hello/WEB-INF 新建controller.xml;
<?xml version="1.0" encoding="UTF-8"?>
<site-conf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://ofbiz.apache.org/Site-Conf" xsi:schemaLocation="http://ofbiz.apache.org/Site-Conf http://ofbiz.apache.org/dtds/site-conf.xsd">
<!--导入通用的xml-->
<include location="component://common/webcommon/WEB-INF/common-controller.xml"/>


<request-map uri="main">
<!--是否配置安全协议-->
<security https="true" auth="true"/>
<response name="success" type="view" value="main"/>
<!--name : 返回响应的参数名-->
<!--tyep : 返回响应的类型-->
<!--value : 返回响应的值(如果Type:view,这里对应的值是指定view-map标签的name属性)-->
</request-map>
<view-map name="main" type="screen" page="component://hello/widget/HelloScreens.xml#main"/>
<!--name : 指定的键名-->
<!--type : 指定的类型-->
<!--page : 指定的页面配置文件路径-->
</site-conf>

- 在hot-deploy/hello/webapp/hello/WEB-INF 新建web.xml;
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0">
<context-param>
<param-name>webSiteId</param-name>
<param-value>HELLO</param-value>
</context-param>
<context-param>
<param-name>localDispatcherName</param-name>
<param-value>hello</param-value>
</context-param>
<context-param>
<param-name>mainDecoratorLocation</param-name>
<param-value>component://hello/widget/CommonScreens.xml</param-value>
</context-param>
<context-param>
<param-name>entityDelegatorName</param-name>
<param-value>default</param-value>
</context-param>


<filter>
<display-name>ControlFilter</display-name>
<filter-name>ControlFilter</filter-name>
<filter-class>org.apache.ofbiz.webapp.control.ControlFilter
</filter-class>
<init-param>
<param-name>allowedPaths</param-name>
<param-value>/error:/control:/select:/index.html:/index.jsp:/default.html:/default.jsp:/images:/js:/ws
</param-value>
</init-param>
<init-param>
<param-name>redirectPath</param-name>
<param-value>/control/main</param-value>
</init-param>
</filter>
<filter>
<display-name>ContextFilter</display-name>
<filter-name>ContextFilter</filter-name>
<filter-class>org.apache.ofbiz.webapp.control.ContextFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>ControlFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<listener>
<listener-class>org.apache.ofbiz.webapp.control.ControlEventListener
</listener-class>
</listener>
<listener>
<listener-class>org.apache.ofbiz.webapp.control.LoginEventListener
</listener-class>
</listener>
<!-- NOTE: not all app servers support mounting implementations of the HttpSessionActivationListener 
interface -->
<!-- <listener><listener-class>org.apache.ofbiz.webapp.control.ControlActivationEventListener</listener-class></listener> -->


<servlet>
<description>Main Control Servlet</description>
<display-name>ControlServlet</display-name>
<servlet-name>ControlServlet</servlet-name>
<servlet-class>org.apache.ofbiz.webapp.control.ControlServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ControlServlet</servlet-name>
<url-pattern>/control/*</url-pattern>
</servlet-mapping>


<session-config>
<session-timeout>60</session-timeout><!-- in minutes -->
<cookie-config>
<http-only>true</http-only>
<secure>true</secure>
</cookie-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>


<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

6.启动项目:cmd ->cd ofbiz项目目录下-> gradlew ofbiz

- 访问地址:https://localhost:8443/hello/control/main账号:admin密码:ofbiz

原创粉丝点击