Introduction of each file of a component of ofbiz

 

<?xml version="1.0" encoding="UTF-8"?>
<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://ofbiz.apache.org/Widget-Form"
       xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form
       http://ofbiz.apache.org/dtds/widget-form.xsd">
    <!--Define a form, the attributes have the type of the form, the request address, the default entity name, the default map collection name-->
    <form name="" type="" target="" default-entity-name=""
          default-map-name="" default-table-style="">
        <!--The input box in the form, etc., one field corresponds to one -->
        <field name="" title="">
            <!--Type of input box, input.text hyperlink, drop-down, etc.-->
            <text/>
        </field>
        <field name="" title="">
            <check all-checked=""/>
        </field>
    </form>

</forms>
 Create a new component and use the gradle command

 

 

gradlew createPlugin -PpluginId=sword -PpluginResourceName=Sword
-PwebappName=sword -PbasePermission=SWORD

 For a detailed introduction to this command, you can read the README.md file in the ofbiz project.

 

After creation, the directory is as follows:


The components created with the command are under specialpurpose by default. This directory and the hot-deploy directory are the directories where the components are stored.

The difference between the two is that the specialpurpose directory has the component-load.xml file in the figure, as shown in the figure:

 If we move the created component to the hot-deploy directory, the component can be loaded without adding this file .

 

After entering the module, the ofbiz-component.xml file defines the files that need to be loaded when the component is loaded when the project is started.

 

<?xml version="1.0" encoding="UTF-8"?>
<ofbiz-component name="sword"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">

    <!--Define resource loader-->
    <!-- define resource loaders; most common is to use the component resource loader -->
    <resource-loader name="main" type="component"/>

    <!-- Load the configuration files of the config and dtd directories -->
    <!-- place the config directory on the classpath to access configuration files -->
    <classpath type="dir" location="config"/>
    <classpath type="dir" location="dtd"/>

    <!-- Load the jar package, the jar package in the lib folder in the build directory, the jar package in the lib directory -->
    <!-- load single or multiple external libraries -->
    <classpath type="jar" location="build/lib/*"/>
    <classpath type="jar" location="lib/*"/>

    <!--Load the entity file defined in this component-->
<entity-resource type="model" reader-name="main"
 loader="main" location="entitydef/entitymodel.xml"/>
<!-- <entity-resource type="eca" reader-name="main"
 loader="main" location="entitydef/eecas.xml"/> -->
     <!-- Load data file -->
<entity-resource type="data"
reader-name="seed" loader="main" location="data/SwordTypeData.xml"/>
                                                     
<entity-resource type="data" reader-name="seed"
 loader="main" location="data/SwordSecurityPermissionSeedData.xml"/>
<entity-resource type="data" reader-name="demo"
 loader="main" location="data/SwordSecurityGroupDemoData.xml"/>
<entity-resource type="data" reader-name="demo"
 loader="main" location="data/SwordDemoData.xml"/>

    <!--Load service file-->
    <!-- service resources: model(s), eca(s) and group definitions -->
    <service-resource type="model" loader="main" location="servicedef/services.xml"/>
    <!--
    <service-resource type="eca" loader="main" location="servicedef/secas.xml"/>
    <service-resource type="group" loader="main" location="servicedef/groups.xml"/>
    -->
    <test-suite loader="main" location="testdef/SwordTests.xml"/>

    <!-- web applications; will be mounted when using the embedded container -->
    <!-- web application configuration
    name is the component name,
    base-permission is the access permission,
    mount-point is the path accessed by the component. If it is /, enter https:localhost:8443 for direct access -->
    <webapp name="sword"
        title="Sword"
        server="default-server"
        location="webapp/sword"
        base-permission="OFBTOOLS,SWORD"
        mount-point="/sword"/>
</ofbiz-component>

 

 

When entering https://localhost:8443/sword in the browser to access the component,

Because of a code defined in the sword/webapp/sword/index.html file,

Access will be redirected to: https://localhost:8443/sword/control/main, only one sentence is defined in this file:

 

<%response.sendRedirect("control/main");%>

 

However, this statement does not seem to work in a separate module. Because I changed it and it didn't work, I don't know why!

 

Because the web.xml file is automatically created when a new component is created, it will not be explained here.

 

Next is the controller.xml file that accepts the request and specifies the jump

The file path is: sword/webapp/sword/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">
    <!-- The controller elements that are common to all OFBiz components
         can be found in the following xml file. A component can override the
         elements found in the common-controller.xml file. -->
    <!--Introduce other controller.xml files-->
    <include location="component://common/webcommon/WEB-INF/common-controller.xml"/>

    <description>Sword Component Site Configuration File</description>


    <!-- Events to run on every request after all other processing (chains exempt) -->
    <!--
    <postprocessor>
        <event name="test" type="java" path="org.apache.ofbiz.webapp.event.TestEvent"
invoke="test"/>
    </postprocessor>
    -->
    <!--Accept the request, the requested path will only respond or jump if it is configured here-->
    <!-- Request Mappings -->
    <request-map uri="main">
        <!--Permission security settings, these two attributes represent whether to use https and whether to log in. If you need to log in,
If you request this uri, you will be asked to log in -->
        <security https="true" auth="true"/>
        <!--Response after successful request-->
        <response name="success" type="view" value="main"/>
        <!--Response after failed request-->
        <response name="error" type="view" value="main"/>
    </request-map>
    <!--According to the value of the response defined in the request, a view-map may have multiple responses pointing to -->
    <!-- View Mappings -->
<view-map name="main" type="screen" page="component://sword/widget/SwordScreens.xml#main"/>
</site-conf>

 

 

 

