ofbiz实现oracle平台小例子详解步骤及注意的问题

来源:互联网 发布:硬件和软件 哪个 编辑:程序博客网 时间:2024/05/17 02:21
一 , 在配置的过程中需要注意一下几点:(请先完成下面的小例子,再进行构建)
1,一般项目都是创建在hot-deploy目录下
2,数据源的配置在D:/ofbiz/framework/entity/configf下的entityengine.xml文件
    其中在配置oracle数据源时需要把schema-name="OFBIZ"属性删除,避免数据库实例不是ofbiz的情况,
    具体的文件内容会复制在文件最后
3 , D:/ofbiz/framework/entity/lib/jdbc需要在该目录下加入ojdbc.jar
4,在D:/ofbiz/framework/base/config目录下有ofbiz-containers.xml,里面定义了ofbiz项目启动时服务的端口,初始为8080
    建议在初期开发是不要更改该端口,如果出现oracle端口和8080冲突时,建议更改oracle的http服务的端口,因为在ofbiz
    提供的一些application中很多地方是把端口写死为8080,如果更改不方便访问一些应用程序
5 , 更改完数据源配置时需要重构ofbiz目录,具体做法如下
 在ofbiz根目录下,运行指令ant clean-all ,接着运行指令ant run-install
 执行完这两个ant的时候就已经完成了对数据库的映射
 注:如果是郭刚提供的ofbiz框架,在ant前,需要把D:/ofbiz/specialpurpose目录下的build.xml文件中的meetingroom/build.xml删除
6 , 框架重构完成以后,在用 java  -Xmx512m -jar ofbiz.jar进行启动时,可能会出现job_sandbox表出现异常,这时
 需要把该表中的RUN_BY_INSTANCE_ID字段全部手动填上值,并commit, 注:我全是负值为1

 

二 , 简单增删改查实例实现详细步骤:
 step1 :    首先在hot-deploy创建一个新的项目目录:hellosix
   在该目录下新建ofbiz-component.xml
   该xml文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<ofbiz-component name="hellosix"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/ofbiz-component.xsd">
    <!-- define resource loaders; most common is to use the component resource loader -->
    <resource-loader name="main" type="component"/>
    <!-- place the config directory on the classpath to access configuration files -->
    <classpath type="dir" location="config"/>
    <classpath type="dir" location="dtd"/>
    <classpath type="dir" location="script"/>
    <!-- load single or multiple external libraries -->
    <classpath type="jar" location="build/lib/*"/>
    <!-- entity resources: model(s), eca(s), group, and data definitions -->
    <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
    <entity-resource type="group" reader-name="main" loader="main" location="entitydef/entitygroup.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services.xml"/>
    <!-- web applications; will be mounted when using the embedded Jetty container -->
    <webapp name="hellosix"
        title="UserExample"
        server="default-server"
        location="webapp/hellosix"
        base-permission="OFBTOOLS"
        mount-point="/hellosix"/>
</ofbiz-component>


 step2 :    在hellosix目录下创建一个entitydef目录
   在该目录下创建entitygroup.xml  , entitymodel.xml两个文件
   entitygroup.xml文件内容为:
   <?xml version="1.0" encoding="UTF-8"?>
   <entitygroup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/entitygroup.xsd">
         <entity-group group="org.ofbiz" entity="UserExample"/>
          </entitygroup>

   entitymodel.xml文件内容为:
   <?xml version="1.0" encoding="UTF-8"?>
   <entitymodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/entitymodel.xsd">
       <!-- ========================================================= -->
       <!-- ======================== Defaults ======================= -->
       <!-- ========================================================= -->
       <title>Entity of an Open For Business Project Component</title>
       <description>None</description>
       <copyright>Copyright 2001-2006 The Apache Software Foundation</copyright>
       <author>None</author>
       <version>1.0</version>
       <entity entity-name="UserExample" package-name="org.ofbiz.hellosix" title="UserExample Entity">
    <field name="userexampleId" type="id-ne"><!-- primary sequenced ID --></field>
    <field name="userexampleName" type="name"></field>
    <field name="description" type="description"></field>
    <field name="longDescription" type="very-long"></field>
    <field name="comments" type="comment"></field>
    <field name="userexampleSize" type="numeric"></field>
    <field name="userexampleDate" type="date-time"></field>
    <prim-key field="userexampleId"/>
       </entity>
   </entitymodel>

   到此为止我们就定义好了Schema,注意:在ofbiz-component.xml,里面有对entitymodel.xml和entitygroup.xml的引用


