Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Step - 2 : Create the ofbiz-component.xml file on path hot-deploy/practice and place following content in it (for reference you can check this file in any other component of OFBiz):

Code Block
<?xml 	version="1.0" encoding="UTF-8"?><ofbiz>
<ofbiz-component name="practice"
       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="practice"
       title="Practice"
       server="default-server"
       base-permission="OFBTOOLS"
       location="webapp/practice"
       mount-point="/practice"
       app-bar-display="false"/>
</ofbiz-component>

...

Code Block
<?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-2008 The Apache Software Foundation</owner> owner>

       <!-- Request Mappings -->       <request>

       <request-map uri="main"><security>
           <security https="false" auth="false"/><response>
           <response name="success" type="view" value="main"/><>
       </request-map> map>

       <!-- end of request mappings -->

       <!-- View Mappings -->

          <view<view-map name="main" type="screen" page="component://practice/widget/PracticeScreens.xml#main"/>       <>

       <!-- end of view mappings -->

</site-conf>

...

All these readings will be really of help.
Very first screen will be like :

Code Block

<?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">

...

{color}
        <section>
            <widgets>
                <label text="This is first practice"/

...

>{color}
            </widgets>
        </section>{color}
    </screen>

</screens>

Step - 9 : Now that we have the basic elements in place lets review the basic flow no matter how large or complex your component gets. First a request will be made by a browser to see a specific resource. Take for example the request:

...

Step - 2 : Create a menu for this application. For this create a file by name PracticeMenus.xml in "widget" directory of you component. For this take a reference from ExampleMenus.xml file of "example" component.

Step - 3:  Create the sub-directory "actions" inside the WEB-INF directory.
               In this directory we will create the scripting files. Scripting files are used to prepare data on fly. These files will be groovy files. Earlier we were using bsh(beanshell) files. This is a script which is used to fetch the data from database on the fly for the UI.
Reference : Tips & Tricks while working with Groovy & http://groovy.codehaus.org/. While working in groovy always be conscious about the imported classes and packages. Import only those which have been used in your file. For putting log messages use methods from "Debug" class just do this practice from the beginning itself. So create a file by name Person.groovy in this  this actions directory which will be fetching all the records from the entity "Person". At this moment this is really going to be the small code for doing this (a single line) like

...

Step - 4 : Now in webapp "practice" create one ftl file by name "person.ftl" which will be used to show the data fetched by groovy file.
               Reference : http://freemarker.sourceforge.net/docs/

...

Note: -Here remember to create an entry for the config directory in your ofbiz-component.xml file.

           which {color:#000000which will be : <classpath type="dir" location="config"/> means you have to place the config directory on the classpath to access configuration files.

Step - 2: Now create a file by name PracticeUiLabels.xml and create some of the ui labels for practice applicaton. (take reference from ExampleUiLabels.xml). Here remember one thing whenever you make a change in UiLabels then you have to restart the server for having the changes in effect. At first create only 2 ui labels like   

Code Block

<property key="PracticeApplication">

...


    <value xml:lang="en">This is first 	practice</value>

...


</property>

...


<property key="PracticeCompanyName">

...


    <value xml:lang="en">OFBiz: Practice</value>

...


</property>

Step - 3: Include this Ui Label resource in your main decorator screen which you created earlier and use these one or two ui labels which you are having now.

...

These requests are needed to add in your controller only when you have not included any of the other component controller which consist of these requests. So if you have already included common-controller.xml file then you don't need to explicitly do these entries in your controller.    
and the same view we have in place can be used for which we have entry in common-controller.xml file we can also have our own:

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

...

Code Block
<request-map uri="main">
        <security https="true" auth="true"/>
        <response name="success" type="view" value="main"/>
        <response name="error" type="view" value="main"/>
    </request-map>

Now run your application and observe the difference. you can login by user name : admin and pwd: ofbiz

...

Code Block
<service name="createExample" default-entity-name="Example" engine="entity-auto" invoke="create" auth="true">
        <description>Create a Example</description>
        <permission-service service-name="exampleGenericPermission" main-action="CREATE"/>
        <auto-attributes include="pk" mode="OUT" optional="false"/>
        <auto-attributes include="nonpk" mode="IN" optional="true"/>
        <override name="exampleTypeId" optional="false"/>
        <override name="statusId" optional="false"/>
        <override name="exampleName" optional="false"/>
    </service>

 engineengine="entity-auto" invoke="create" play the role for creating the records for the default-entity "Example."

...

Here important thing to note is in case of simple event controller entry will be like :

Code Block

<request-map uri="createPracticePersonSimpleEvent">

...


    <security https="true" auth="true"/>

...

{color}
    <event type="simple" path="org/hotwax/practice/PracticeEvents.xml" invoke="createPracticePersonSimpleEvent"/>

...


    <response name="success" type="view" value="CreatePracPersonSimpleEvent"/>

...


    <response name="error" type="view" value="CreatePracPersonSimpleEvent"/>

...


</request-map>

Here the path is the path of the file where the event is written. it will be practice/script/org/hotwax/practice.

...