Configure the SwordUiLabels.xml of the internationalization information , the path is sword\config\SwordUiLabels.xml,

 

<?xml version="1.0" encoding="UTF-8"?>
<resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-properties.xsd">
    <property key="SwordApplication">
        <value xml:lang="en">Sword Application</value>
        <value xml:lang="en">Sword Application</value>
        <value xml:lang="zh-TW">Sword Application</value>
    </property>
    <property key="SwordCompanyName">
        <value xml:lang="en">OFBiz: Sword</value>
        <value xml:lang="zh-TW">OFBiz: Sword</value>
    </property>
    <property key="SwordCompanySubtitle">
        <value xml:lang="en">Part of the Apache OFBiz Family of Open Source Software</value>
        <value xml: lang = "it"> A module of the Apache OFBiz open source software family </value>
        <value xml:lang="zh">Open software OFBiz part?</value>
    </property>
    <property key="SwordViewPermissionError">
        <value xml:lang="en">You are not allowed to view this page.</value>
        <value xml:lang="zh">You are not allowed to browse this page?</value>
    </property>
</resource>

 

 

The files that store permission data and permission group data. Half of the data in these files is imported by us and will not be edited by us. 

 

Finally, the main screen file for display,


 

⒈Define the file SwordMenus.xml of the menu screen in the component

 

<?xml version="1.0" encoding="UTF-8"?>
<menus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://ofbiz.apache.org/Widget-Menu"
       xsi:schemaLocation="http://ofbiz.apache.org/Widget-Menu
       http://ofbiz.apache.org/dtds/widget-menu.xsd">
    <menu name="MainAppBar" title="${uiLabelMap.SwordApplication}"
          extends="CommonAppBarMenu"
          extends-resource="component://common/widget/CommonMenus.xml">
        <!--Define a menu button called main, the nested link tag is the jump uri of the menu button,
        Will be received by the controller.xml file -->
        <menu-item name="main" title="${uiLabelMap.CommonMain}">
            <link target="main"/>
        </menu-item>
    </menu>
</menus>

 ⒉ Define the form SwordForms.xml used in the page

 

<?xml version="1.0" encoding="UTF-8"?>
<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://ofbiz.apache.org/Widget-Form"
       xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form
       http://ofbiz.apache.org/dtds/widget-form.xsd">
    <!--Define a form, the attributes have the type of the form, the request address, the default entity name, the default map collection name-->
    <form name="" type="" target="" default-entity-name=""
          default-map-name="" default-table-style="">
        <!--The input box in the form, etc., one field corresponds to one -->
        <field name="" title="">
            <!--Type of input box, input.text hyperlink, drop-down, etc.-->
            <text/>
        </field>
        <field name="" title="">
            <check all-checked=""/>
        </field>
    </form>
</forms>
 3. The file that defines the public decorator of this component , CommonScreen.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-decorator">
        <!--Public Decorators-->
        <section>
            <actions>
                <!--Load internationalization file, set as component global-->
                <property-map resource="SwordUiLabels"
                              map-name="uiLabelMap" global="true"/>
                <property-map resource="CommonUiLabels"
                              map-name="uiLabelMap" global="true"/>

                <!--Set the company name at the top left of the module page and the title of the page
                 title shows the value of SwordCompanyName in the internationalization file
                 -->
                <set field="layoutSettings.companyName"
                     from-field="uiLabelMap.SwordCompanyName" global="true"/>
                <set field="layoutSettings.companySubtitle"
                     from-field="uiLabelMap.SwordCompanySubtitle" global="true"/>

                <set field="activeApp" value="sword" global="true"/>

                <!--This should be a comment related to the project's common module menu, and the entire module will report an error-->
                <set field="applicationMenuName" value="MainAppBar" global="true"/>

                <!--Introduce the menu file of this module-->
                <set field="applicationMenuLocation"
                     value="component://sword/widget/SwordMenus.xml" global="true"/>

                <!--App title, I don't know where it is displayed -->
                <set field="applicationTitle"
                     value="${uiLabelMap.SwordApplication}" global="true"/>
            </actions>
            <widgets>
                <!--Introduce public global decorators-->
                <include-screen name="GlobalDecorator"
                                location="component://common/widget/CommonScreens.xml"/>
            </widgets>
        </section>
    </screen>

    <screen name="SwordCommonDecorator">
        <section>
            <actions>
            </actions>
            <widgets>
                <decorator-screen name="main-decorator"
                                  location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <section>
                            <!--Verify permission information-->
                            <condition>
                                <if-has-permission permission="SWORD" action="_VIEW"/>
                            </condition>
                            <widgets>
                                <decorator-section-include name="body"/>
                            </widgets>
                            <fail-widgets>
                                <!--Prompt message after unable to log in-->
                                <label style="h3">${uiLabelMap.SwordViewPermissionError}</label>
                            </fail-widgets>
                        </section>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
</screens>

 ⒋Define the file of the displayed screen returned after accepting the request, SwordScreens.xm

 

<?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>
            <actions>
                <!--After clicking the component first, the dark color shows that the component is selected-->
                <set field="headerItem" value="main"/>
                <!-- this highlights the selected menu-item with name "main" -->
            </actions>
            <widgets>
                <!--Use the definition in CommonScreen, the section attribute name is body-->
                <decorator-screen name="SwordCommonDecorator"
                                  location="${parameters.mainDecoratorLocation}">
                    <decorator-section name="body">
                        <!--Add form screen here-->
                        <include-form name="" location=""/>
                        <!--Add menu screen-->
                        <include-menu name="" location=""/>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
</screens>

 These are the files that are mainly used for the time being, they are written in a mess, alas

 

 

 

 

 


 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326254829&siteId=291194637