Ofbiz Getting Started Tutorial

xiaoxiao2021-03-06  59

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:

"http://www.ofbiz.org/dtds/entitymodel.dtd">

Entity of An Open for Business Project Component </ Title></p> <p><Description> None </ description></p> <p><Copyright> Copyright (C) 2002 The Open for Business Project - www.ofbiz.org </ Copyright></p> <p><author> none </ author>></p> <p><Version> 1.0 </ version></p> <p><! - =============================================== =========== -></p> <p><! - ======================== Data mod ===================== = -></p> <p><! - The Modules in this file area as follows: -></p> <p><! - - org.ofbiz.commonapp.study -></p> <p><! - =============================================== =========== -> <! - ================================= ========================= -></p> <p><! - org.ofbiz.commonapp.study -></p> <p><! - =============================================== =========== -></p> <p><Entity Entity-name = "studycustomer"</p> <p>Package-name = "Org.ofbiz.commonApp.study"</p> <p>Title = "Study Customer Entity"></p> <p><Field Name = "Customerid" type = "id-ne"> </ field></p> <p><Field Name = "Customername" type = "long-varchar"> </ field></p> <p><Field Name = "Customernote" Type = "long-varchar"> </ field></p> <p><prim-key field = "customerid" /></p> <p></ Entity></p> <p></ EntityModel></p> <p><! - =============================================== =========================================== -> TAG in this XML file is basically clear, Just Field's Type is OFBIZ has been predefined, this</p> <p>It is to ensure the migration between the database.</p> <p>Add the files we just defined in EntityEngine.xml, join a line in the right location:</p> <p><Resource Loader = "Mainfile" location = "EntityModel_Study.xml" /></p> <p>Concrete place We can find other files inside to find EntityEngine.xml.</p> <p>Add our Schema definition in EntityGroup.xml, join a line behind</p> <p><Entity-Group Group = "Org.Ofbiz.commonApp" entity = "studycustomer" /></p> <p>This way we define schema, now copy C: /ofbiz/commonApp/etc/entityEngine.xml to</p> <p>C: / OFBIZ / CATALINA / Shared / Classes directory, this is to remember, I used to have no copy, last Schema</p> <p>Why can't you create it.</p> <p>Restart OFBIZ, access URL: http: // localhost: 8080 / WebTools, click on "Login" link in the top right.</p> <p>Use admin / OFBIZ to log in, select the link "Check / Update Database" after entering, then CHECK FORM,</p> <p>The form can only verify whether Schema changes, the default groupname is "org.ofbiz.commonApp", this does not need to change,</p> <p>Click the "Check Only" button, OFBIZ will check the changes, display a complete list, you can check if we have just built</p> <p>"StudyCustomer", if not, it may be some problems we defined in front, check again.</p> <p>After checking, you can choose "Check and add missing", this is a very powerful function of OFBIZ, you are in XML</p> <p>Increase the table or add a segment in a table, which will automatically map into the database, avoid us to direct the database directly.</p> <p>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.</p> <p>C: /ofbiz/data/ofbiz.script, query the words of Create Table StudyCustomer, if there is no problem in front, we can find it.</p> <p>4. How to use the already defined Schema</p> <p>How to use the already defined Schema</p> <p>OFBIZ follows the MVC design mode, on the View end, the JSP terminal mainly uses the OFBIZ defined TAG to display or</p> <p>Extract data, Control is a Controller Servlet, our URI Mapping in Controller Servlet</p> <p>Define each URL in the configuration file should point to what program, so that through this mapping profile, we can guarantee our various pages.</p> <p>And the independence between the specific processing programs, we can change a form's Post Action by modifying this profile.</p> <p>The URL does not need to modify the actual HTML or JSP code.</p> <p>The concept of Regions is defined in OFBIZ, which is to divide a HTML page into several areas, like top, left, right, main</p> <p>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</p> <p>Move the menu from above to the bottom, just change a configuration file. Regions is similar to Frame in HTML, but it is</p> <p>By a page to combine the interface, Frame is displayed in different frames through several pages, and the Frame control is more complicated, and</p> <p>Change the related procedure.</p> <p>In OFBIZ, we can operate Schema defined Object directly in JSP, which is the StudyCustomer we just defined.</p> <p>Examples are as follows:</p> <p><% @ Taglib Uri = "OFBIZTAGS" prefix = "OFBIZ"%></p> <p><% @ Page Import = "java.util. *"%></p> <p><% @ page import = "org.ofbiz.core.UTIL. *, org.ofbiz.core.pseudotag. *"%></p> <p><% @ page import = "org.ofbiz.core.entity. *"%></p> <p><jsp: usebean id = "delegator" type = "org.ofbiz.core.entity.GenericDelegator" scope = "request" /></p> <p><jsp: usebean id = "security" type = "org.ofbiz.core.security.security" scope = "request" /></p> <p><% IF (Security.haseTyPermission ("Partymgr", "_View", session) {%></p> <p><%</p> <p>Try {</p> <p>Delegator.create ("StudyCustomer",</p> <p>Utilmisc.TOMAP ("Customerid", "1", "Customername", "Customernote", "Customer Note 1)); item CUSTS =</p> <p>Utilmisc.toiterator (delegator.Findall, Utilmisc.tolist ("Customerid", "Customername", "Customernote")))</p> <p>While (Custs.hasNext ())</p> <p>{</p> <p>GenericValue Cust = (genericvalue) Custs.next ();</p> <p>Out.println (Cust.getstring ("Customerid"));</p> <p>Out.println (Cust.getstring ("Customername"));</p> <p>Out.println (Cust.getString ("Customernote"));</p> <p>}</p> <p>} catch (Exception E)</p> <p>{</p> <p>Out.println (E.GetMessage ());</p> <p>}</p> <p>%></p> <p><%} else {%></p> <p><h3> you do not have much permission to view this page. ("Partymgr_View" or "partymgr_admin" Needed </ h3></p> <p><%}%></p> <p>This program is very easy to understand, first create an Object through Delegator, which will be automatically synchronized by OFBIZ to</p> <p>In the database. Then take all saved Object by delegator's Findall, and finally pass an Iterator object.</p> <p>display.</p> <p>This program named Testofbiz.jsp, for the sake of simplicity, we put it in a WebApp directory of OFBIZ, put it</p> <p>C: / OFBIZ / OFBIZ / PARTYMGR / WebApp / Party directory. Then we need to modify two profiles: Controller.xml</p> <p>And Regions.xml, these two files are the Mapping and Regions profiles mentioned above.</p> <p>Both of these files are under: c: / OFbiz / OFBIZ / Partymgr / WebApp / Web-INF, add the following in Controller.xml</p> <p><request-map uri = "testofbiz"></p> <p><Description> Test OFBIZ </ Description></p> <p><security https = "false" auth = "false" /></p> <p><Response name = "success" type = "view" value = "testofbiz" /></p> <p></ request-map></p> <p>with</p> <p><view-map name = "Testofbiz" type = "region" /></p> <p>Please refer to Controller.xml for the Controller.xml. Add: in Regions.xml:</p> <p><define id = 'Testofbiz' region = 'main_region'></p> <p><Put Section = 'Title'> Test OFBIZ </ PUT> <PUT Section = 'Content' Content = '/ Party / TestOfbiz.JSP' /></p> <p></ define></p> <p>Please refer to the existing configuration.</p> <p>After configuring, restart OFBIZ, then access the URL:</p> <p>Http: // localhost: 8080 / Partymgr / Control / Testofbiz</p> <p>Since we use OFBIZ security control mechanism in the TestOfbiz.JSP program, the system will prompt to visit now.</p> <p>Permissions, you need to log in, click "Login" on the right, you will see our program TestOfbiz.jsp after logging in with admin / OFBIZ.</p> <p>Operation results. If you need to add new records, please modify</p> <p>Utilmisc.TOMAP ("Customerid", "1", "Customername", "Cust1", "CustomerNote", "Customer Note 1));</p> <p>Value of each segment, then access http: // localhost: 8080 / partymgr / control / testofbiz, if you do not modify</p> <p>When you visit the URL directly, the system will prompt the Primary Key conflict.</p> <p>5. Use Schema using the principles of displaying and logical separation:</p> <p>The last story tells how to use the created schema object in JSP, this time we tell about how to put the program</p> <p>Logic placed in JavaBeans, put the display processing in the JSP and use the controller.xml to</p> <p>Part is integrated.</p> <p>First let's create a JavaBeans to complete the add / get / delete / update schema object</p> <p>Operation, the program file is named Testofbiz.java, placed</p> <p>C: / OFBIZ / OFBIZ / TESTOFBIZ / COM / GEEYO / OFBIZ directory, the specific procedures are as follows:</p> <p>> ================================================================================================================================================================= ================</p> <p>Package com.geeyo.ofbiz;</p> <p>Import javax.servlet. *;</p> <p>Import javax.servlet.http. *;</p> <p>Import java.util. *;</p> <p>Import java.net. *;</p> <p>Import Org.Ofbiz.core.UTIL. *;</p> <p>Import org.ofbiz.core.entity. *;</p> <p>Import Org.Ofbiz.core.Service. *;</p> <p>Import Org.Ofbiz.core.security. *;</p> <p>Import Org.Ofbiz.core.stats. *;</p> <p>Public Class Testofbiz</p> <p>{</p> <p>Public static void main (string [] args)</p> <p>Throws Exception</p> <p>{</p> <p>GenericDelegator delegator = GenericDelegator.getGenericDelegator ( "default"); delegator.create ( "StudyCustomer", UtilMisc.toMap ( "customerId", "3", "customerName", "Kane3", "customerNote", "This is test customer. 3 "));</p> <p>ITerator Custs = Utilmisc.toITerator (Delegator.Findall ("StudyCustomer", Utilmisc.tolist ("Customerid", "Customername", "Customernote")))</p> <p>While (Custs.hasNext ())</p> <p>{</p> <p>GenericValue Cust = (genericvalue) Custs.next ();</p> <p>System.out.println (Cust.getstring ("Customerid");</p> <p>System.out.println (Cust.getstring ("CustomerName"));</p> <p>System.out.println (Cust.getstring ("Customernote"));</p> <p>}</p> <p>}</p> <p>Public Static String CreateNewRecord (httpservletRequest Request, HttpservletResponse Response)</p> <p>Throws Exception</p> <p>{</p> <p>Map Paras = Utilmisc.getParameterMap (Request);</p> <p>GenericDelegator delegator = genericdelegator.getGenericDelegator ("default");</p> <p>Delegator.create ("StudyCustomer", Paras;</p> <p>Return "Success";</p> <p>}</p> <p>Public Static String LookAllRecords (HttpservletRequest Request, HttpservletResponse Response)</p> <p>Throws Exception</p> <p>{</p> <p>GenericDelegator delegator = genericdelegator.getGenericDelegator ("default");</p> <p>ITerator Custs = Utilmisc.toITerator (Delegator.Findall ("StudyCustomer", Utilmisc.tolist ("Customerid", "Customername", "Customernote")))</p> <p>Collection col = new arraylist ();</p> <p>While (Custs.hasNext ())</p> <p>{</p> <p>GenericValue Cust = (genericvalue) Custs.next ();</p> <p>Col.Add (Cust);</p> <p>}</p> <p>Request.getSession (). SetaTRibute ("Search_Results", Col)</p> <p>Return "Success";</p> <p>}</p> <p>Public Static String FindRecord (HttpservletRequest Request, HttpservletResponse Response) THROWS Exception</p> <p>{</p> <p>String ID = (String) Request.getParameter ("Customerid");</p> <p>GenericDelegator delegator = genericdelegator.getGenericDelegator ("default");</p> <p>Try {</p> <p>GenericValue Cust = Delegator.FindByPrimaryKey ("StudyCustomer", Utilmisc.Tomap ("CustomerID", ID));</p> <p>Request.getSession (). SetAttribute ("Edit_Cust", CUST);</p> <p>} catch (genericentityException gee) {</p> <p>Debug.logwarning (GEE);</p> <p>}</p> <p>Return "Success";</p> <p>}</p> <p>Public Static String UpdateRecord (httpservletRequest Request, HttpservletResponse Response)</p> <p>Throws Exception</p> <p>{</p> <p>Map Paras = Utilmisc.getParameterMap (Request);</p> <p>GenericDelegator delegator = genericdelegator.getGenericDelegator ("default");</p> <p>GenericValue Cust = Delegator.FindByprimaryKey ("StudycuStomer", Utilmisc.Tomap ("Customerid", Paras.get ("CustomerID")));</p> <p>Cust.setnonpkfields (Paras);</p> <p>Cust.store ();</p> <p>Request.getSession (). SetAttribute ("Edit_Cust", CUST);</p> <p>Return "Success";</p> <p>}</p> <p>Public Static String RemoveRecord (httpservletRequest Request, HttpservletResponse Response)</p> <p>Throws Exception</p> <p>{</p> <p>String strid = Request.getParameter ("ID");</p> <p>GenericDelegator delegator = genericdelegator.getGenericDelegator ("default");</p> <p>GenericValue Cust = Delegator.FindByPrimaryKey ("StudyCustomer", Utilmisc.Tomap ("Customerid", Strid);</p> <p>Cust.remove ();</p> <p>Return "Success";</p> <p>}</p> <p>}</p> <p>> ================================================================================================================================================================= ================= Most of the processing in the program can be understood, with a function, it is</p> <p>Map Paras = Utilmisc.getParameterMap (Request);</p> <p>This is an interesting but very useful feature of OFBIZ. It is mapped to a map in the request in Request to a MAP.</p> <p>Object, then use</p> <p>Cust.setnonpkfields (Paras);</p> <p>You can assign each paragraph of Object Cust, free of us to use the Request.GetParameter ("Name") to take each</p> <p>Value, this feature can greatly reduce redundant code quantity when there are many values.</p> <p>The logic of the basic program is like this,</p> <p>1. Read the value from the Request</p> <p> 2. Use Delegator to handle, add / update / delete / query</p> <p>3. Put the return result in the session to JSP</p> <p>I made an Ant build.xml file to help compile, put this file:</p> <p>C: / OFBIZ / OFBIZ / TESTOFBIZ / Directory, then enter the directory under the command line window, knock an ANT</p> <p>To compile (need to ensure that Ant is installed), after compiled .class will be put</p> <p>C: / OFBIZ / OFBIZ / TESTOFBIZ / COM / GEEYO / OFBIZ,</p> <p>Copy C: / Ofbiz / Offbiz / TestOfbiz / COM directory to C: / OFBIZ / OFBIZ / PartYMGR / WebApp / Web-INF / CLASSES</p> <p>Under contents.</p> <p>Build.xml</p> <p>> ================================================================================================================================================================= ============================</p> <p><Project name = "Testofbiz" default = "DIST" basedir = ">></p> <p><description></p> <p>Test OFBIZ</p> <p></ description></p> <p><! - TEST CVS -></p> <p><! - set Global Properties for this build -></p> <p><Property Name = "src" location = "." /> <property name = "Build" location = "." /></p> <p><proty name = "lib_dir" location = "c: / offbiz / catalina / shared / lib" /></p> <p><proty name = "lib1_dir" location = "c: / offbiz / catalina / common / lib" /></p> <p><path id = "project.class.path"></p> <p><fileset dir = "$ l l_dir}"></p> <p><include Name = "*. jar" /></p> <p></ fileset></p> <p><fileset dir = "$ {lib1_dir}"></p> <p><include Name = "*. jar" /></p> <p></ fileset></p> <p></ path></p> <p><target name = "init"></p> <p><! - CREATE The Time Stamp -></p> <p><TSTAMP /></p> <p><! - CREATE The Build Directory Structure Used by Compile -></p> <p><mkdir dir = "$ {build}" /></p> <p></ target></p> <p><target name = "compile" depends = "init"</p> <p>Description = "Compile the Source"></p> <p><! - compile the java code from $ {src} inTo $ {build} -></p> <p><javac srcdir = "$ {src}" destdir = "$ {build}"></p> <p><classpath refid = "Project.class.path" /></p> <p></ javac></p> <p></ target></p> <p><target name = "dist" depends = "compile"</p> <p>Description = "Generate the distribution"></p> <p><! - CREATE The Distribution Directory -></p> <p></ target></p> <p><target name = "clean"</p> <p>Description = "Clean Up"></p> <p><! - delete the $ {build} and $ {dist} Directory Trees -></p> <p></ target></p> <p></ provject></p> <p>> ================================================================================================================================================================= ============================ then let's create a JSP program, all of the JSP programs are put</p> <p>C: / OFBIZ / OFBIZ / PARTYMGR / WebApp / Party</p> <p>1.Listofbiz.jsp</p> <p>> ================================================================================================================================================================= ============================</p> <p><% @ Taglib Uri = "OFBIZTAGS" prefix = "OFBIZ"%></p> <p><% @ Page Import = "java.util. *, org.ofbiz.core.service.modelservice"%></p> <p><% @ page import = "org.ofbiz.core.UTIL. *, org.ofbiz.core.pseudotag. *"%></p> <p><% @ page import = "org.ofbiz.core.entity. *"%></p> <p><jsp: usebean id = "security" type = "org.ofbiz.core.security.security" scope = "request" /></p> <p><jsp: usebean id = "delegator" type = "org.ofbiz.core.entity.GenericDelegator" scope = "request" /></p> <p><script language = "javascript"></p> <p>Function confirmdelete ()</p> <p>{</p> <p>RETURN CONFIRM ("Are Your Sure To delete?");</p> <p>}</p> <p></ script></p> <p><% IF (Security.haseTyPermission ("Partymgr", "_View", session) {%></p> <p><table width = "600" align = "center"> <OFBIZ: if Name = "Search_Results"></p> <p><tr> <th> ID </ tH> <TH> Name </ TH> <TH> Note </ TH> <TH> </ th> </ tr></p> <p><OFBIZ: Iterator Name = "Cust" property = "Search_Results"></p> <p><tr></p> <p><TD> <OFBIZ: EntityField Attribute = "Cust" Field = "Customerid" /> </ td></p> <p><TD> <OFBIZ: EntityField Attribute = "CUST" Field = "Customername" /> </ td></p> <p><TD> <OFBIZ: EntityField Attribute = "Cust" Field = "Customernote" /> </ td></p> <p><TD></p> <p><a href='<Ofbiz:ürl> / showte? Customerid = <OFBIZ: EntityField Attribute = "Cust" field = "customerid" /> </ OFBIZ: URL> 'Class = "ButtonText"> [Edit] </ a ></p> <p><a href='<Ofbiz:UR> / Removetest? Customerid = <OFBIZ: EntityField Attribute = "Cust" field = "customerid" /> </ OFBIZ: URL> 'class = "Buttontext" οnclick = "Return ConfirMdelete () "> [Transove] </A></p> <p></ td></p> <p></ TR></p> <p></ OFBIZ: ITERATOR></p> <p></ OFBIZ: IF></p> <p></ TABLE></p> <p><Table Width = "200" align = "center"></p> <p><tr></p> <p><TD> <a href='<Ofbiz:UroR> / CreateTestForm </ OFBIZ: URL> '> CREATE CUSTOMER </a> </ td></p> <p></ TR></p> <p></ TABLE></p> <p><%} else {%></p> <p><h3> you do not have much permission to view this page. ("Partymgr_View" or "partymgr_admin" Needed </ h3></p> <p><%}%></p> <p>> ================================================================================================================================================================= =============================================================================================================================================================================</p> <p><OFBIZ: if Name = "Search_Results"></p> <p>with</p> <p><OFBIZ: Iterator Name = "Cust" Property = "Search_Results">,</p> <p><OFBIZ: if Name = "Search_Results"> is used to verify the session or pageContext object</p> <p>Whether to include a Search_Results object, the object is placed in the session from our program.</p> <p><OFBIZ: Iterator Name = "Cust" property = "Search_Results"> is used to loop read objects</p> <p>Search_results stored in the objects stored in the COLLECTION object, and assigns Cust, then in the cyclic body</p> <p>In, we can use the Cust object to read the value of each segment.</p> <p>2.CreateOfbiz.jsp</p> <p>> ================================================================================================================================================================= ============================</p> <p><% @ Taglib Uri = "OFBIZTAGS" prefix = "OFBIZ"%></p> <p><% @ Page Import = "java.util. *, org.ofbiz.core.service.modelservice"%></p> <p><% @ page import = "org.ofbiz.core.UTIL. *, org.ofbiz.core.pseudotag. *"%></p> <p><% @ page import = "org.ofbiz.core.entity. *"%></p> <p><jsp: usebean id = "security" type = "org.ofbiz.core.security.security" scope = "request" /> <jsp: usebean id = "delegator" type = "org.Ofbiz.core.entity.GenericDelegate "scope =" request "/></p> <p><% IF (Security.haseTyPermission ("Partymgr", "_View", session) {%></p> <p><form method = "post" action = "<OFBIZ: URL> / CreateTest </ OFBIZ: URL>" Name = "CreateOfbiz"></p> <p><Table Width = "300" align = "center"></p> <p><tr></p> <p><TD> ID </ TD> <TD> <input type = "text" name = "Customerid" size = "20"> </ td></p> <p></ TR></p> <p><tr></p> <p><TD> Name </ TD> <TD> <input type = "text" Name = "Customername" size = "20"> </ td></p> <p></ TR></p> <p><tr></p> <p><TD> Note </ TD> <TD> <input type = "text" name = "Customernote" size = "30"> </ td></p> <p></ TR></p> <p><tr></p> <p><TD> </ td></p> <p><TD> <Input Type = "Submit"> </ td></p> <p></ TR></p> <p></ TABLE></p> <p></ form></p> <p><%} else {%></p> <p><h3> you do not have much permission to view this page. ("Partymgr_View" or "partymgr_admin" Needed </ h3></p> <p><%}%></p> <p>> ================================================================================================================================================================= ============================</p> <p>This procedure is easy to understand, you need to pay attention to the name of each text box, you have to consistent with each segment of Schema StudyCustomer to make the program to process it.</p> <p>3.Showofbiz.jsp</p> <p>> ================================================================================================================================================================= ============================</p> <p><% @ Taglib Uri = "OFBIZTAGS" prefix = "OFBIZ"%></p> <p><% @ Page Import = "java.util. *, org.ofbiz.core.service.modelservice"%></p> <p><% @ page import = "org.ofbiz.core.UTIL. *, org.ofbiz.core.pseudotag. *"%></p> <p><% @ page import = "org.ofbiz.core.entity. *"%></p> <p><jsp: usebean id = "security" type = "org.ofbiz.core.security.security" scope = "request" /></p> <p><jsp: usebean id = "delegator" type = "org.ofbiz.core.entity.GenericDelegator" scope = "request" /></p> <p><% IF (Security.haseTyPermission ("Partymgr", "_View", session) {%></p> <p><form method = "post" action = "<OFBIZ: URL> / UpdateTest </ OFBIZ: URL>" Name = "UpdateOfbiz"></p> <p><Table Width = "300" align = "center"></p> <p><tr></p> <p><TD> ID </ TD> <TD> <input type = "name =" customerid "size =" 20 "value =" <OFBIZ: Entityfield Attribute = "Edit_Cust" Field = "/>"> < / TD></p> <p></ TR></p> <p><tr></p> <p><TD> Name </ TD> <TD> <Input Type = "Name =" Customername "Size =" 20 "Value =" <OFBIZ: EntityField Attribute = "Edit_Cust" Field = "Customername" /> "> < / TD> </ tr></p> <p><tr></p> <p><TD> Note </ TD> <TD> <Input Type = "Name =" Customernote "Size =" 30 "Value =" <OFBIZ: EntityField Attribute = "Edit_Cust" Field = "Customernote" />> < / TD></p> <p></ TR></p> <p><tr></p> <p><TD> </ td></p> <p><TD> <Input Type = "Submit"> </ td></p> <p></ TR></p> <p></ TABLE></p> <p></ form></p> <p><%} else {%></p> <p><h3> you do not have much permission to view this page. ("Partymgr_View" or "partymgr_admin" Needed </ h3></p> <p><%}%></p> <p>> ================================================================================================================================================================= ============================</p> <p>This program is mainly through</p> <p><OFBIZ: EntityField Attribute = "Edit_Cust" Field = "Customerid" /></p> <p>Show the paragraph of the taken object, the object edit_cust is we taken and put in the session in the program.</p> <p>Let's configure Controller.xml and Regions.xml, join in Controller.xml:</p> <p>> ================================================================================================================================================================= ============================ <request-map uri = "createstform"></p> <p><Description> Show The Create Form </ description></p> <p><security https = "false" auth = "false" /></p> <p><Response name = "success" type = "view" value = "createtestform" /></p> <p></ request-map></p> <p><request-map uri = "testofbiz"></p> <p><Description> Test OFBIZ </ Description></p> <p><security https = "false" auth = "false" /></p> <p><Response name = "success" type = "view" value = "testofbiz" /></p> <p></ request-map></p> <p><request-map uri = "listtest"></p> <p><Description> List All Records </ Description></p> <p><security https = "false" auth = "false" /></p> <p><event type = "java" path = "com.geeyo.ofbiz.testofbiz" invoke = "LookAllRecords" /></p> <p><response name = "success" type = "view" value = "listalltest" /></p> <p></ request-map></p> <p><request-map uri = "showtest"></p> <p><Description> Show Records </ Description></p> <p><security https = "false" auth = "false" /></p> <p><event type = "java" path = "com.geeyo.ofbiz.testofbiz" invoke = "findrecord" /></p> <p><Response name = "success" type = "view" value = "showtest" /> </ request-map></p> <p><request-map uri = "createtetest"></p> <p><security https = "true" auth = "true" /></p> <p><event type = "java" path = "com.geeyo.ofbiz.testofbiz" invoke = "createNewrecord" /></p> <p><Response name = "success" type = "request" value = "listtest" /></p> <p><Response name = "error" type = "view" value = "createtestform" /></p> <p></ request-map></p> <p><request-map uri = "updatetest"></p> <p><Description> Update a Record </ description></p> <p><security https = "false" auth = "false" /></p> <p><event type = "java" path = "com.geeyo.ofbiz.testofbiz" invoke = "updateRecord" /></p> <p><Response name = "success" type = "request" value = "listtest" /></p> <p></ request-map></p> <p><request-map uri = "removetest"></p> <p><Description> Remove a Record </ description></p> <p><security https = "false" auth = "false" /></p> <p><event type = "java" path = "com.geeyo.ofbiz.testofbiz" invoke = "removeRecord" /></p> <p><Response name = "success" type = "request" value = "listtest" /></p> <p></ request-map></p> <p><view-map name = "listalltest" type = "region" /></p> <p><view-map name = "createtestform" type = "region" /></p> <p><view-map name = "showte" type = "region" /></p> <p>> ================================================================================================================================================================= ============================ Add:</p> <p>> ================================================================================================================================================================= ============================</p> <p><define id = 'recreatetestform' region = 'main_region'></p> <p><Put Section = 'Title'> CREATE OFBIZ </ PUT></p> <p><Put section = 'content' content = '/ party / createofbiz.jsp' /></p> <p></ define></p> <p><define id = 'listalltest' region = 'main_region'></p> <p><Put Section = 'Title'> List OFBIZ </ PUT></p> <p><put section = 'content' content = '/ party / listofbiz.jsp' /></p> <p></ define></p> <p><defion = 'showtest' region = 'main_region'></p> <p><Put Section = 'Title'> Show OFBIZ </ PUT></p> <p><Put Section = 'Content' Content = '/ Party / ShowOfbiz.Jsp' /></p> <p></ define></p> <p>> ================================================================================================================================================================= ============================ is complete now, we restart OFBIZ and use IE to access:</p> <p>Http:// localhost: 8080 / partymgr / control / listtest, you can log in with admin / OFBIZ</p> <p>Seeing our work results, you can now add / delete / modify the record.</p> <p>6.Ofbiz complete database operations (very powerful features) via XML (very powerful features)</p> <p>This is a very powerful function of OFBIZ, which may complete data increase / deletion / change by simple XML files.</p> <p>These processes are very much in database applications, because there are many data that need to be maintained, so write procedures are also time to time.</p> <p>Ofbiz completes these operations through XML, can't be said to be a revolution - so that we can do it without writing programs</p> <p>Part of processing, this is the ultimate goal of each programmer.</p> <p>Let's use XML using the STUDYCUSTOMER that is processed by us.</p> <p>The configuration file is used to complete most of the previous program TestOfbiz.java.</p> <p>Create a file TestofbizServices.xml in a C: / Ofbiz / Ofbiz / TestOfbiz / COM / GEEYO / OFBIZ directory.</p> <p>The content of this file is as follows:</p> <p>> ================================================================================================================================================================= ================</p> <p><? XML Version = "1.0" encoding = "UTF-8"?></p> <p><! Doctype simple-methods public "- // ofbiz // DTD Simple methods // en" "http://www.ofbiz.org/dtds/simple-methods.dtd"></p> <p><Simple-Methods></p> <p><! - Testofbiz Methods -></p> <p><Simple-Method Method-Name = "CreateNewRecord" short-description = "Create a new record"></p> <p><Check-permission permission = "STUDYCUSTOMER" action = "_ CREATE"> <fail-message message = "Security Error: to run createRecord you must have the STUDYCUSTOMER_CREATE permission" /> </ check-permission> <check-errors /> < Make-value entity-name = "studycustomer" value-name = "newentity" /></p> <p><set-pk-fields map-name = "parameters" value-name = "newentity" /></p> <p><set-nonpk-fields map-name = "parameters" value-name = "newentity" /></p> <p><create-value value-name = "newentity" /></p> <p></ simple-method></p> <p><Simple-Method Method-Name = "UpdateRecord" short-description = "Update a record"></p> <p><Check-permission permission = "STUDYCUSTOMER" action = "_ UPDATE"> <fail-message message = "Security Error: to run updateRecord you must have the STUDYCUSTOMER_UPDATE permission" /> </ check-permission></p> <p><Check-Errors /></p> <p><make-value entity-name = "studycustomer" value-name = "lookuppkmap" /></p> <p><set-pk-fields map-name = "parameters" value-name = "lookuppkmap" /></p> <p><Find-by-primary-key entity-name = "studycustomer" map-name = "lookuppkmap" value-name = "lookedupvalue" /></p> <p><set-nonpk-fields map-name = "parameters" value-name = "lookedupvalue" /></p> <p><store-value value-name = "lookedupvalue" /></p> <p></ simple-method></p> <p><Simple-Method Method-Name = "Findrecord" short-description = "Lookup A Record"></p> <p><Check-Errors /></p> <p><make-value entity-name = "studycustomer" value-name = "lookuppkmap" /> <set-pk-fields map-name = "parameters" value-name = "lookuppkmap" /></p> <p><find-by-primary-key entity-name = "studycustomer" map-name = "lookuppkmap" value-name = "edit_cust" /></p> <p><Field-to-session Field-name = "Edit_Cust" /></p> <p></ simple-method></p> <p><Simple-Method Method-Name = "RemoveRecord" short-description = "delete a record"></p> <p><checkYcustom permission = "studycustomer" action = "_ delete"> <fail-message message = "security error: to run deleterecord you must have the studycustomer_delete permission" /> </ check-permission></p> <p><Check-Errors /></p> <p><make-value entity-name = "studycustomer" value-name = "lookuppkmap" /></p> <p><set-pk-fields map-name = "parameters" value-name = "lookuppkmap" /></p> <p><Find-by-primary-key entity-name = "studycustomer" map-name = "lookuppkmap" value-name = "lookedupvalue" /></p> <p><remove-value value-name = "lookedupvalue" /></p> <p></ simple-method></p> <p><Simple-Method Method-Name = "LookAllRecords" Short-Description = "Lookup Suitable Records"></p> <p><Check-Errors /></p> <p><Find-by-and entity-name = "studycustomer" list-name = "search_results" /></p> <p><Field-to-session Field-name = "Search_Results" /></p> <p></ simple-method></p> <p></ simple-methods></p> <p>> ================================================================================================================================================================= ================ The above XML basically does not explain, defined</p> <p>CreateNewrecord</p> <p>UpdateRecord</p> <p>LookallRecords</p> <p>REMOVERECORD</p> <p>FINDRECORD</p> <p>These methods, and have inspections of user privileges, these methods correspond to several methods in the previous TestOfbiz.java,</p> <p>This way to do database operations is obviously much more simpler than writing Java programs.</p> <p>The following is also required to change the maping settings in Controller.xml (see the tutorial in front of the specific file).</p> <p>When you change the following, the configuration when using TestOfbiz.java, I have retained the way in the note:</p> <p>> ================================================================================================================================================================= ================</p> <p><request-map uri = "createtestform"></p> <p><Description> Show The Create Form </ description></p> <p><security https = "false" auth = "false" /></p> <p><Response name = "success" type = "view" value = "createtestform" /></p> <p></ request-map></p> <p><request-map uri = "listtest"></p> <p><Description> List All Records </ Description></p> <p><security https = "false" auth = "false" /></p> <p><event type = "simple" path = "COM / geeyo / offbiz / testofbizservices.xml" invoke = "lookRecords" /></p> <p><response name = "success" type = "view" value = "listalltest" /></p> <p></ request-map> <request-map uri = "showtest"></p> <p><Description> Show Records </ Description></p> <p><security https = "false" auth = "false" /></p> <p><event type = "simple" path = "COM / geeyo / offbiz / testofbizservices.xml" invoke = "findrecord" /></p> <p><Response name = "success" type = "view" value = "showtest" /></p> <p></ request-map></p> <p><request-map uri = "createtetest"></p> <p><security https = "true" auth = "true" /></p> <p><event type = "simple" path = "COM / geeyo / offbiz / testofbizservices.xml" invoke = "createNewrecord" /></p> <p><Response name = "success" type = "request" value = "listtest" /></p> <p><Response name = "error" type = "view" value = "createtestform" /></p> <p></ request-map></p> <p><request-map uri = "updatetest"></p> <p><Description> Update a Record </ description></p> <p><security https = "false" auth = "false" /></p> <p><event type = "simple" path = "com / geeyo / offbiz / testofbizservices.xml" invoke = "updateRecord" /></p> <p><Response name = "success" type = "request" value = "listtest" /></p> <p></ request-map></p> <p><request-map uri = "removetest"></p> <p><Description> Remove a Record </ description></p> <p><security https = "false" auth = "false" /></p> <p><event type = "simple" path = "COM / geeyo / offbiz / testofbizservices.xml" invoke = "removeRecord" /></p> <p><Response name = "success" type = "request" value = "listtest" /> </ request-map></p> <p><view-map name = "listalltest" type = "region" /></p> <p><view-map name = "createtestform" type = "region" /></p> <p><view-map name = "Testofbiz" type = "region" /></p> <p><view-map name = "showte" type = "region" /></p> <p>> ================================================================================================================================================================= ================</p> <p>Please refer to the tutorial in front of configuring this file, and regions.xml does not need to be changed.</p> <p>After configuring, please use the methods mentioned earlier: http: // localhost: 8080 / partymgr / control / listtest</p> <p>Now we can see that OFBIZ is very good in MVC, we can change the backend process from Java.</p> <p>Use XML control, while other parts (like JSP) do not need any changes, which guarantees independence of each part of our system.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-83635.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="83635" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.046</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '0TPnAi08CIOEY6Szlsos3HQTjYTH5YRxylr2jyEq_2BSrx9eYApiN_2FnLe0ntRmrrk7DTSaExQiRAENZDQi'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>