Versions Compared

Key

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

...

Creating

...

Practice

...

Application

 This document is meant for OFBiz  beginners. It will help to come up with the most basic knowledge of OFBiz application development process. Aim behind the creation of this tutorial is to acquaint a developer with best practices, coding conventions and the control flow.

Note - 1 :- For any additional query and concern you can consult to Example component. You will always find the code in example component to be the most latest code of Ofbiz. Take reference whenever you want to see some sample code for the development of this application.
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 form :
            http://docs.ofbiz.org/display/OFBADMIN/OFBiz+Contributors+Best+Practiceshttp://docs.ofbiz.org/display/OFBADMIN/Coding+Conventions

...

and

...

http://docs.ofbiz.org/display/OFBADMIN/Best+Practices+Guide

...

Note - 3 : Dont copy any file from other component, as the revision number for the file is also copied. Always create 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 : http://docs.ofbiz.org/display/OFBADMIN/OFBiz+Documentation+Index

...

.   

Create first basic application by name "practice" :

Step - 1 : Create the sub - directory in hot-deploy/ and name it "practice"(hot-deploy/practice).

...

The

...

directory

...

name

...

should

...

match

...

the

...

new

...

components

...

name

...

that

...

we

...

are

...

creating.

...

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

...

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

    c) server :- This will let ofbiz know what server to use 

    d) location :- This will be the location that is the default base directory for the server 

    e) mount-point :- This is the URL used to access this resource. in this case it would be localhost:8080/practice 

    f) 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 on the back end:

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

...

-

...

2

...

:

...

Create

...

a

...

sub-directory

...

inside

...

the

...

webapp

...

directory

...

by

...

the

...

name of  "practice"

...

which

...

is

...

the

...

name

...

of

...

the

...

webapp

...

which

...

you

...

are

...

going

...

to

...

develop

...

(hot-deploy/practice/webapp/practice).

...

A

...

component

...

can

...

have

...

multiple

...

webapp's

...

attached

...

to

...

it.

...

e.g.

...

In

...

the

...

"marketing"

...

component

...

there

...

are

...

two

...

webapps

...

"marketing"

...

and

...

"sfa"

...

.

...


The

...

webapp

...

we

...

are

...

creating

...

will

...

follow

...

the

...

J2EE

...

webapp

...

standards.

...

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:

...

<?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).

...

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  e.g.

...

example

...

component.

...


 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

...

-

...

7

...

:

...

Create

...

a

...

sub-directory

...

inside

...

your

...

component

...

directory

...

"practice"

...

named

...

"widget"(hot-deploy/practice/widget)

...

.
              This directory will contain your forms and screens which will be created for UI.

Step - 8 : Create a file inside the directory "widget" named "PracticeScreens.xml".

...


 Contents of this file can be taken from any of the existing component  e.g.

...

example

...

component.

...

Very

...

first

...

screen

...

will

...

be

...

like

...

:

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

...


        <section>
            <widgets>                           
                   <label text="This is first practice"/>                            
            </widgets>
        </section>
    </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:

"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 - 11 : Now create a file in webapp directory "practice" by name index.jsp (Contents of this file can be taken from "example" component), this file is responsible for redirecting the response to control/main if you give url  http://localhost:8080/practice/

...

and

...

if

...

you

...

give

...

url

...

like

...

http://localhost:8080/practice/unknown/request

...

it

...

will

...

be

...

redirected

...

to

...

the

...

redirectPath

...

specified

...

in

...

web.xml.

...

In

...

that

...

case,

...

ContextFilter

...

filter

...

out

...

the

...

request

...

and

...

use

...

this

...

redirect

...

path

...

to

...

redirect

...

the

...

request.

...

Doing some advancements :

Step - 1 : Now its the time to create a decorator for the screens in this application so for that create a file by name CommonScreens.xml file in "widget" directory. This file will be containing the common screens which will be used through out the whole application. E.g. A common screen may have header and footer included in it so which ever is the screen will be using it as a decorator will be having those in common. For this you can take reference from CommonScreens.xml file of "example" component.
An important reading at this moment is at http://docs.ofbiz.org/display/OFBIZ/Understanding+the+OFBiz+Widget+Toolkit

