最近在研究OFBIZ,在12.4的版本下写一个最简单的例子。
1. 首先在hot-deploy下面建各种文件以及文件夹,结构如图所示
2.ofbiz-component.xml文件如下
<?xml version="1.0" encoding="UTF-8"?> <ofbiz-component name="simple" 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="simple" title="Simple" server="default-server" base-permission="OFBTOOLS" location="webapp/simple" mount-point="/simple" app-bar-display="false"/> </ofbiz-component>
3.SimpleScreens.xml文件如下
<?xml version="1.0" encoding="UTF-8"?> <screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/widget-screen.xsd"> <screen name="main"> <section> <widgets> <label text="This is first simple"/> </widgets> </section> </screen> </screens>
4.index.jsp 内容如下
<%response.sendRedirect("control/main");%>
5. web.xml内容如下
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>simple</display-name> <description>The First Hello World Application</description> <context-param> <param-name>entityDelegatorName</param-name> <param-value>default</param-value> <description>The Name of the Entity Delegator to use, defined in entityengine.xml</description> </context-param> <context-param> <param-name>localDispatcherName</param-name> <param-value>simple</param-value> <description>A unique name used to identify/recognize the local dispatcher for the Service Engine</description> </context-param> <context-param> <param-name>mainDecoratorLocation</param-name> <param-value>component://simple/widget/CommonScreens.xml</param-value> <description>The location of the main-decorator screen to use for this webapp; referred to as a context variable in screen def XML files.</description> </context-param> <filter> <filter-name>ContextFilter</filter-name> <display-name>ContextFilter</display-name> <filter-class>org.ofbiz.webapp.control.ContextFilter</filter-class> <init-param> <param-name>disableContextSecurity</param-name> <param-value>N</param-value> </init-param> <init-param> <param-name>allowedPaths</param-name> <param-value>/control:/select:/index.html:/index.jsp:/default.html: /default.jsp:/images:/includes/maincss.css</param-value> </init-param> <init-param> <param-name>errorCode</param-name> <param-value>403</param-value> </init-param> <init-param> <param-name>redirectPath</param-name> <param-value>/control/main</param-value> </init-param> </filter> <filter-mapping> <filter-name>ContextFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener><listener-class> org.ofbiz.webapp.control.ControlEventListener</listener-class></listener> <listener><listener-class> org.ofbiz.webapp.control.LoginEventListener</listener-class></listener> <!-- NOTE: not all app servers support mounting implementations of the HttpSessionActivationListener interface --> <!-- <listener><listener-class> org.ofbiz.webapp.control.ControlActivationEventListener</listener-class></listener> --> <servlet> <servlet-name>ControlServlet</servlet-name> <display-name>ControlServlet</display-name> <description>Main Control Servlet</description> <servlet-class>org.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 --> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
6. controller.xml内容如下
<?xml version="1.0" encoding="UTF-8"?> <site-conf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/site-conf.xsd"> <include location="component://common/webcommon/WEB-INF/common-controller.xml"/> <description>Practice Component Site Configuration File</description> <owner>Copyright 2001-2009 The Apache Software Foundation</owner> <handler name="screen" type="view" class="org.ofbiz.widget.screen.ScreenWidgetViewHandler"/> <!-- Request Mappings --> <request-map uri="main"> <security https="false" auth="false"/> <response name="success" type="view" value="main"/> </request-map> <!-- end of request mappings --> <!-- View Mappings --> <view-map name="main" type="screen" page="component://simple/widget/SimpleScreens.xml#main"/> <!-- change the path to the following if the above doesn't work for you --> <!-- <view-map name="main" type="screen" page="component://practice/webapp/practice/widget/PracticeScreens.xml#main"/> --> <!-- end of view mappings --> </site-conf>
7. 运行的结果如下:
注意几点:
1. 在这里不要main.ftl文件, 所展示的内容就是SimpleScreens.xml里面的东西
2. opentaps里面的东西有点老,虽然是Si写的