step3 : 启动ofbiz 访问url:http://localhost:8080/webtools/constrol/main,点击右上方的"Login"
            用admin/ofibz 登陆,登陆进入后选择链接"Check/Update DataBase" ,这是会出现Check 的Form
     该表单验证Schema是否改变,默认的GroupName为org.ofbiz.
     点击"Check/Update DataBase"按钮,Ofbiz会检验变动情况,显示出一个详细列表,你可以检查一下
     我们刚才建的"UserExample",如果没有,那可能就是我们前面定义的xml文件有问题了,按照之前的不步骤
     重新再做一遍

     到现在为止,我们就成功的完成了,UserExample Schema的创建.

step 4 : 下面我们创建数据操作层
             在d:/ofbiz/hot-deploy/hellosix/ 下创建servicedef目录
      在该文件下创建services.xml文件
      该文件内容如下:

      <?xml version="1.0" encoding="UTF-8"?>
  <services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/services.xsd">
      <description>UserExample Services</description>
      <vendor>OFBiz</vendor>
      <version>1.0</version>
      <!-- Example & Related Services -->
      <service name="createUserExample" default-entity-name="UserExample" engine="simple"
       location="org/ofbiz/hellosix/UserExampleServices.xml" invoke="createUserExample" auth="false">
   <description>Create a UserExample</description>
   <auto-attributes include="pk" mode="OUT" optional="false"/>
   <auto-attributes include="nonpk" mode="IN" optional="true"/>
   <override name="userexampleName" optional="false"/>
      </service>
      <service name="updateUserExample" default-entity-name="UserExample" engine="simple"
         location="org/ofbiz/hellosix/UserExampleServices.xml" invoke="updateUserExample" auth="false">
   <description>Update a UserExample</description>
   <auto-attributes include="pk" mode="IN" optional="false"/>
   <auto-attributes include="nonpk" mode="IN" optional="true"/>
      </service>
      <service name="deleteUserExample" default-entity-name="UserExample" engine="simple"
         location="org/ofbiz/hellosix/UserExampleServices.xml" invoke="deleteUserExample" auth="false">
   <description>Delete a Example</description>
   <auto-attributes include="pk" mode="IN" optional="false"/>
      </service>
     </services>

 
step 5 :    在D:/ofbiz/hot-deploy/hellosix/下
  创建目录/script/org/ofbiz/hellosix
  在该目录下创建UserExampleServices.xml
  该文件内容如下:
  <?xml version="1.0" encoding="UTF-8"?>
  <simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/simple-methods.xsd">
      <!-- Example methods -->
      <simple-method method-name="createUserExample" short-description="create a UserExample" login-required="false">
   <make-value entity-name="UserExample" value-name="newEntity"/>
   <sequenced-id-to-envsequence-name="UserExample" env-name="newEntity.userexampleId"/><!-- get the next sequenced ID -->
   <field-to-result field-name="newEntity.userexampleId" result-name="userexampleId"/>
   <set-nonpk-fields map-name="parameters" value-name="newEntity"/>
   <create-value value-name="newEntity"/>
      </simple-method>  
      <simple-method method-name="updateUserExample" short-description="update a UserExample" login-required="false">
   <entity-one entity-name="UserExample" value-name="lookedUpValue"/>
   <!-- handle statusId change stuff; first put the current statusId in the oldStatusId result -->
   <set-nonpk-fields map-name="parameters" value-name="lookedUpValue"/>
   <store-value value-name="lookedUpValue"/>
      </simple-method>
      <simple-method method-name="deleteUserExample" short-description="delete a Example" login-required="false">
   <entity-one entity-name="UserExample" value-name="lookedUpValue"/>
   <remove-value value-name="lookedUpValue"/>
      </simple-method>
  </simple-methods>


上面定义了:增,删,改的数据操作方法的定义
这几个方法在services.xml中提供了用户权限的检查

 