...

another

...

is

...

http://docs.ofbiz.org/display/OFBIZ/FAQ+-+Tips+-+Tricks+-+Cookbook+-+HowTo

...

  in

...

this

...

you

...

can

...

read

...

the

...

contents

...

under heading  "The

...

Decorator".

...

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 bsh files.
Reference : http://www.beanshell.org/docs.html

...

.

...

While

...

working

...

in

...

bsh

...

always

...

be

...

conscious

...

about

...

the

...

imported

...

classess

...

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

...

begining

...

itself.

...


so

...

create

...

a

...

file

...

by

...

name

...

person.bsh

...

in this  actions directory which will be fetching all the records from the entity "Person".

...

Now

...

a

...

new

...

scripting

...

language

...

has

...

been

...

introduced

...

in

...

place

...

of

...

bsh

...

script

...

the

...

name

...

is

...

"groovy".

...

For

...

more

...

info

...

you

...

can

...

visit

...

:

...

http://groovy.codehaus.org/

...

 

Step - 4 : Now in webapp "practice"

...

create

...

one

...

ftl

...

file

...

by

...

name "person.ftl" which will be used to show the data fetched by bsh file.
               Reference : http://freemarker.sourceforge.net/docs/

...

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.

...

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

Step - 4 : Do the needful for showing this screen in controller.xml.

Now run the application again and observe the difference.

Till Now you have worked on controller requests mappings, Screen widget, form widget, Decorator, Menus, bsh, ftl.

Create main Decorator for decorating this application:

Step - 1 : Create screen by name "main-decorator" in CommonScreens.xml file.(Take reference from CommonScreens.xml file of Example component.)

Step - 2 : Now include this decorator in CommonPracticeDecorator screen which you are already having.

Now run it again and see the difference.

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

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

           which 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

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

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

Note : Always search first for any existing Ui label in ofbiz and if you don't find it there then only create new one.

Now its time to make this practice application secure by checking authentication (user login):

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.

...

 

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.

Now run your application and observe the difference.

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.

For writing services following steps must be performed:

Step - 1: Create directory by name "servicedef" in component directory "practice". This directory will contain all the service definition files e.g. services.xml, secas.xml.

Note If it is a service which is written in Java then it will be placed in "src" directory and if it is a service which is written in minilang then it will be placed in script directory. e.g. for java applications/party/src/org/ofbiz/party/party/PartyServices.java

...

and

...

for

...

minilang

...

applications/party/script/org/ofbiz/party/party/PartyInvitationServices.xml.

...

Respective

...

class

...

path

...

and

...

file

...

path

...

will

...

be

...

mentioned

...

in

...

the

...

service

...

definition.

...

Step - 2 :  In controller you have to create an entry for the request for the execution of a service and set the response.

Step - 3: Now all the services which you have written needs to be loaded when server starts so you need to do an entry for service definition in ofbiz-component.xml file which will be like :

             <service-resource type="model" loader="main" location="servicedef/services.xml"/>

...

So whenever you make any change in any service definition then you must restart the server to have changes in effect.

Writing CRUD operations for Party entity:

First we will be writing services for Party then while writing services for creating Person we will be calling the service for party.

Step - 1 :  Create a file by name "services.xml" in servicedef directory.

Step - 2 : Define services for CRUD operations for Party entity. Name of services will be createPracticeParty, updatePracticeParty, deletePracticeParty and specify the correct location to the file where these services will be implemented like /framework/example/script/org/ofbiz/example/example/ExampleServices.xml.

...

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)

Note : Do not use the <override> tag as it is introduced later in the tutorial. 

From this place if you want to run these services then you can run them by webtools--> Run Service . By this place you can test your services.

Writing CRUD operations for Person entity:

