1.Ofbiz Introduction:
OFBIZ (http://www.ofbiz.org) is Open Source's business software system that fully utilizes excellent Open Source projects.
Like Tomcat, Ant, Beanshell, JBoss, etc., built a powerful system platform, OFBIZ has completed most business software systems
Need to be required, like user authentication, workflow, business rules, OFBIZ's core technology lies in Entity Engine, other components basically
It is based on it. Simply, the main function of Entity Engine is to create database tables, objects and data sheets, and object queries, etc.
Package, you can define database table structures in a simple XML file, OFBIZ will automatically help you build tables in the database and dynamically generate mapping objects.
You can only consider processing Object in the program, and OFBIZ automatically updates to the database via transaction logic. One of the advantages claimed by OFBIZ
Little Code completes complex processing.
2.Ofbiz Download and Installation
First install J2SDK1.4, download it on http://java.sun.com, set the Java_Home environment variable to the J2SDK installation directory after installation.
Access the website http://www.ofbiz.org, have a downloaded connection above, select the Complete package, because this package already contains Ofbiz
Everything can be running after downloading down.
Unlock the OFBIZ package to a directory, assume that "C: / OFBIZ", the catalog will have two directory, Catalina
The directory is Tomcat directory, and OFBIZ has modified its configuration, the OFBIZ directory is OFBIZ's program code directory. Enter in the command line
The "c: / OFBIZ / CATALINA / BIN" directory, run the "OFBIZ RUN" command, you can start OFBIZ, you can use your browser after startup
"Http:// localhost: 8080 / ecommerce", this can access the OFBIZ e-commerce module, you can access by the connection above the page.
Other modules.
3. Foundment of FBIZ Schema
Ofbiz application Getting started:
With an example, suppose we need to build a customer information sheet, named StudyCustomer, each segment is as follows:
StudyCustomer {
Customerid INTEGER,
Customername String,
Customernote String,
}
Let's implement basic data operation --- Increase / delete / change / query, the specific steps are as follows:
1. Define the data in the XML file SCHEMA:
Three files need to be used, one is the entitymodel_xxx.xml and EntityEngine.xml of the project we have to build, and
EntityGroup.xml,
EntityModel_xxx.xml is required to be created by us, suppose we are named ENTITYMODEL_STUDY.XML, put it on
"C: / OFBIZ / OFBIZ / CommonApp / EntityDef" directory,
EntityEngine.xml is Ofbiz already available, put in the "C: / Ofbiz / CommonApp / etc" directory, used to include us
Defined EntityModel file.
EntityGroup.xml is also OFBIZ already available, followed by EngityEngine.xml in the same directory, we need to add our Schema definition to the file.
The definition format of the EntityModel_Study.xml file is as follows:
XML Version = "1.0" encoding = "UTF-8"?>
"http://www.ofbiz.org/dtds/entitymodel.dtd">
Package-name = "Org.ofbiz.commonApp.study" Title = "Study Customer Entity"> Entity> EntityModel> TAG in this XML file is basically clear, Just Field's Type is OFBIZ has been predefined, this It is to ensure the migration between the database. Add the files we just defined in EntityEngine.xml, join a line in the right location: Concrete place We can find other files inside to find EntityEngine.xml. Add our Schema definition in EntityGroup.xml, join a line behind This way we define schema, now copy C: /ofbiz/commonApp/etc/entityEngine.xml to C: / OFBIZ / CATALINA / Shared / Classes directory, this is to remember, I used to have no copy, last Schema Why can't you create it. Restart OFBIZ, access URL: http: // localhost: 8080 / WebTools, click on "Login" link in the top right. Use admin / OFBIZ to log in, select the link "Check / Update Database" after entering, then CHECK FORM, The form can only verify whether Schema changes, the default groupname is "org.ofbiz.commonApp", this does not need to change, Click the "Check Only" button, OFBIZ will check the changes, display a complete list, you can check if we have just built "StudyCustomer", if not, it may be some problems we defined in front, check again. After checking, you can choose "Check and add missing", this is a very powerful function of OFBIZ, you are in XML Increase the table or add a segment in a table, which will automatically map into the database, avoid us to direct the database directly. The creation of StudyCustom Schama is now completed. If you want to check if there is a table creation, we can open it with the editor. C: /ofbiz/data/ofbiz.script, query the words of Create Table StudyCustomer, if there is no problem in front, we can find it. 4. How to use the already defined Schema How to use the already defined Schema OFBIZ follows the MVC design mode, on the View end, the JSP terminal mainly uses the OFBIZ defined TAG to display or Extract data, Control is a Controller Servlet, our URI Mapping in Controller Servlet Define each URL in the configuration file should point to what program, so that through this mapping profile, we can guarantee our various pages. And the independence between the specific processing programs, we can change a form's Post Action by modifying this profile. The URL does not need to modify the actual HTML or JSP code. The concept of Regions is defined in OFBIZ, which is to divide a HTML page into several areas, like top, left, right, main Wait, we can easily combine the UI interface through these regions, and can make it easy to change the location of each part, such as we can Move the menu from above to the bottom, just change a configuration file. Regions is similar to Frame in HTML, but it is By a page to combine the interface, Frame is displayed in different frames through several pages, and the Frame control is more complicated, and Change the related procedure. In OFBIZ, we can operate Schema defined Object directly in JSP, which is the StudyCustomer we just defined. Examples are as follows: <% @ Taglib Uri = "OFBIZTAGS" prefix = "OFBIZ"%> <% @ Page Import = "java.util. *"%> <% @ page import = "org.ofbiz.core.UTIL. *, org.ofbiz.core.pseudotag. *"%> <% @ page import = "org.ofbiz.core.entity. *"%> <% IF (Security.haseTyPermission ("Partymgr", "_View", session) {%> <% Try { Delegator.create ("StudyCustomer", Utilmisc.TOMAP ("Customerid", "1", "Customername", "Customernote", "Customer Note 1)); item CUSTS = Utilmisc.toiterator (delegator.Findall, Utilmisc.tolist ("Customerid", "Customername", "Customernote"))) While (Custs.hasNext ()) { GenericValue Cust = (genericvalue) Custs.next (); Out.println (Cust.getstring ("Customerid")); Out.println (Cust.getstring ("Customername")); Out.println (Cust.getString ("Customernote")); } } catch (Exception E) { Out.println (E.GetMessage ()); } %> <%} else {%> you do not have much permission to view this page. ("Partymgr_View" or "partymgr_admin" Needed h3>
<%}%>
This program is very easy to understand, first create an Object through Delegator, which will be automatically synchronized by OFBIZ to
In the database. Then take all saved Object by delegator's Findall, and finally pass an Iterator object.
display.
This program named Testofbiz.jsp, for the sake of simplicity, we put it in a WebApp directory of OFBIZ, put it
C: / OFBIZ / OFBIZ / PARTYMGR / WebApp / Party directory. Then we need to modify two profiles: Controller.xml
And Regions.xml, these two files are the Mapping and Regions profiles mentioned above.
Both of these files are under: c: / OFbiz / OFBIZ / Partymgr / WebApp / Web-INF, add the following in Controller.xml
request-map>
with
Please refer to Controller.xml for the Controller.xml. Add: in Regions.xml:
define>
Please refer to the existing configuration.
After configuring, restart OFBIZ, then access the URL:
Http: // localhost: 8080 / Partymgr / Control / Testofbiz
Since we use OFBIZ security control mechanism in the TestOfbiz.JSP program, the system will prompt to visit now.
Permissions, you need to log in, click "Login" on the right, you will see our program TestOfbiz.jsp after logging in with admin / OFBIZ.
Operation results. If you need to add new records, please modify
Utilmisc.TOMAP ("Customerid", "1", "Customername", "Cust1", "CustomerNote", "Customer Note 1));
Value of each segment, then access http: // localhost: 8080 / partymgr / control / testofbiz, if you do not modify
When you visit the URL directly, the system will prompt the Primary Key conflict.
5. Use Schema using the principles of displaying and logical separation:
The last story tells how to use the created schema object in JSP, this time we tell about how to put the program
Logic placed in JavaBeans, put the display processing in the JSP and use the controller.xml to
Part is integrated.
First let's create a JavaBeans to complete the add / get / delete / update schema object
Operation, the program file is named Testofbiz.java, placed
C: / OFBIZ / OFBIZ / TESTOFBIZ / COM / GEEYO / OFBIZ directory, the specific procedures are as follows:
> ================================================================================================================================================================= ================
Package com.geeyo.ofbiz;
Import javax.servlet. *;
Import javax.servlet.http. *;
Import java.util. *;
Import java.net. *;
Import Org.Ofbiz.core.UTIL. *;
Import org.ofbiz.core.entity. *;
Import Org.Ofbiz.core.Service. *;
Import Org.Ofbiz.core.security. *;
Import Org.Ofbiz.core.stats. *;
Public Class Testofbiz
{
Public static void main (string [] args)
Throws Exception
{
GenericDelegator delegator = GenericDelegator.getGenericDelegator ( "default"); delegator.create ( "StudyCustomer", UtilMisc.toMap ( "customerId", "3", "customerName", "Kane3", "customerNote", "This is test customer. 3 "));
ITerator Custs = Utilmisc.toITerator (Delegator.Findall ("StudyCustomer", Utilmisc.tolist ("Customerid", "Customername", "Customernote")))
While (Custs.hasNext ())
{
GenericValue Cust = (genericvalue) Custs.next ();
System.out.println (Cust.getstring ("Customerid");
System.out.println (Cust.getstring ("CustomerName"));
System.out.println (Cust.getstring ("Customernote"));
}
}
Public Static String CreateNewRecord (httpservletRequest Request, HttpservletResponse Response)
Throws Exception
{
Map Paras = Utilmisc.getParameterMap (Request);
GenericDelegator delegator = genericdelegator.getGenericDelegator ("default");
Delegator.create ("StudyCustomer", Paras;
Return "Success";
}
Public Static String LookAllRecords (HttpservletRequest Request, HttpservletResponse Response)
Throws Exception
{
GenericDelegator delegator = genericdelegator.getGenericDelegator ("default");
ITerator Custs = Utilmisc.toITerator (Delegator.Findall ("StudyCustomer", Utilmisc.tolist ("Customerid", "Customername", "Customernote")))
Collection col = new arraylist ();
While (Custs.hasNext ())
{
GenericValue Cust = (genericvalue) Custs.next ();
Col.Add (Cust);
}
Request.getSession (). SetaTRibute ("Search_Results", Col)
Return "Success";
}
Public Static String FindRecord (HttpservletRequest Request, HttpservletResponse Response) THROWS Exception
{
String ID = (String) Request.getParameter ("Customerid");
GenericDelegator delegator = genericdelegator.getGenericDelegator ("default");
Try {
GenericValue Cust = Delegator.FindByPrimaryKey ("StudyCustomer", Utilmisc.Tomap ("CustomerID", ID));
Request.getSession (). SetAttribute ("Edit_Cust", CUST);
} catch (genericentityException gee) {
Debug.logwarning (GEE);
}
Return "Success";
}
Public Static String UpdateRecord (httpservletRequest Request, HttpservletResponse Response)
Throws Exception
{
Map Paras = Utilmisc.getParameterMap (Request);
GenericDelegator delegator = genericdelegator.getGenericDelegator ("default");
GenericValue Cust = Delegator.FindByprimaryKey ("StudycuStomer", Utilmisc.Tomap ("Customerid", Paras.get ("CustomerID")));
Cust.setnonpkfields (Paras);
Cust.store ();
Request.getSession (). SetAttribute ("Edit_Cust", CUST);
Return "Success";
}
Public Static String RemoveRecord (httpservletRequest Request, HttpservletResponse Response)
Throws Exception
{
String strid = Request.getParameter ("ID");
GenericDelegator delegator = genericdelegator.getGenericDelegator ("default");
GenericValue Cust = Delegator.FindByPrimaryKey ("StudyCustomer", Utilmisc.Tomap ("Customerid", Strid);
Cust.remove ();
Return "Success";
}
}
> ================================================================================================================================================================= ================= Most of the processing in the program can be understood, with a function, it is
Map Paras = Utilmisc.getParameterMap (Request);
This is an interesting but very useful feature of OFBIZ. It is mapped to a map in the request in Request to a MAP.
Object, then use
Cust.setnonpkfields (Paras);
You can assign each paragraph of Object Cust, free of us to use the Request.GetParameter ("Name") to take each
Value, this feature can greatly reduce redundant code quantity when there are many values.
The logic of the basic program is like this,
1. Read the value from the Request
2. Use Delegator to handle, add / update / delete / query
3. Put the return result in the session to JSP
I made an Ant build.xml file to help compile, put this file:
C: / OFBIZ / OFBIZ / TESTOFBIZ / Directory, then enter the directory under the command line window, knock an ANT
To compile (need to ensure that Ant is installed), after compiled .class will be put
C: / OFBIZ / OFBIZ / TESTOFBIZ / COM / GEEYO / OFBIZ,
Copy C: / Ofbiz / Offbiz / TestOfbiz / COM directory to C: / OFBIZ / OFBIZ / PartYMGR / WebApp / Web-INF / CLASSES
Under contents.
Build.xml
> ================================================================================================================================================================= ============================
fileset>
fileset>
path>
target>
Description = "Compile the Source"> javac> target> Description = "Generate the distribution"> target> Description = "Clean Up"> target> provject> > ================================================================================================================================================================= ============================ then let's create a JSP program, all of the JSP programs are put C: / OFBIZ / OFBIZ / PARTYMGR / WebApp / Party 1.Listofbiz.jsp > ================================================================================================================================================================= ============================ <% @ Taglib Uri = "OFBIZTAGS" prefix = "OFBIZ"%> <% @ Page Import = "java.util. *, org.ofbiz.core.service.modelservice"%> <% @ page import = "org.ofbiz.core.UTIL. *, org.ofbiz.core.pseudotag. *"%> <% @ page import = "org.ofbiz.core.entity. *"%> Function confirmdelete () { RETURN CONFIRM ("Are Your Sure To delete?"); } script> <% IF (Security.haseTyPermission ("Partymgr", "_View", session) {%> td> TR> OFBIZ: ITERATOR> OFBIZ: IF> TABLE> TR> TABLE> <%} else {%> <%}%> > ================================================================================================================================================================= ============================================================================================================================================================================= with Whether to include a Search_Results object, the object is placed in the session from our program. Search_results stored in the objects stored in the COLLECTION object, and assigns Cust, then in the cyclic body In, we can use the Cust object to read the value of each segment. 2.CreateOfbiz.jsp > ================================================================================================================================================================= ============================ <% @ Taglib Uri = "OFBIZTAGS" prefix = "OFBIZ"%> <% @ Page Import = "java.util. *, org.ofbiz.core.service.modelservice"%> <% @ page import = "org.ofbiz.core.UTIL. *, org.ofbiz.core.pseudotag. *"%> <% @ page import = "org.ofbiz.core.entity. *"%> <% IF (Security.haseTyPermission ("Partymgr", "_View", session) {%>
ID tH> Name TH> Note TH> th> tr>
CREATE CUSTOMER td>
you do not have much permission to view this page. ("Partymgr_View" or "partymgr_admin" Needed h3>