step6 :     创建显示层
  在D:/ofbiz/hot-deploy/hellosix/widget/hellosix下创建目录
  widget/hellosix
  在该目录下创建CommonScreen.xml,UserExampleForms.xml,UserExampleMenus.xml,UserExampleScreens.xml
  其中CommonScreen.xml内容如下:

  <?xml version="1.0" encoding="UTF-8"?>
   <screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/widget-screen.xsd">
       <screen name="main-decorator">
    <section>
        <actions>
     <!-- base/top/specific map first, then more common map added for shared labels -->
     <property-map resource="ExampleUiLabels" map-name="uiLabelMap" global="true"/>
     <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/>
     <set field="layoutSettings.companyName" from-field="uiLabelMap.ExampleCompanyName" global="true"/>
     <set field="layoutSettings.companySubtitle" from-field="uiLabelMap.ExampleCompanySubtitle" global="true"/>
     <set field="layoutSettings.headerImageUrl" value="/images/ofbiz_logo.jpg" global="true"/>
     <!-- <set field="layoutSettings.headerMiddleBackgroundUrl" value="" global="true"/> -->
     <!-- <set field="layoutSettings.headerRightBackgroundUrl" value="" global="true"/> -->
     <set field="activeApp" value="userexample" global="true"/>
     <set field="appheaderTemplate" value="component://hellosix/webapp/hellosix/includes/appheader.ftl" global="true"/>
        </actions>
        <widgets>
     <include-screen name="GlobalDecorator" location="component://common/widget/CommonScreens.xml"/>
        </widgets>
    </section>
       </screen>
       <screen name="main">
    <section>
        <widgets>
     <decorator-screen name="main-decorator">
         <decorator-section name="body">
      <container style="screenlet">
          <container style="screenlet-header">
       <label style="boxhead" text="Example Main Page"/>
          </container>
          <container style="screenlet-body">
       <section>
           <condition><if-empty field-name="userLogin"/></condition>
           <widgets>
        <container><label text="${uiLabelMap.ExampleMessage}"/></container>
           </widgets>
       </section>
       <container><label text="${uiLabelMap.ExampleWelcome}"/></container>
          </container>
      </container>
         </decorator-section>
     </decorator-screen>
        </widgets>
    </section>
       </screen>
       <screen name="login">
    <section>
        <widgets>
     <decorator-screen name="main-decorator">
         <decorator-section name="body">
      <platform-specific>
          <html><html-template location="component://common/webcommon/login.ftl"/></html>
      </platform-specific>
         </decorator-section>
     </decorator-screen>
        </widgets>
    </section>
       </screen>
   </screens>

 


  UserExampleForms.xml内容如下:


  <?xml version="1.0" encoding="UTF-8"?>
   <forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/widget-form.xsd">
       <form name="ListUserExamples" type="list" list-name="examples"
     paginate-target="FindUserExample">
    <actions>
        <entity-condition entity-name="UserExample"><order-by field-name="description"/></entity-condition>
    </actions>
    <field name="userexampleId" title="${uiLabelMap.ExampleExampleId}" widget-style="buttontext">
       <hyperlink also-hidden="false" description="${userexampleId}"target="EditUserExample?userexampleId=${userexampleId}"/>
    </field>
    <field name="userexampleName" title="${uiLabelMap.CommonName}"><display/></field>
    <field name="description" title="${uiLabelMap.CommonDescription}"><display/></field>
     <field name="deleteexampleId" title="${uiLabelMap.ExampleExampleId}" widget-style="buttontext">
       <hyperlink also-hidden="true" description="${userexampleId}"target="deleteUserExample?userexampleId=${userexampleId}"/>
    </field>
       </form>
       <form name="EditUserExample" type="single" target="updateUserExample" title="" default-map-name="userexample">
           <alt-target use-when="userexample==null" target="createUserExample"/>
     <auto-fields-service service-name="updateUserExample"/>
   <field use-when="userexample!=null" name="userexampleId"title="${uiLabelMap.ExampleExampleId}"tooltip="${uiLabelMap.CommonNotModifRecreat}"><display/></field>
    <fielduse-when="userexample==null&amp;&amp;userexampleId==null"name="userexampleId"title="${uiLabelMap.ExampleExampleId}"><ignored/></field>
    <fielduse-when="userexample==null&amp;&amp;userexampleId!=null"name="userexampleId"title="${uiLabelMap.ExampleExampleId}"><displaydescription="${uiLabelMap.CommonCannotBeFound}: [${userexampleId}]"also-hidden="false"/></field>        
    <field name="description" title="${uiLabelMap.CommonDescription}"/>
    <fieldname="submitButton" use-when="example==null"title="${uiLabelMap.CommonCreate}"><submitbutton-type="button"/></field>
    <fieldname="submitButton" use-when="example!=null"title="${uiLabelMap.CommonUpdate}"><submitbutton-type="button"/></field>
       </form>
       </forms>

 


  UserExampleMenus.xml内容如下:
  <?xml version="1.0" encoding="UTF-8"?>
   <menus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/widget-menu.xsd">     
       <menu name="EditUserExample" default-selected-style="selected"
        menu-container-style="button-bar button-style-1"
        selected-menuitem-context-field-name="tabButtonItem"
        type="simple">
    <menu-item name="EditUserExample" title="${uiLabelMap.ExampleExample}">
        <link target="EditUserExample?userexampleId=${userexampleId}"/>
    </menu-item>
       </menu>
   </menus>

 

  UserExampleScreens.xml内容如下:

  <?xml version="1.0" encoding="UTF-8"?>
   <screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/widget-screen.xsd">
       <screen name="FindUserExample">
    <section>
        <actions>
     <set field="headerItem" value="UserExample"/>
     <set field="titleProperty" value="PageTitleFindExample"/>
        </actions>
        <widgets>
     <decorator-screen name="main-decorator" location="component://hellosix/widget/hellosix/CommonScreens.xml">
         <decorator-section name="body">
      <section>
          <widgets>
       <container><label style="head1">${uiLabelMap.${titleProperty}}</label></container>
       <containerstyle="button-bar"><link target="EditUserExample"text="${uiLabelMap.ExampleNewExample}"style="buttontext"/></container>
       <include-form name="ListUserExamples" location="component://hellosix/widget/hellosix/UserExampleForms.xml"/>
          </widgets>
          <fail-widgets>
       <label style="head3">${uiLabelMap.ExampleViewPermissionError}</label>
          </fail-widgets>
      </section>
         </decorator-section>
     </decorator-screen>
        </widgets>
    </section>
       </screen>
       <screen name="CommonExampleDecorator">
    <section>
        <actions>
     <set field="headerItem" value="UserExample"/>
     <set field="userexampleId" from-field="parameters.userexampleId"/>
     <entity-one entity-name="UserExample" value-name="userexample"/>
        </actions>
        <widgets>
     <decorator-screen name="main-decorator" location="component://hellosix/widget/hellosix/CommonScreens.xml">
         <decorator-section name="body">
      <section>
         <widgets>
       <section>
           <condition>
        <not><if-empty field-name="userexample"/></not>
           </condition>
           <widgets>
        <include-menu name="EditUserExample" location="component://hellosix/widget/hellosix/UserExampleMenus.xml"/>
        <containerstyle="button-bar"><link target="EditUserExample"text="${uiLabelMap.ExampleNewExample}"style="buttontext"/></container>
        <containerstyle="button-bar"><labelstyle="head1">${uiLabelMap.${titleProperty}}</label><labelstyle="head2"> ${uiLabelMap.CommonFor}"${userexample.userexampleName}"[${userexampleId}]</label></container>
           </widgets>
       </section>
       <decorator-section-include name="body"/>
          </widgets>
          <fail-widgets>
       <label style="head3">${uiLabelMap.ExampleViewPermissionError}</label>
          </fail-widgets>
      </section>                   
         </decorator-section>
     </decorator-screen>
        </widgets>
    </section>
       </screen>
       <screen name="EditUserExample">
    <section>
        <actions>
     <set field="titleProperty" value="PageTitleEditExample"/>
     <set field="tabButtonItem" value="EditUserExample"/>
     <set field="userexampleId" from-field="parameters.userexampleId"/>
     <entity-one entity-name="UserExample" value-name="userexample"/>
        </actions>
        <widgets>
     <decorator-screen name="CommonExampleDecorator">
         <decorator-section name="body">
      <include-form name="EditUserExample" location="component://hellosix/widget/hellosix/UserExampleForms.xml"/>
         </decorator-section>
     </decorator-screen>
        </widgets>
    </section>
       </screen>
       </screens>

