Create a component
Step 1: Create a subdirectory under hot-deploy and name it "computer". The directory name must match the component name we want to create.
Step 2: Create a ofbiz-component.xml file in the hot-deploy/computer path and fill in the following content.
<?xml version="1.0" encoding="UTF-8"?><ofbiz-component name="computer"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="computer" title="Computer" server="default-server"base-permission="OFBTOOLS" location="webapp/computer" mount-point="/computer"app-bar-display="false" /></ofbiz-component>
1. This ofbiz-component.xml file is responsible for letting OFBiz know the location of the resource and letting you add to classpath.
2. the 'Resource-loader name' can be any string. Here we set it to "Main". This 'type' tells OFBiz that we will start to load a component.
3. In Tags have different attributes and their purposes are as follows:
A) Name:-defines the name of our web application.
B) Title:-The Application ID will be displayed on the top navigation bar.
C) server:-This lets OFBiz know which server to use
D) Base-permission:-This line requires the user to have the ofbtools permission to use this application. Because the 'admin' user has this permission, we do not need to create other new users.
E) Location:-default location of the Reference Path on this server.
F) Mount-point:-this is the URL to access the resource, which should be localhost: 8080/Computer
G) app-bar-display:-This is to let OFBiz know whether to display on the main application navigation bar, which is part of the Public OFBiz modifier.
Create a web application
Step 1: create a "webapp" Directory (hot-deploy/computer/webapp) in the computer component. This directory contains all the webapp directories related to this component.
Step 2: create a sub-directory named "computer" under the webapp directory. This is the name of the webapp to be developed (hot-deploy/computer/webapp/computer ).
Step 3: Create the WEB-INF directory (hot-deploy/computer/webapp/computer/WEB-INF) under your webapp ). An OFBiz web application must have two configuration files: controller. XML and Web. xml. The Controller. xml tells OFBiz to do different things from different requests from visitors: what actions and what pages to render. Web. xml tells OFBiz what resources (database and business logic access) are effective for this web application and how to handle web-related matters, such as welcome pages, redirects, and error pages ..
Step 3: create a file named "Web. xml" (Web. xml complies with J2EE Web application specifications). The content of this file is as follows:
<?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"><!--Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the"License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing,software distributed under the License is distributed on an"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied. See the License for thespecific language governing permissions and limitationsunder the License.--><web-app> <display-name>Open For Business - Computer Application</display-name> <description>Computer Application of the Open For Business Project</description> <context-param> <param-name>webSiteId</param-name> <param-value>COMPUTER</param-value> <description>A unique ID used to look up the WebSite entity</description> </context-param> <context-param> <param-name>localDispatcherName</param-name><param-value>computer</param-value> <description>A unique name used to identify/recognize the local dispatcher for the Service Engine</description> </context-param> <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>mainDecoratorLocation</param-name> <param-value>component://computer/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> <!-- context-param> <param-name>widgetVerbose</param-name> <param-value>false</param-value> <description>Enable/disable widget boundary comments. will override widget.properties See org.ofbiz.widget.ModelWidget.widgetBoundaryCommentsEnabled().</description> </context-param--> <context-param> <param-name>compressHTML</param-name> <param-value>false</param-value> <description>Remove unnecessary whitespace from HTML output.</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>/error:/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>index.html</welcome-file> <welcome-file>index.htm</welcome-file> </welcome-file-list></web-app>
Step 5: create a file named "Controller. xml" (used by the OFBiz webapp Controller. This file started to be small and simple, but then we added features and grew rapidly. The Code is as follows:
<?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>Computer Component Site Configuration File</description><owner>Copyright 2001-2009 The Apache Software Foundation</owner>
Step 6: Create an index. jsp in the directory hot-deploy/computer/webapp/computer. The Code is as follows:
<%response.sendRedirect("control/main");%>
Step 7: create a "widget" (hot-deploy/practice/widget) in your component directory practice ). this directory contains forms, menus, and screens for processing user interfaces.
Step 8: create a file "computerscreens. xml" in "widget". The Code is as follows:
<?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 computer" /></widgets></section></screen></screens>
Step 9: restart OFBiz. After startup, enter http: // localhost: 8080/computer/control/main to view the following interface: