Versions Compared

Key

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

...

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>

...

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
     c) server :- This will let OFBiz know what server to 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
    f) mount-point :- This is the URL used to access this resource. in this case it would be localhost:8080/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 - 3 : Create WEB-INF directory in your webapp (hot-deploy/practice/webapp/practice/WEB-INF).
An OFBiz web application requires two configuration files, a controller.xml and a web.xml. The controller.xml tells OFBiz what to do with various requests from visitors: what actions to take and what  pages to render. web.xml tells OFBiz what resources (database and business logic access) are available for this web application and how to handle web-related issues, such as welcome pages, redirects, and error pages.

Step - 4 Create a file named "web.xml"(web.xml follows j2ee webapp specs). Contents of this file can be taken from any of the existing component e.g. example component. The Important values to change are the <display-name>, the localDispatcherName, and the mainDecoratorLocation.
For now put the value: "component://practice/widget/PracticeScreens.xml" in for the location and you will see why in a while.

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:

...

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

Step - 6.a :  Create a file error.jsp inside the "error" directory. Contents of this file can be taken from any of the existing component  component e.g. example component.
 The The location of your error page will be specified in the beginning of your controller.xml file like <errorpage>/error/error.jsp</errorpage> . You will need to make or copy over a /webapp/practice/error/error.jsp page to show an error message to the user.

...

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"

...

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

...

"Person", null, null, null, null, false);

The above statement will fetch all the records from the Person entity and will put them in context by the name persons. Now this list by the name person will be iterated in the ftl file to show the records.

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/
At this moment you need only to iterate the list of persons which is there in the context. The only code that is needed to that is:

Code Block

<#if persons?has_content>
  <h2>Some of the people who visited our site are:</h2>
  <br>
  <ul>
    <#list persons as person>
      <li>${person.firstName?if_exists} ${person.lastName?if_exists}<li>
    </#list>
  </ul>
</#if>

Step - 5 : Now create a new screen by name "person" in PracticeScreens.xml file and also create a new menu item in PracticeMenus.xml file.

...

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

Step - 1 :  Now add one more menu item to by name "PersonForm" to your PracticeMenus.xml file.

Step - 2: Create one file in widget by name PracticeForms.xml and create a list form for showing the records from person entity.
(Take reference from ExampleScreens.xml and ExampleForms.xml files).

Step - 3 :  Create new screen by name personForm and include this list form in it.

...

Now its the time to show practice application in the app bar :

Step - 1 :  For this just make app-bar-display="true" in ofbiz-component.xml file.

             Restart the server then run it again you will find practice application in app bar.

Create UI Labels:

Step - 1 :  For this create directory by name "config" in your component directory i.e. "practice".

...

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.

Step - 4 : Use those 2 ui UI labels at appropriate places.

...

Step - 1 :  Take reference from ExampleMenus.xml file for having login and logout options in your menu.                  
             Targets for these options will be available from "component://common/webcommon/WEB-INF/common-controller.xml", which we have to include in our controller.xml.
             or you can do these entries in your controller.xml file under

...

Step - 2 :  Make changes in requests in controller.xml file make auth="true" means now these requests needs authentication.
             This is first security level which you have implemented. you request should look like :

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

Here we should understand why we had given the permission "OFBTOOLS" in base-permission in ofbiz-component.xml file. To understand this please read following carefully and perform steps as mentioned:

...

Step - 3 : Create directory structure and PracticeServices.xml file in your component directory for giving the implementation of these services.
             (For implementation take reference from service.xml and ExampleServices.xml files of Example component)

...

Code Block
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

...