step 7 :    下面需要在controller.xml进行mapping的设置
  在D:/ofbiz/hot-deploy/hellosix/下创建目录webapp/hellosix
  在D:/ofbiz/hot-deploy/hellosix/webapp/hellosix下
  创建一个文件index.jsp,创建三个目录error,includes, WEB-INF
  index.jsp内容如下:
  <%response.sendRedirect("control/main");%>


  在D:/ofbiz/hot-deploy/hellosix/webapp/hellosix/error创建error.jsp
  error.jsp内容如下:

  <%@ page import="org.ofbiz.base.util.*" %>
  <html>
  <head>
  <title>Open For Business Message</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  </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>:ERRORMESSAGE:</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>


  在D:/ofbiz/hot-deploy/hellosix/webapp/hellosix/includes下创建文件appheader.ftl
  该文件内容如下:

  <#assign selected = headerItem?default("void")>

  <div id="app-navigation">
    <h2>${uiLabelMap.ExampleApplication}</h2>
    <ul>
      <li<#if selected = "main"> class="selected"</#if>><a href="<@ofbizUrl>main</@ofbizUrl>">${uiLabelMap.CommonMain}</a></li>
      <li<#if selected = "Example"> class="selected"</#if>><a href="<@ofbizUrl>FindUserExample</@ofbizUrl>">${uiLabelMap.ExampleExample}</a></li>
     
      <#if userLogin?has_content>
        <li class="opposed"><a href="<@ofbizUrl>logout</@ofbizUrl>">${uiLabelMap.CommonLogout}</a></li>
      <#else>
        <li class="opposed"><a href="<@ofbizUrl>${checkLoginUrl?if_exists}</@ofbizUrl>">${uiLabelMap.CommonLogin}</a></li>
      </#if>
    </ul>
    <br class="clear" />
  </div>


  在D:/ofbiz/hot-deploy/hellosix/webapp/hellosix/WEB-INF下
  创建二个文件controller.xml,web.xml
  其中controller.xml内容如下:

  <?xml version="1.0" encoding="UTF-8"?>
  <site-conf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/site-conf.xsd">
      <description>Example Component Site Configuration File</description>
      <owner>Copyright 2001-2006 The Apache Software Foundation</owner>
      <errorpage>/error/error.jsp</errorpage>
     
      <!-- event handlers -->
      <handler name="java" type="request" class="org.ofbiz.webapp.event.JavaEventHandler"/>
      <handler name="soap" type="request" class="org.ofbiz.webapp.event.SOAPEventHandler"/>
      <handler name="service" type="request" class="org.ofbiz.webapp.event.ServiceEventHandler"/>
      <handler name="simple" type="request" class="org.ofbiz.webapp.event.SimpleEventHandler"/>

      <!-- view handlers -->
      <handler name="screen" type="view" class="org.ofbiz.widget.screen.ScreenWidgetViewHandler"/>
      <handler name="screenfop" type="view" class="org.ofbiz.widget.screen.ScreenFopViewHandler"/>
      <handler name="jsp" type="view" class="org.ofbiz.webapp.view.JspViewHandler"/>
      <handler name="http" type="view" class="org.ofbiz.webapp.view.HttpViewHandler"/>
     
      <!--
        These can be used to return the reports as views; make sure the classes are compiled and available
   <handler name="datavision" type="view" class="org.ofbiz.webapp.view.DataVisionViewHandler"/>
   <handler name="jasperreportspdf" type="view" class="org.ofbiz.webapp.view.JasperReportsPdfViewHandler"/>
   <handler name="jasperreportsxml" type="view" class="org.ofbiz.webapp.view.JasperReportsXmlViewHandler"/>
      -->
   
    
      <postprocessor>
   <!-- Events to run on every request after all other processing (chains exempt) -->
   <!-- <event type="java" path="org.ofbiz.webapp.event.TestEvent" invoke="test"/> -->
      </postprocessor>

      <!-- Security Mappings -->
      <request-map uri="checkLogin" edit="false">
   <description>Verify a user is logged in.</description>
   <security https="true" auth="false"/>
   <event type="java" path="org.ofbiz.webapp.control.LoginWorker" invoke="checkLogin" />
   <response name="success" type="view" value="main"/>
   <response name="error" type="view" value="login"/>
      </request-map>
      <request-map uri="login">
   <security https="true" auth="false"/>
   <event type="java" path="org.ofbiz.webapp.control.LoginWorker" invoke="login"/>
   <response name="success" type="view" value="main"/>
   <response name="error" type="view" value="login"/>
      </request-map>
      <request-map uri="logout">
   <security https="true" auth="true"/>
   <event type="java" path="org.ofbiz.webapp.control.LoginWorker" invoke="logout"/>
   <response name="success" type="request" value="checkLogin"/>
   <response name="error" type="view" value="main"/>
      </request-map>
      <!-- End of Security Mappings -->

      <!-- Request Mappings -->
      <request-mapuri="main"><security https="true" auth="false"/><responsename="success" type="view" value="main"/></request-map>
     <request-map uri="authview"><security https="true"auth="false"/><response name="success" type="view"value="main"/></request-map>
      <request-map uri="setSessionLocale">
   <security https="true" auth="false"/>
   <event type="java" path="org.ofbiz.common.CommonEvents" invoke="setSessionLocale"/>
   <response name="success" type="view" value="main"/>
   <response name="error" type="view" value="main"/>
      </request-map>

      <!-- Example Requests -->
      <request-mapuri="FindUserExample"><response name="success" type="view"value="FindUserExample"/></request-map>
     <request-map uri="EditUserExample"><response name="success"type="view" value="EditUserExample"/></request-map>
      <request-map uri="createUserExample">
   <security https="true" auth="false"/>
   <event type="service" path="" invoke="createUserExample"/>
   <response name="success" type="view" value="EditUserExample"/>
   <response name="error" type="view" value="EditUserExample"/>
      </request-map>
      <request-map uri="updateUserExample">
   <security https="true" auth="false"/>
   <event type="service" path="" invoke="updateUserExample"/>
   <response name="success" type="view" value="EditUserExample"/>
   <response name="error" type="view" value="EditUserExample"/>
      </request-map>
   <request-map uri="deleteUserExample">
   <security https="true" auth="false"/>
   <event type="service" path="" invoke="deleteUserExample"/>
   <response name="success" type="view" value="FindUserExample"/>
   <response name="error" type="view" value="FindUserExample"/>
      </request-map>

     
      
    <!-- end of request mappings -->

      <!-- View Mappings -->
      <view-map name="error" page="/error/error.jsp"/>

      <view-map name="main" type="screen" page="component://unifyuser/widget/unifyuser/CommonScreens.xml#main"/>
      <view-map name="login" type="screen" page="component://unifyuser/widget/unifyuser/CommonScreens.xml#login"/>

      <view-map name="FindUserExample" type="screen"page="component://unifyuser/widget/unifyuser/UserExampleScreens.xml#FindUserExample"/>
     <view-map name="EditUserExample" type="screen"page="component://unifyuser/widget/unifyuser/UserExampleScreens.xml#EditUserExample"/>
      <!-- end of view mappings -->
  </site-conf>


  web.xml文件内容如下:

  <?xml version="1.0" encoding="UTF-8"?>
   <web-app>
       <display-name>Open For Business - Example Component</display-name>
       <description>Example Component of the Open For Business Project</description>
      
       <context-param>
    <param-name>localDispatcherName</param-name><param-value>example</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>

       <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>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
       </welcome-file-list>
   </web-app>

 

