实列3_1
2015-07-23 10:32
281 查看
目录结构 增加加service 文件 进行数据更新
增加有控制逻辑文件
增加有更新请求
增加方法
增加更新逻辑
最终显示结果
参考:
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 operationsfor 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 record, first a party record needs to be created with partyTypeId="PERSON". So there can be two ways to do that:
Create service for the creation of a party with party type "PERSON".
Create a party first in the service which will be creating person.
Writing Services
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.
In controller you have to create an entry for the request for the execution of a service and set the response like.
?
<request-map uri= "createPracticePerson" > <security https= "true" auth= "true" /> <event type= "service" invoke= "createPracticePerson" /> <response name= "success" type= "view" value= "PersonForm" /> </request-map> |
?
<service-resource type= "model" loader= "main" location= "servicedef/services.xml" /> |
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.Create a file by name "services.xml" in servicedef directory.
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.
Create directory structure and PracticeServices.xml file in your component directory for giving the implementation of these services. (For implementation take reference from services.xml and
ExampleServices.xml files of Example component)
Important
Icon
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.
At this place you must read http://markmail.org/message/dj4wvtm4u2nxoz3r. This feature has been added against the traditional approach of writing CRUD operations
for an entity.
This new feature enables you to just define the services by mentioning the operation you want to perform.Basically just set the engine attribute to "entity-auto" and the invoke attribute to
"create", "update", or "delete".
like you can take a look in the following code from services.xml of example component:
?
<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> |
Here for practice you may go by following further steps those steps will help you in understanding the concept then onwards you can practice the pattern given above in your code as its the best practice for these kind of simple operations in OFBiz.
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 createthe 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.
Create the add form for the creation of person and add this in the same screen for person form.
?
<form name= "CreatePerson" type= "single" target= "createPracticePerson" > <auto-fields-service service-name= "createPracticePerson" /> <field name= "submitButton" title= "Create" widget-style= "smallSubmit" ><submit button-type= "button" /></field> </form> |
?
<service name= "createPracticePerson" default -entity-name= "Person" engine= "simple" location= "component://practice/script/org/hotwax/practice/PracticeServices.xml" invoke= "createPracticePerson" auth= "true" > <description>Create a Person</description> <auto-attributes include= "pk" mode= "OUT" optional= "false" /> <attribute name= "salutation" mode= "IN" type= "String" optional= "true" /> <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> |
# 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. As shown bellow:
?
<form name= "ListPersons" type= "list" list-name= "persons" list-entry-name= "person" target= "updatePracticePerson" paginate-target= "personForm" > <auto-fields-service service-name= "updatePracticePerson" default -field-type= "edit" map-name= "person" /> <field name= "partyId" ><hidden/></field> <field name= "submitButton" title= "Update" widget-style= "smallSubmit" ><submit button-type= "button" /></field> <field name= "deletePracticePerson" title= "Delete Person" widget-style= "buttontext" > <hyperlink target= "deletePracticePerson?partyId=${person.partyId}" description= "Delete" /> </field> </form> |
Now run the application and see the output screen as bellow:
Output Screen:
相关文章推荐
- 实列3-2
- 设置页面显示个数
- sql语法:inner join on, left join on, right join on详细使用方法
- Codeforces Round #313 (Div. 2)(A,B,C,D)
- linux fork 函数
- 懒人的python——一次执行多条linux命令
- CodeVS 3304 水果姐逛水果街Ⅰ(线段树)
- [Unity3D]脚本中Start()和Awake()的区别
- OC—写入,读取文件
- Populating Next Right Pointers in Each Node
- Web.xml配置详解
- 什么是独占设备,对独占设备如何分配?
- 内存优化
- ISO 8 自适应cell
- SSH 环境搭建例子详解
- MS access sql injection cheat sheet -version 0.2
- ofbiz
- 表
- android studio常用快捷键
- webapp开发---后台框架 ci rest