-- Here for the creation of record for person entity we will need to have the partyId for that so we will first call the service createPracticeParty then after getting the partyId we will create the record for person.

-- Here we will be adding one add form in the bottom of the list form which we have for the person entity. This form will be calling the services for creating a record for person.

Step - 1 : Create the add form for the creation of person and add this in the same screen for person form.

Step - 2 :  Write CRUD operations for person entity.

Step - 3: Now convert the List form with editable field(Ref. ListExampleItems from ExampleForms.xml) and add Update and delete option with it and also in the same screen there is add form also.

Step - 4 :  Create controller entries for these services which are going to be called by this form.

Writing Events:

Events can be written in Java and minilang both. Now the next development which you are going to do will be writting these events.

Events are used for the validation and conversion using Simple Map Processor. The Simple Map Processor Mini-Language performs two primary tasks: validation and conversion. It does this in a context of moving values from one Map to another. The input map will commonly contain Strings, but can contain other object types like Integer, Long, Float, Double, java.sql.Date, Time, and Timestamp.

Before moving any further an important link to go through is : http://docs.ofbiz.org/display/OFBIZ/Mini-Language+Guide#Mini-LanguageGuide-smap

...

For

...

making

...

an

...

understanding

...

with

...

it

...

implementation

...

will

...

be

...

done

...

by

...

performing

...

following

...

steps:

...

Step

...

-

...

1

...

:

...

For

...

this

...

create

...

another

...

tab

...

in

...

your

...

practice

...

application

...

menu

...

bar

...

for

...

this

...

by

...

Name

...

"Events".

...

Step

...

-

...

2

...

:

...

Now

...

create

...

another

...

menu

...

with

...

two

...

menu

...

item

...

in

...

PracticeMenus.xml

...

file

...

by

...

name

...

"EventMenu".

...

This

...

menu

...

will

...

be

...

having

...

2

...

menu

...

Item

...

one

...

will

...

be

...

by

...

name

...

"EventMinilang"

...

and  another by name "EventJava".

...

One

...

will

...

be

...

used

...

to

...

show

...

the

...

form

...

which

...

we

...

will

...

be

...

calling

...

an

...

event

...

which

...

will

...

be

...

in

...

minilang

...

and

...

other

...

will

...

be

...

used

...

to

...

call

...

java

...

event.

...

Step

...

-

...

3

...

:

...

Simply

...

show

...

form

...

on

...

the

...

request

...

of

...

both

...

which

...

will

...

be

...

for

...

creating

...

a

...

new

...

person.

...

Both

...

the

...

forms

...

will

...

be

...

different

...

for

...

calling

...

different

...

events

...

as

...

target

...

in

...

them.

...

Step

...

-

...

4

...

:

...

Show

...

labels

...

in

...

screens

...

above

...

the

...

form

...

like

...

"New

...

Person

...

--

...

Simple

...

Event"

...

  and  "New

...

Person

...

-

...

-

...

Java

...

Event"

...

so

...

that

...

it

...

will

...

be

...

easy

...

to

...

identify

...

the

...

purpose

...

of

...

that

...

form.

...

Step

...

-

...

5

...

:

...

Now

...

set

...

event

...

in

...

target

...

of

...

the

...

forms

...

and

...

create

...

request

...

mappings

...

in

...

controller

...

for

...

the

...

event.

...

Here

...

important

...

thing

...

to

...

note

...

is

...

in

...

case

...

of

...

simple

...

event

...

controller

...

entry

...

will

...

be

...

like

...

:

<request-map

...

uri="createPracticePersonSimpleEvent">

...


        <security https="true" auth="true"/>
        <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.

...

 and for java event controller entry will be like:

<request-map

...

uri="createPracticePersonJavaEvent">

...


        <security https="true" auth="true"/>
        <event type="java"

...

path="org.hotwax.practice.PracticeEvents"

...

invoke="createPracticePersonJavaEvent"/>

...


        <response name="success"

...

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

