Versions Compared

Key

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

...

Creating Practice Application (Hello World...)

Part

...

1

Note - 1 :- For any additional queries and concerns you can refer Example component. You will always find the code in example component to be the latest code of OFBiz. Take reference whenever you want to see some sample code for the development of this application, this will help you in future developments as well.
Every new feature is first added in the Example component for the references.
Note - 2 : Before starting the development of this application you must read the contents from:
OFBiz Contributors Best PracticesCoding Conventions and Best Practices Guide
Note - 3 : Don't copy any file from other component, as the revision number for the file is also copied. Always create a new file and, if required, then copy the contents of the file." Also be conscious about the unused code as well.
Note - 4 : For searching any of the document the best place is at : OFBiz Documentation Index.
Note - 5 : Right from the beginning, reading the console log must be a habit to make troubleshooting easy and understanding the system well.
Note - 6 : You can find the source code of this application attached with this document that you are going to develop but it is preferred to just take reference from it. It can be downloaded from here: Download Source (wink)

...

Output Screen :

Step - 11 : Create a file in the webapp directory "practice" named index.jsp (Contents of this file can be copied from the "example" component). This file is responsible for redirecting the response to control/main if you give a url such as  http://localhost:8080/practice/. If you give a url such as http://localhost:8080/practice/unknown/requestit will be redirected to the redirectPath specified in web.xml. In that case, ContextFilter will filter out the request and use the redirect path to redirect the request.

Part

...

2

Doing

...

Some Advancements To User Interface

Step - 1 : Now it is time to create a decorator for the screens in this application. Create a file named CommonScreens.xml in the "widget" directory. This file will contain the common screens which will be used throughout the entire application. A common screen may have a header and footer included so any other screens that use it as a decorator will also have those items. For this you can take reference from the CommonScreens.xml file in the "example" component.

...

Now run your application and observe the difference. you can login by user name : admin and pwd: ofbizHere 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:
Confirm that user 'admin' has the 'OFBTOOLS' permission.
Step : 1 - Login into partymanager to confirm that the user admin has the required permission https://127.0.0.1:8443/partymgr/control/main
Step : 2 - Once your logged in search for the user by typing 'admin' in the User Login field and then clicking the Lookup Party button.
Step : 3 -   This does a wild char*  search and you should see multiple users returned.Click the 'Details' button for the admin user.
Note : Important point to note here is that the person 'Mr. THE PRIVILEGED ADMINISTRATOR' has a partyid admin has multiple logins as listed in the
User Name(s) form.
Step : 4 - We interested in the admin user login so click on the 'Security Groups' button and confirm that the use 'admin' is part of the 'FULLADMIN' group. The Groups that the user belongs to is shown in the bottom list form Drill down on the FULLADMIN.
Step : 5 - Click on the Permissions tab. This tab shows all the permissions for the FULLADMIN security group. Navigate between the permissions till you find the OFBTOOLS permissions.
'OFBTOOLS_VIEW Permission to access the Stock OFBiz Manager Applications.' This confirms that the userlogin 'admin' has the permission 'OFBTOOLS'
Step : 6 - Take a moment  to review the entity model as it relates to users and permissions. The arrow represents the many side of the relationship.An really important reading at this moment is at : OFBiz Security

Part

...

3

Writing CRUD

...

Operations

Create, Update and Delete operations for an entity will be done by services which we will be writing in minilang.
At first approach we will write our own services for performing these operations for making a better understanding with it.
Onwards we will be doing this by calling already implemented services.
For doing so we will take the entities from Party model which are:
--Party
--Person
A person is a party so for the creation of a person first a party needs to be created with partyTypeId="PERSON".
So there can be two ways to do that:
1. Create service for the creation of a party with type Person.
2. Create a party first in the service which will be creating person.

...

Here the path is the classpath in which this event is defined. 
The file name will be PracticeEvents.java and will be created at  practice/src/org/hotwax/practice.

Simple

...

Minilang Event

Step - 6 : Now in the script/org/hotwax/practice/ create one file by name PracticeEvents.xml.
Step - 7 : Write the event in PracticeEvents.xml file by name createPracticePersonSimpleEvent.(For reference you can go through the event "createUser" from UserEvents.xml from party component)
The event which you will be writing should be the simple one as you just have to process 5 fields coming from the form which are salutation, firstName, middleName, lastName, suffix. and then you have to call the createPracticePerson service.
For processing the field you will be using simple map processor as you have read earlier. 
Follow these steps for writing the event:
7.a : Process fields coming from the form like: 

...

7.b : Create some Ui labels for showing them in fail-property like PracticeFirstNameMissingError.
7.c : Now call service createPracticePerson service by passing out map which is obtained after processing fields as a in map to the service.
OutPut Screen :

...

Java Event

...

Here the java event which you will be writing will be fairly simple. For reference you can check any of the *Events.java file.
Step - 1 : The contents will be :

...

So create a file by name build.xml and then compile it. It will create a build directory in your component directory which will be containing all *.jar and class files after compilation. For the content of build.xml file you can refere example component. 
For running the simple event don't forget to make an entry for <classpath type="dir" location="script"/> in ofbiz-component.xml file.
For running the java event make an entry <classpath type="jar" location="build/lib/*"/> in ofbiz-component.xml file.

Part 4

ECA(Event Condition Action)

...

Here we are implementing an interface and overriding the behaviour of the attribute "suffix", which will have effect when this service will be in action.
Implementation of service createPracticePersonInterfaceService will be the same as createPracticePerson.
Don't forget to restart the server after this implementation.

Part

...

5

Creating

...

Custom Entity

 For the creation of new entity you can again take a referecne from example component for this you can have a look in entitymodel.xml file of example component. You can create new entities by following these steps:
Step - 1 : Create a new subdirectory by name entitydef in hot-deploy/practice/.
Step - 2 : Create new file by name  entitymodel.xml. This file will contain the defintions of entities which you want to define.
Step - 3 : For loading the defintion you need to do an entry in your ofbiz-component.xml file like:

...

That implies that when ever you do a change you need to restart the server to have those changes in effect.
At this place an important reading is at http://docs.ofbiz.org/display/OFBTECH/General+Entity+Overview.
You will rarely find this way to define new entity because you are already having entities there in OFBiz already defined which will be useful for the conduction of your business process. Though you may feel at some place to add more fields to an existing entity so how can you do that? The next  step will show you the way how you can extend an entity for your customized needs.
Earlier we used to have one more file in same directory by name entitygroup.xml which not needed any more because code is checked in to the trunk for this.

Extending an

...

Existing OOTB Entity

Yes you can extend an existing entity for adding more fields to for your custom needs. This can be done in following way:
Step - 1 :  For extending an entity you can do in this manner in the entitydef/entitymodel.xml file of your custom application.

...

After doing this entry when you will run the command ant run-install to load demo data then the data from this file will be loaded as demo data and once you start the server you can see this record added for person by going to Person Form in practice application or you can prefer to go to https://localhost:8443/webtools/control/entitymaint and find each entity and check the records have gone in the database or not.

Part

...

6

Info
titleImportant!

This part of the tutorial doesn't work with the latest version of Ofbiz. You can find informations about Ajax Request with this version in the Example component (tab Ajax Examples).

...