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

ofbiz-component.xml explained:

1. The ofbiz-component.xml file is responsible for letting OFBiz know where resources are at as well as allowing you to add to the classpath.

2. Here 'resource-loader name' can be any string here it is "main". The 'type' tells OFBiz that we will be loading a component.

3. In <webapp> tag, we have different attributes and their purpose is as follows:

    a) name :- defines the name of our web application.
    b) title :- This will be the title of our component component
    c) server :- This will let OFBiz know what server to use use
    d) base-permission :- This line requires that the user should have the OFBTOOLS permission to be able to use the application. Since the 'admin' user has this permission we do not have to create any new users. 
    e) location :- This will be the location that is the default base directory for the server server
    f) mount-point :- This is the URL used to access this resource. in this case it would be localhost:8080/practice practice
    g) app-bar-display :- This will let OFBiz know if we want our component to show up in the main application tabs that are part of the common ofbiz decorator.  
 

Creating the web app:

Step - 1 : Create a "webapp" directory in the practice component (hot-deploy/practice/webapp).
This directory contains all the webapp related files for the component we are creating.

...

Step - 5  Create a file named "controller.xml" (used by ofbiz webapp controller)  This file will be small and simple at first but will grow as we add functionality later on. For now insert the following code:<

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>     

...

  <!-- 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://practice/widget/PracticeScreens.xml#main"/

...

   

...

  <!-- end of view mappings -->

...



</site-conf>

Step - 6 : Move up one level and create a new directory named 'error'(hot-deploy/practice/webapp/practice/error).

...

"localhost:8080/practice/control/main"

1-. When OFBiz sees this request it will look at the /practice section first. Because in our ofbiz-component.xml file we said our webapps mount point would be /practice. Now OFBiz knows that our practice component will handle the rest of the request.

2-. OFBiz will then look at our controller.xml file. Inside our controller.xml file we have request-maps and view-maps. If it finds a view-map with the name 'main' it will go there. The request-map can either specify a view, or as we will see later an event or a service. If it specifies a view it will look further down in the controller.xml file and see if there is a view-map with the name specified by the value tag in the request-map.

3-. For now we will keep it simple and assume that all the views go to a type=screen. If this is the case then the page tag will specify a path to a screen definition file as well as a screen name to display after the "#" sign.

*Step - 10 :* Now its the time to run you first practice application :
                Start server by : java -Xmx256M -jar ofbiz.jar (the -Xmx256M command just ensures that the program has enough memory)
                Then hit the url http://localhost:8080/practice/control/main in your browser.
                Browser should show "This is first practice"

...

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, but because of deprecation of bsh files we are using this groovy 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 So create a file by name Person.groovy in 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

Code Block

context.persons = delegator.findList(entityName, null, null, null, null, false);

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/

...

Step - 6 : Now do the needful for rendering this screen in controller.xml file as we did earlier.

Now again run the application and see the results.

Now moving to create a form for showing the content of Person entity on the screen:(Using Form Widget)

...

Step - 2 :  Now you have to create a file by name "eecas.xml" in "entitydef" directory, which will be in your component directory "practice". Eeca definition will come here. (Take reference from eecas.xml of "accounting" component). This will be :

    <!-- To create party role whenever a party is created - ->
    <eca entity="Party" operation="create" event="return">
        <condition field-name="partyId" operator="is-not-empty"/>
        <action service="createPartyRoleCustomer" mode="sync"/>
    </eca>

...

 Create a group service by name "partyGroup" like :

<!- - Group service - ->
    <service name="partyGroup" engine="group" auth="true">
        <description>Creates a party, person and party role Client</description>
        <group>
            <invoke name="createPracticePerson" result-to-context="true"/>
            <invoke name="createPartyRoleClient"/>
        </group>
    </service>

...