...

type="view"

...

value="

...

CreatePracPersonJavaEvent

...

"/>

...


</request-map>

...

Here

...

the

...

path

...

is

...

the

...

classpath

...

in

...

which

...

this

...

event

...

is

...

defined.

...

 

The file name will be PracticeEvents.java

...

and

...

will

...

be

...

creted at  practice/src/org/hotwax/practice.

...

Simple 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

...

writting

...

should

...

be

...

the

...

simple

...

one

...

as

...

you

...

just

...

have

...

to

...

process

...

5

...

fields

...

comming

...

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 writting the event:

7.a

...

:

...

Process

...

fields

...

coming

...

from

...

the

...

form

...

like: 

     <call-map-processor

...

in-map-name="parameters"

...

out-map-name="createPersonContext">

...


         <simple-map-processor name="createPersonMap">
             <process field="firstName">
                 <copy/>
                 <not-empty>
                     <fail-property property="PracticeFirstNameMissingError" resource="PracticeUiLabels"/>
                 </not-empty>   
             </process>
         </simple-map-processor>
     </call-map-processor>
     <check-errors/>

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.

Java Event: 

Here the java event which you will be writting will be fairly simple. For reference you can check any of the *Events.java file.

Step - 1 : The contents can be :

Code Block

public static String createPracticePersonJavaEvent(HttpServletRequest request, HttpServletResponse response){              LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");                          GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
}

Step - 2 : Now you have to process the fields comming from the form like :
            

Code Block

&nbsp;&nbsp;&nbsp;>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <copy/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <not-empty>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <fail-property property="PracticeFirstNameMissingError" resource="PracticeUiLabels"/>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </not-empty>&nbsp; String salutation = (String) request.getParameter("salutation");
&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </process>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String firstName = (String) request.getParameter("firstName");
&nbsp;&nbsp;&nbsp; </simple-map-processor>
&nbsp;&nbsp;&nbsp;&nbsp; </call-map-processor>
nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <check-errors/>

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

h5. Java Event:&nbsp;

Here the java event which you will be writting will be fairly simple. For reference you can check any of the \*Events.java file.

*Step - 1 :* The contents can be :

{code}
public static String createPracticePersonJavaEvent(HttpServletRequest request, HttpServletResponse response)
{            LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");            GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
 
}
{code} 
Step - 2:  Now you have to process the fields comming from the form like :             String salutation = (String) request.getParameter("salutation");            String firstName = (String) request.getParameter("firstName");
Step - 3Now prepare a map for the values which you have to pass to the service which you will call "createPracticePerson" . Like :  Map createPersonCtx = UtilMisc.toMap("salutation", salutation, "firstName", firstName);  *Step - 4 :* Then at the end just call the service "createPracticePerson" like :  try {     Map person = dispatcher.runSync("createPracticePerson", createPersonCtx); }\\ \\
\\

catch (GenericServiceException e)

{     Debug.logError(e.toString(), module);     return "error"; }\\ \\
return "success";
\\
\\

After writting event in Java don't forget to compile it by running "ant" command. At this moment you will need to add build.xml file to your component directory i.e. at hot-deploy/practice/ For the content of build.xml file you can refer "example" component.
Here in build.xml file ensure one thing you are having follwing entry:

<target name="classpath">
&nbsp;&nbsp;&nbsp; <path id="local.class.path">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <fileset 

Step - 3 : Now prepare a map for the values which you have to pass to the service which you will call "createPracticePerson" . Like :
            

Code Block

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Map createPersonCtx = UtilMisc.toMap("salutation", salutation, "firstName", firstName);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

 

Step - 4 : Then at the end just call the service "createPracticePerson" like :
             