到此一个简单的增删改的操作就算完成了,访问地址为:
URL: http://localhost:8080/hellosix/control/main

 

 

三 , 快速了解ofbiz配置
     ofbiz框架中的几个重要文件说明
   1 , component-load.xml
       路径:ofbiz/application/
      作用:定义了所有在OFBIZ启动时需要加载的应用程序的位置。所以,当你创建了新的应用程序时,别忘了在该文件中添加应用程                 序的位置信息。在ofbiz/hot-deploy/目录下的应用程序不需要在component-load.xml里定义,ofbiz启动时会自动加载所有
      hot-deploy下的内容。
       经典内容:
                <load-component component-location="${ofbiz.home}/applications/content" />

   2 , ofbiz-component.xml
 路径:基于ofbiz的任何应用程序根目录下,如ofbiz/applications/accounting/
 作用:指出该应用程序数据模型(<entity-resource>),商业逻辑(<service-resource>),web应用程序(<webapp.../>)的位置.
   经典内容:
   <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml" />
   <service-resource type="model" loader="main" location="servicedef/services_agreement.xml" />
  <webapp name="accounting" title="Accounting"server="default-server" location="webapp/accounting"base-   permission="OFBTOOLS,ACCOUNTING" mount-point="/accounting" />

   3 , web.xml
   位置:(以accounting为例)accounting/webapp/accounting/WEB-INF
   作用:配置main servlet(s),控制后台服务器(如tomcat server),及一些相关参数。
   经典内容:
   <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>
 
  4 , controller.xml
   位置:(以accounting为例)accounting/webapp/accounting/WEB-INF
   作用:负责控制接收到的请求request。任何到来的请求,无论是屏幕请求,还是服务请求或事件请求,都要经过controller.xml的处       理,然后转交给相应的相应的部分处理。
   经典内容:
   <request-map uri="main">
   <security https="true" auth="true" />
   <response name="success" type="view" value="main" />
   </request-map>
   <view-map name="main" type="screen" page="component://accounting/widget/CommonScreens.xml#main" />
  (当请求"main"到来时,在controller.xml中,先找到<request-mapuri="main">,根据其value="main",继续向下找到view-map name="main",最后得到该请求该返回的页面位置page="component://accounting/widget/CommonScreens.xml#main" )


原创粉丝点击