Code Block

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Map person = dispatcher.runSync("createPracticePerson", createPersonCtx);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }catch (GenericServiceException e){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debug.logError(e.toString(), module);     return "error";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "success";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 



After writting event in Java don't forget to compile it by running "ant" command. At this moment you will need to add build.xml file to your component directory i.e. at hot-deploy/practice/ For the content of build.xml file you can refer "example" component.
Here in build.xml file ensure one thing you are having follwing entry:

<target name="classpath">
    <path id="local.class.path">
        <fileset dir="../../framework/base/lib/j2eespecs"

...

includes="*.jar"/>

...


    </path>

...


</target>

...

This

...

will

...

needed

...

for

...

the

...

classes

...

like

...

import

...

javax.servlet.http.HttpServletRequest;

...


import

...

javax.servlet.http.HttpServletResponse;

...

  

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.

...

ECA(Event

...

Condition

...

Action):

...

 

ECA : Its a combinition of 3 things an event, conditions per event and Actions per event. It is a rule. Which is used to trigger an action on the execution of an event when certain conditions are met. 

This is much like a trigger. When a service is called, a lookup is performed to see if any ECAs are defined for this event. Events include before authentication, before IN parameter validation, before actual service invocation, before OUT parameter validation, before transaction commit, or before the service returns. Next each condition in the ECA definition is evaluated and if all come back as true, each action is performed. An action is just a service which must be defined to work with the parameters already in the service's context. There are no limit to the number of conditions or actions each ECA may define.

For mor details on this visit :  http://docs.ofbiz.org/display/OFBTECH/Service+Engine+Guide

...

1.

...

SECA

...

(Service

...

Event

...

Condition

...

Action)

...

:

...

This

...

is

...

used

...

when

...

we

...

want

...

to

...

trigger

...

another

...

service(action)

...

on

...

the

...

execution

...

of

...

a

...

service

...

when

...

certain

...

conditions

...

are

...

met.

...

2.

...

EECA

...

(Entity

...

Event

...

Condition

...

Action)

...

:

...

This

...

used

...

when

...

we

...

want

...

to

...

trigger

...

a

...

service

...

on

...

the

...

creation

...

of

...

a

...

record

...

for

...

an

...

entity

...

when

...

certain

...

conditions

...

are

...

met.

...

For

...

the

...

implementation

...

of

...

ECA

...

again

...

we

...

will

...

be

...

following

...

the

...

same

...

approach

...

for

...

screens,

...

menus

...

by

...

following

...

steps:

...

Step

...

-

...

1

...

:

...

Add

...

one

...

more

...

application

...

menu

...

in

...

practice

...

application's

...

menu

...

bar

...

by

...

name

...

"ECA".(Do

...

the

...

needful

...

entries

...

for

...

target

...

in

...

controller.xml)

...

Step

...

-

...

2

...

:

...

Now

...

create

...

another

...

menu

...

with

...

two

...

menu

...

item

...

in

...

PracticeMenus.xml

...

file

...

by

...

name

...

"EcaMenu".

...

This

...

menu

...

will

...

be

...

having

...

2

...

menu

...

Item

...

one

...

will

...

be

...

by

...

name

...

"seca"

...

and

...

"eeca".

...

For

...

both

...

of

...

them

...

2

...

screens

...

will

...

be

...

needed

...

which

...

will

...

be

...

using

...

the

...

form

...

"CreatePerson"

...

which

...

we

...

are

...

already

...

having.

...

(in

...

personForm

...

screen)

...

SECA

...

:

...

Step

...

-

...

1

...

:

...

For

...

this

...

you

...

have

...

to

...

write

...

another

...

service

...

by

...

name

...

"createPartyRoleVisitor",

...

  which

...

will

...

be

...

setting

...

the

...

role

...

for

...

the

...

party

...

which

...

will

...

be

...

created

...

by

...

"createPracticePerson"

...

service.

...


The

...

service

...

"createPartyRoleVisitor"

...

will

...

be

...

triggered

...

by

...

the

...

seca

...

rule

...

which

...

you

...

will

...

define

...

for

...

service

...

"createPracticePerson".

...


In

...

the

...

new

...

service

...

involved

...

entity

...

will

...

by

...

"PartyRole".

...

In

...

"createPartyRoleVisitor"

...

just

...

call

...

service

...

"createPartyRole"

...

which

...

is

...

already

...

implemented.

...

Step

...

-

...

2

...

:

...

  Now

...

you

...

have

...

to

...

create

...

a

...

file

...

by

...

name

...

"secas.xml"

...

in

...

"servicedef"

...

directory.

...

Seca

...

definition

...

will

...

come

...

here.

...

(Take

...

reference

...

from

...

secas.xml

...

of

...

"party"

...

component).

...

This

...

will

...

be

...

<eca

...

service="createPracticePerson"

...

event="commit">

...


    <condition field-name="partyId"

...

operator="is-not-empty"/>

...


    <action service="createPartyRoleVisitor"

...

mode="sync"/>

...


</eca>

...

Step

...

-

...

3

...

:

...

Do

...

an

...

entry

...

in

...

ofbiz-component.xml

...

file

...

for

...

this

...

seca

...

definition

...

to

...

to

...

be

...

loaded.

...

It

...

will

...

be

...

:

...

<service-resource

...

type="eca"

...

loader="main"

...

location="servicedef/secas.xml"/>

...

Don't

...

forget

...

to

...

restart

...

the

...

server

...

after

...

doing

...

this

...

entry.

...

Now

...

run

...

the

...

service

...

through

...

form

...

and

...

check

...

the

...

records

...

in

...

PartyRole

...

entity.

...

You

...

will

...

find

...

a

...

role

...

is

...

set

...

for

...

the

...

party

...

created

...

because

...

synchrounously

...

you

...

have

...

triggered

...

another

...

service

...

by

...

seca

...

rule

...

for

...

setting

...

up

...

the

...

role

...

for

...

the

...

party

...

created.

...

EECA

...

:

...

Step

...

-

...

1

...

:

...

For

...

this

...

you

...

have

...

to

...

write

...

another

...

service

...

by

...

name

...

"createPartyRoleCustomer",

...

  which

...

will

...

be

...

setting

...

the

...

role

...

for

...

the

...

party

...

which

...

will

...

be

...

created

...

means

...

when

...

a

...

record

...

for

...

the

...

entity

...

"Party"

...

will

...

be

...

created

...

this

...

service

...

will

...

be

...

triggered

...

for

...

setting

...

a

...

role

...

customer

...

for

...

that

...

party.

...

The

...

service

...

"createPartyRoleCustomer"

...

will

...

be

...

similar

...

to

...

"createPartyRoleVisitor".

...

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>

...

Step

...

-

...

3

...

:

...

Do

...

an

...

entry

...

in

...

ofbiz-component.xml

...

file

...

for

...

this

...

seca

...

definition

...

to

...

to

...

be

...

loaded.

...

It

...

will

...

be

...

:

...

<entity-resource

...

type="eca"

...

reader-name="main"

...

loader="main"

...

location="entitydef/eecas.xml"/>

...

 Don't

...

forget

...

to

...

restart

...

the

...

server

...

after

...

doing

...

this

...

entry.

...

Now

...

run

...

the

...

service

...

through

...

form

...

and

...

check

...

the

...

records

...

in

...

PartyRole

...

entity.

...

You

...

will

...

find

...

a

...

role

...

is

...

set

...

for

...

the

...

party

...

created

...

because

...

synchrounously

...

you

...

have

...

triggered

...

a

...

service

...

by

...

eeca

...

rule

...

for

...

setting

...

up

...

the

...

role

...

for

...

the

...

party

...

created.

...

The

...

main

...

difference

...

here

...

is

...

that

...

you

...

are

...

triggering

...

a

...

service

...

when

...

an

...

operation

...

performed

...

on

...

the

...

entity.

...

In

...

our

...

case

...

it

...

is

...

"create".

...

Note Here you have created a saparate menu to understand the concept separately. As you written seca for the service "createPracticePerson",

...

so

...

where

...

ever

...

in

...

your

...

practice

...

application

...

you

...

will

...

be

...

calling

...

this

...

service

...

that

...

seca

...

will

...

trigger

...

"createPartyRoleVisitor"

...

and

...

on

...

the

...

other

...

hand

...

when

...

a

...

party

...

will

...

be

...

created

...

"createPartyRoleCustomer"

...

will

...

be

...

triggered.

...

 Group Service:

    Group services are used to call more then one services as a group. Service groups are a set of services which should run when calling the initial service. You define a service using the group service engine, and include all the parameters/attributes needed for all the services in the group. The location attribute is not needed for groupservices, the invoke attribute defines the name of the group to run. When this service is invoked the group is called and the services defined in the group are called as defined.

For mor details on this visit :  http://docs.ofbiz.org/display/OFBTECH/Service+Engine+Guide

...

For

...

the

...

implementation

...

of

...

Group

...

service

...

follow

...

these

...

steps:

...

 

Step - 1 :  Add another menu item to applicatoin menu bar by name "Group Service".(Do

...

the

...

needful

...

entries

...

for

...

target

...

in

...

controller.xml)

...

Step

...

-

...

2

...

:

...

Now

...

create

...

new

...

screen

...

and

...

a

...

form

...

for

...

creation

...

of

...

the

...

person

...

because

...

the

...

target

...

for

...

the

...

form

...

will

...

be

...

the

...

group

...

service

...

which

...

we

...

will

...

be

...

defining.

...

Note : Now the time is to define the group service. We will be defining the group service for the services which we have implemented for this practice application.

Step - 4 : You will be defining the service group in services.xml file.(Take reference from services.xml of party component).

Just write one more service which will be setting the role "CLIENT" for the party which will be created by createPracticePerson Service. 

 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>

Don't forget to restart the server before testing it. 

Interface:

The interface service engine has been implemented to help with defining services which share a number of the same parameters. An interface service cannot be invoked, but rather is a defined service which other services inherit from. Each interface service will be defined using the interface engine.

For more details on this visit :  http://docs.ofbiz.org/display/OFBTECH/Service+Engine+Guide

...

For

...

implemeting

...

the

...

interface

...

follow

...

these

...

steps:

...

Step

...

-

...

1

...

:

...

Add

...

another

...

menu

...

item

...

to

...

applicatoin

...

menu

...

bar

...

by

...

name

...

"Interface".(Do

...

the

...

needful

...

entries

...

for

...

target

...

in

...

controller.xml)

...

Step

...

-

...

2

...

:

...

Create

...

new

...

screen,

...

form

...

and

...

service

...

for

...

creating

...

a

...

person.

...

Here

...

service

...

will

...

implement

...

the

...

interface.

...

(For

...

creating

...

interface

...

take

...

reference

...

from

...

services_fixedasset.xml

...

of

...

accounting

...

component)

...

it

...

will

...

be

...

like

...

:

...

<

...

!-

...

-

...

Peson

...

Interface

...

-->

...


    <service name="createPersonInterface"

...

engine="interface"

...

location

...

="" invoke="">
        <attribute name="firstName"

...

mode="IN"

...

type="String"

...

optional="false"/>

...


        <attribute name="middleName"

...

mode="IN"

...

type="String"

...

optional="true"/>

...


        <attribute name="lastName"

...

mode="IN"

...

type="String"

...

optional="false"/>

...


        <attribute name="suffix"

...

mode="IN"

...

type="String"

...

optional="true"

...

/>
    </service>
   
    <service name="createPracticePersonInterfaceService"

...

engine="simple"

...

location="org/hotwax/practice/PracticeServices.xml"

...

invoke="createPracticePersonInterfaceService"

...

auth="false">

...


        <description>Creates a new Person</description>
        <implements service="createPersonInterface"/>
        <attribute name="partyId"

...

mode="OUT"

...

type="String"

...

optional="false"/

...

>  
        <override name="suffix"

...

optional="false"/>

...


    </service>

...

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.