??xml version="1.0" encoding="utf-8" standalone="yes"?>伊人成年综合电影网,波多野结衣在线影院,国产伦精品一区二区三区视频免费
http://www.aygfsteel.com/liaojiyong/category/14093.htmlzh-cn Wed, 28 Feb 2007 06:49:24 GMT Wed, 28 Feb 2007 06:49:24 GMT 60 安装ofbiz+tomcat+oracle http://www.aygfsteel.com/liaojiyong/archive/2006/08/15/63641.htmlliaojiyong liaojiyong Tue, 15 Aug 2006 03:31:00 GMT http://www.aygfsteel.com/liaojiyong/archive/2006/08/15/63641.html http://www.aygfsteel.com/liaojiyong/comments/63641.html http://www.aygfsteel.com/liaojiyong/archive/2006/08/15/63641.html#Feedback 0 http://www.aygfsteel.com/liaojiyong/comments/commentRss/63641.html http://www.aygfsteel.com/liaojiyong/services/trackbacks/63641.html q个文章描述的是安装ofbiz在oracle+tomcat环境
ofbiz2.11提供的缺省的webserver是jetty,׃我比较习惯tomcatQ因此打把他{Udtomcat上来?
ofbiz2.11提供的却省的数据库是hsql的,用webtoolsQ{UM的数据库是非常方便的Q这里我介绍如何按装到oracle中,
同样的方法我也在mysql中测试通过了?
1。下载ofbiz2.11
可以通过www.ofbiz.org下蝲Q不q需要代理,也可以直接到http://sf.net上面查找ofbiz目下蝲?
2。下载tomcat
使用tomcat4.1.24,曄在网上看到过有h介绍tomcat.4.1.7之前的版本运行ofbizӞtaglib的处理非常慢Q?
之后的版本就没有q个问题了。tomcat可以到www.apache.org处下载?
3。安装oracle
理论上数据库可以是Q何支持jdbc的数据库Q我使用的是oracle8.17.
3.1建立oracle表空?
createtablespaceofbiz
datafile'd:\orant\oradata\ofbiz.dbf'size2m
autoextendonnext2mmaxsizeunlimited;
3.2建立用户
createuserofbiz
identifiedbyofbiz
defaulttablespaceofbiz;
grantconnect,resourcetoofbiz;
试用户
connectofbiz/ofbiz;
4。安装ofbiz
4.1讄环境变量
JAVA_HOME
ANT_HOME
CATALINA_HOME
OFBIZ_HOME
4.2自动安装
ofbiz已经准备了一个ant脚本Q它可以自动安装ofbiz到?
在OFBIZ_HOME中有一个build.xml,执行antinstall卛_?
但是q个自动脚本有的时候执行时会出错!如果出错Q请??手工安装?
4.3手工安装
4??
复制OFBIZ_HOME\commonapp\etc\目录下面的所有文件到CATALINA_HOME\share\classes中?
复制OFBIZ_HOME\commonapp\lib\目录?.jar到CATALINA_HOME\share\lib中?
复制OFBIZ_HOME\core\lib\目录?.jar到CATALINA_HOME\share\lib中?
复制OFBIZ_HOME\lib\目录?.jar到CATALINA_HOME\share\lib中?
注意OFBIZ_HOME\lib\中的jar文g是按目录分门别类存放的,复制到CATALINA_HOME\share\lib需要去掉所有目录,把所有jar都放到lib目录下?
4??
~辑CATALINA_HOME\share\classes\entityengine.xml
查找
helper-class="org.ofbiz.core.entity.GenericHelperDAO"
field-type-name="oracle"
check-on-start="true"
add-missing-on-start="true"
join-style="theta-oracle">
jdbc-driver="oracle.jdbc.driver.OracleDriver"
jdbc-uri="jdbc:oracle:thin:@127.0.0.1:1521:ofbiz"
jdbc-username="ofbiz"
jdbc-password="ofbiz"
isolation-level="ReadCommitted"/>
jdbc部分Ҏ对应的参数?
查找
Ҏ
4.3.3
复制OFBIZ_HOME\setup\catalina41\bin中的ofbiz.bat到CATALINA_HOME\bin?
复制OFBIZ_HOME\setup\catalina41\conf中的server.xml到CATALINA_HOME\conf?
注意Q这里的server.xml也可以不复制Q这里面是配置ofbiz的ContextQ手工更新到server.xml中即?
另外注意Qofbiz默认ofbiz和tomcat在一个目录下Q因此在server.xml中,他的context路径都是用的相对路径
例如
在OFBIZ_HOME\setup\catalina41\bin\runofbiz.bat
内容如下Q?
ofbiz.batrun
5.0q行runofbiz.bat
他首先调用ofbiz.bat讄环境变量Q然后启动tomcat.
启动tomcat的时候,ofbiz的DatabaseUtils会检查数据库中是否已l存在系l的表,没有׃自动创徏的,一般的创徏q程不会出错误的?
如果有错误生,请察看CATALINA_HOME\logs中的日志文gQ一般都是少某个jar,看到哪个到OFBIZ_HOME中找到后复制到CATALINA_HOME\share\lib?
6.0如果建立表都一切顺利就可以打开IEQ然后输入URL
http://localhost:8080/webtools/control/main
C要先用webtools导入数据Q否则你不能用admin/ofbiz登陆的!
在这里http://localhost:8080/webtools/control/install
直接点LoadData按钮
执行完毕?
到这?
http://localhost:8080/webtools/control/checkLogin/install
用admin/ofbiz登陆Q登陆成功证明安装完毕,不成功就察看一下日志文件?
???步中Q如果要安装到其他的数据库,可以修改其他数据库的jdbcq接配置Qofbiz为大部分支持jdbc的数据库提供的例子?
同样的方法也可以实施ofbiz到resin?不过没有试!:)
试环境
SERVER:PII300,512M
PIII733,256M
windows2000advanceserver
ofbiz2.11
oracle8.1.7
mysql4.0max
tomcat4.1.24
]]>ofbiz实体引擎l合jbuilder的配|?/title> http://www.aygfsteel.com/liaojiyong/archive/2006/08/15/63639.htmlliaojiyong liaojiyong Tue, 15 Aug 2006 03:29:00 GMT http://www.aygfsteel.com/liaojiyong/archive/2006/08/15/63639.html http://www.aygfsteel.com/liaojiyong/comments/63639.html http://www.aygfsteel.com/liaojiyong/archive/2006/08/15/63639.html#Feedback 0 http://www.aygfsteel.com/liaojiyong/comments/commentRss/63639.html http://www.aygfsteel.com/liaojiyong/services/trackbacks/63639.html q一节将l出实体引擎在jbuider中单独用的配置向导 本文是从ofbiz|站的(OFBiz Quick Start Guide by Brett G. PalmerQ的基础上完成配|?br /> 1Q从www.ofbiz.org中下载ofbiz-XX-XX-complete.zip包,本文用的是ofbiz-2.1.1-apps.zip 解开攑ֈ某个目录下,本文在j:\ofbiz,q也是ofbiz.home的?br />2Q徏立jbuilder目Q如下图所C?br /> 3Q加入源文gQ?br />ofbiz.home/core/src/entiry ofbiz.home/core/src/share 4Q加入所用到的jar文g ofbiz.home/lib/common ofbiz.home/lib/compile ofbiz.home/lib/jasterreports ofbiz.home/lib/jotm ofbiz.home/lib/scripting ofbiz.home/lib/share ofbiz.home/lib/tyrex 5Q将配置文g{导入工E?br />ofbiz.home/commonapp/etc下所有文件打到ofbiz_etc.jar包内 jar cvf ofbiz_etc.jar * ofbiz.home/core/docs/xmldefs/ofbiz下所有文件打到ofbiz_dtd.jar包内 jar cvf ofbiz_dtd.jar * 这两个包引入工E?br /> 6Q将ofbiz.home\setup\jrun4\servers\ofbiz\SERVER-INF\jndi.properties文g攑օ ofbiz.home\lib\jotm\jotm.jar包内 7Q配|ofbiz.home 在项目run tab中加入vm parameter: -Dofbiz.home=j:\ofbiz 8Q在GenericDelegator.java中,下面语句注释掉?br />/* // setup the Entity ECA Handler try { Class eecahClass = loader.loadClass(ECA_HANDLER_CLASS_NAME); this.entityEcaHandler = (EntityEcaHandler) eecahClass.newInstance(); this.entityEcaHandler.setDelegator(this); } catch (ClassNotFoundException e) { Debug.logWarning(e, "EntityEcaHandler class with name " + ECA_HANDLER_CLASS_NAME + " was not found, Entity ECA Rules will be disabled"); } catch (InstantiationException e) { Debug.logWarning(e, "EntityEcaHandler class with name " + ECA_HANDLER_CLASS_NAME + " could not be instantiated, Entity ECA Rules will be disabled"); } catch (IllegalAccessException e) { Debug.logWarning(e, "EntityEcaHandler class with name " + ECA_HANDLER_CLASS_NAME + " could not be accessed (illegal), Entity ECA Rules will be disabled"); } catch (ClassCastException e) { Debug.logWarning(e, "EntityEcaHandler class with name " + ECA_HANDLER_CLASS_NAME + " does not implement the EntityEcaHandler interface, Entity ECA Rules will be disabled"); } */ 9Q测试文件Test.java package org.ofbiz.core; import org.ofbiz.core.entity.GenericDelegator; import org.ofbiz.core.entity.GenericValue; import org.ofbiz.core.util.UtilMisc; import org.ofbiz.core.entity.*; public class Test { public static void main(String[] args) { System.out.println("Entered testFindByPrimaryKey"); //Instantiate the delegator. GenericDelegator delegator = GenericDelegator.getGenericDelegator("default"); // Find book by primary key try { GenericValue party= delegator.findByPrimaryKey("PartyType", UtilMisc.toMap("partyTypeId", "PERSON")); } catch (GenericEntityException ex1) { } return; } } 10.ok ]]> Ofbiz 入门教程(? http://www.aygfsteel.com/liaojiyong/archive/2006/08/15/63638.htmlliaojiyong liaojiyong Tue, 15 Aug 2006 03:25:00 GMT http://www.aygfsteel.com/liaojiyong/archive/2006/08/15/63638.html http://www.aygfsteel.com/liaojiyong/comments/63638.html http://www.aygfsteel.com/liaojiyong/archive/2006/08/15/63638.html#Feedback 0 http://www.aygfsteel.com/liaojiyong/comments/commentRss/63638.html http://www.aygfsteel.com/liaojiyong/services/trackbacks/63638.html 原创 Ofbiz 入门教程
1.Ofbiz 介绍Q?
Ofbiz(http://www.ofbiz.org) ?Open Source 的商务Y件系l,充分利用了各优秀的的Open Source 目Q?
?Tomcat, Ant, BeanShell, Jboss {,构徏了一个强大的pȝq_QOfbiz 已经完成了大部分商务cY件系l?
都需要的部gQ像用户认证、工作流、商务规则处理等QOfbiz 的核心技术在?Entity EngineQ其他的lg基本?
是基于它的。简单来?Entity Engine 的主要功能是数据库表创建、对象与数据表的映射、对象的查询{做了强?
装Q你可以在一个简单的 XML 文g中定义数据库表结构,Ofbiz 会自动帮你在数据库徏表,q动态生成映对象,
你在E序中可以只考虑?Object 的处理,Ofbiz 会自动通过事务逻辑更新到数据库中。Ofbiz 宣称的优点之一是用
很少?Code 完成复杂的处理?
2.Ofbiz 下蝲与安?
首先要安?J2SDK1.4Q到 http://java.sun.com 上下载,安装后设?JAVA_HOME 环境变量?J2SDK 的安装目录?
讉K|站 http://www.ofbiz.orgQ上面有下蝲的连接,请选择 Complete 包,因ؓq个包中已经包含了运?Ofbiz
的所有东西,下蝲下来解开后就可以q行了?
解开 Ofbiz 包到一个目录下Q假设是 “C:\ofbiz”,该目录下会?catalina ?ofbiz 两个目录Q?catalina
目录?Tomcat 的目录,Ofbiz 对其配置做了修改Qofbiz 目录?Ofbiz 的程序代码目录。在命o行状态下q入
“c:\ofbiz\catalina\bin?目录Q运行?ofbiz run”命令,可以启?OfbizQ启动后你可以用览器访?
“http://localhost:8080/ecommerce”,q可以访?Ofbiz 的电子商务模块,通过面上面的连接你可以讉K?
其他模块?
3.Ofbiz Schema 的创?
Ofbiz 应用入门Q?
以一个实例说明,假设我们需要徏一个客戯料表Qv名ؓ StudyCustomerQ各个段分别如下Q?
StudyCustomer {
customerId Integer,
customerName String,
customerNote String,
}
我们来实现基本的数据操作---???查询Q具体步骤如下:
1.?XML 文g中定义数?SchemaQ?
需要用C个文Ӟ一个是我们要徏的项目的 entitymodel_xxx.xml ?entityengine.xmlQ还?
entitygroup.xml,
entitymodel_xxx.xml 是需要我们自己创建的Q假设我们v名ؓ entitymodel_study.xmlQ放?
“c:\ofbiz\ofbiz\commonapp\entitydef”目录下Q?
entityengine.xml ?Ofbiz 已经有的Q放?“c:\ofbiz\commonapp\etc”目录下Q用来包含我?
定义?entitymodel 文g?
entitygroup.xml 也是 Ofbiz 已经有的Q跟 engityengine.xml 在同一目录下,我们需要把我们?
Schema 定义加入到该文g?
entitymodel_study.xml 文g的定义格式如下:
<!--================================================================================-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE entitymodel PUBLIC "-//OFBiz//DTD Entity Model//EN"
"http://www.ofbiz.org/dtds/entitymodel.dtd">
<entitymodel>
<title>Entity of an Open For Business Project Component</title>
<description>None</description>
<copyright>Copyright (c) 2002 The Open For Business Project - www.ofbiz.org</copyright>
<author>None</author>
<version>1.0</version>
<!-- ========================================================= -->
<!-- ======================== Data Model ===================== -->
<!-- The modules in this file are as follows: -->
<!-- - org.ofbiz.commonapp.study -->
<!-- ========================================================= -->
<!-- ========================================================= -->
<!-- org.ofbiz.commonapp.study -->
<!-- ========================================================= -->
<entity entity-name="StudyCustomer"
package-name="org.ofbiz.commonapp.study"
title="Study Customer Entity">
<field name="customerId" type="id-ne"></field>
<field name="customerName" type="long-varchar"></field>
<field name="customerNote" type="long-varchar"></field>
<prim-key field="customerId"/>
</entity>
</entitymodel>
<!--================================================================================-->
q个 XML 文g中的 Tag 基本是看得明白的Q只?field ?type ?Ofbiz 已经预定义好的,q?
是ؓ了保证数据库间的q移?
?entityengine.xml 加入我们刚才定义的文Ӟ加入一行在合适的位置Q?
<resource loader="mainfile" location="entitymodel_study.xml"/>
具体攄位置我们可以通过查看 entityengine.xml 扑ֈQ里面已l有加好的其他文件?
?entitygroup.xml 加入我们?Schema 定义Q在后面加入一?
<entity-group group="org.ofbiz.commonapp" entity="StudyCustomer" />
q样我们定义好?SchemaQ现在把 c:\ofbiz\commonapp\etc\entityengine.xml 拯?
c:\ofbiz\catalina\shared\classes 目录下,q点要切讎ͼ我以前就因ؓ没有拯Q最?Schema
怎么也创Z了?
重新启动 OfbizQ访?URL: http://localhost:8080/webtoolsQ点d上方?"Login" 链接Q?
?admin/ofbiz dQ登录进入后选择链接“Check/Update Database”,q时会出?Check ?FormQ?
该表单可以只?Schema 是否改变Q默认的 GroupName 是“org.ofbiz.commonapp”,q个不需要变Q?
点击“Check Only”按钮,Ofbiz 会检验变动情况,昄Z个完整的列表Q你可以查一下是否有我们刚徏?
"StudyCustomer"Q如果没有,可能是我们前面定义的有些问题Q检查一下再重新做?
在检查到以后Q可以再选择“Check and Add Missing”,q是 Ofbiz 很强大的一个功能,你在 XML 中新
增了表,或在某个表中新增了段Q它会自动映到数据库中Q避免我们去直接操作数据库?
现在已经完成?StudyCustomer Schema 的创?如果x验一下是否有表创建,我们可以用编辑器打开
c:\ofbiz\data\ofbiz.script Q在里面查询 CREATE TABLE StudyCustomer 的字P如果前面没有
问题Q我们可以找到的?
4.如何使用已经定义?Schema
如何使用已经定义?Schema
Ofbiz 遵@ MVC 的设计模式,?View 端,?JSP 端主要?Ofbiz 定义?Tag 来显C或
提取数据QControl 是一?Controller ServletQ我们在 Controller Servlet ?URI mapping
配置文g中定义各 URL 应该指向什么程序,q样Q通过q个 mapping 配置文gQ可以保证我们各个页?
及具体处理程序之间的独立性,例我们可以通过修改q个配置文g可以改变某?Form ?Post Action
?URLQ而不需要修改实际的 HTML ?JSP 代码?
Ofbiz 中定义了 Regions 的概念,卛_一?HTML 面分成几个区域Q像 Top, Left, Right, Main
{,通过q些 Regions 我们可以方便的组?UI 界面Qƈ且可以方便改变各部分所处的位置Q如我们可以
把菜单很Ҏ的从上方Ud下方Q只需要改变一个配|文件。Regions cM?HTML 中的 FrameQ但它是
通过一个页面来l合界面QFrame 是通过几个面昄在不同的帧中QFrame 的控制比较复杂,而且需?
改变相关的程序?
?Ofbiz 中,我们可以直接?JSP 中操?Schema 定义?ObjectQ即我们刚定义的 StudyCustomerQ?
CZ如下Q?
<%@ 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.*" %>
<jsp:useBean id="delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />
<jsp:useBean id="security" type="org.ofbiz.core.security.Security" scope="request" />
<%if(security.hasEntityPermission("PARTYMGR", "_VIEW", session)) {%>
<%
try {
delegator.create("StudyCustomer",
UtilMisc.toMap("customerId","1","customerName","Cust1","customerNote","Customer Note 1"));
Iterator custs =
UtilMisc.toIterator(delegator.findAll("StudyCustomer",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{%>
<h3>You do not have permission to view this page. ("PARTYMGR_VIEW" or "PARTYMGR_ADMIN" needed)</h3>
<%}%>
q段E序挺容易理解,先是通过 delegator 创徏一?ObjectQ该 Object 会?Ofbiz 自动同步?
数据库中。然后通过 delegator ?findAll 取到所有已保存?ObjectQ最后通过一?Iterator 对象
昄出来?
q个E序起名?testofbiz.jspQؓ单v见,我们攑ֈ Ofbiz 已有的一?Webapp 的目录下Q放?
c:\ofbiz\ofbiz\partymgr\webapp\party 目录下。然后我们需要修改两个配|文Ӟcontroller.xml
?regions.xmlQ这两个文g是我们上面提到?mapping ?regions 配置文g?
q两个文仉在:c:\ofbiz\ofbiz\partymgr\webapp\WEB-INF 下,?controller.xml 中加入下?
<request-map uri="testofbiz">
<description>Test Ofbiz</description>
<security https="false" auth="false"/>
<response name="success" type="view" value="testofbiz"/>
</request-map>
?
<view-map name="testofbiz" type="region"/>
加入位置请参?controller.xml 中已l有的配|。在 regions.xml 中加入:
<define id='testofbiz' region='MAIN_REGION'>
<put section='title'>Test Ofbiz</put>
<put section='content' content='/party/testofbiz.jsp'/>
</define>
具体加入位置请参考已有的配置?
配置完后Q重新启?ofbizQ然后访?URL:
http://localhost:8080/partymgr/control/testofbiz
׃我们?testofbiz.jsp E序中用了 Ofbiz 的安全控制机Ӟpȝ会提C现在没有访?
权限Q需要登录,点击双的“Login??admin/ofbiz d后会看到我们E序 testofbiz.jsp
的运行结果。如果需要增加新记录Q请修改
UtilMisc.toMap("customerId","1","customerName","Cust1","customerNote","Customer Note 1"));
中的各个D늚|然后再访?http://localhost:8080/partymgr/control/testofbizQ如果不修改
而直接访问那?URL Ӟpȝ会提C?Primary key 冲突?
5.按照昄与逻辑分离的原则?Schema:
上篇讲了如何?JSP 中用创建的 Schema 对象Q这ơ我们来讲述一下如何把E序
逻辑攑ֈ JavaBeans 中,把显C处理放?JSP 中,q?controller.xml 两
部分整合h?
首先我们来创Z?JavaBeansQ来完成Add/Get/Delete/Update Schema 对象
的操作,E序文g名ؓ TestOfbiz.javaQ放|在
c:\ofbiz\ofbiz\testOfbiz\com\geeyo\ofbiz 目录? 具体E序如下Q?
>=================================================================
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().setAttribute("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";
}
}
>=================================================================
E序中的处理大部分可以看懂的Q其中有个功能,?
Map paras = UtilMisc.getParameterMap(request);
q是 Ofbiz 的一个有但非常有用的功能,它是?request 中各D늚名字和值映到一?Map
对象中,然后使用
cust.setNonPKFields(paras);
可以赋l?Object cust 的各个段Q免了我们?request.getParameter("name")来取各个
|在值很多的时候这个功能可以大大减冗余代码量?
基本E序的逻辑是这LQ?
1.?request d传来的?
?2.使用 delegator 来处理,Add/Update/Delete/Query
3.返回结果放?Session 中传l?JSP
我做了个 Ant build.xml 文g可以帮助~译Q把q个文g攑֜:
c:\ofbiz\ofbiz\testOfbiz\ 目录下,然后在命令行H口下进入该目录Q敲?ant
来编译(需要保证已l安?AntQ,~译后的 .class 会放?
c:\ofbiz\ofbiz\testOfbiz\com\geeyo\ofbiz 下,
拯 c:\ofbiz\ofbiz\testofbiz\com 目录?c:\ofbiz\ofbiz\partymgr\webapp\WEB-INF\classes
目录下?
build.xml
>=============================================================================
<project name="TestOfbiz" default="dist" basedir=".">
<description>
Test ofbiz
</description>
<!--test cvs-->
<!-- set global properties for this build -->
<property name="src" location="."/>
<property name="build" location="."/>
<property name="lib_dir" location="c:/ofbiz/catalina/shared/lib"/>
<property name="lib1_dir" location="c:/ofbiz/catalina/common/lib"/>
<path id="project.class.path">
<fileset dir="${lib_dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${lib1_dir}">
<include name="*.jar"/>
</fileset>
</path>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}">
<classpath refid="project.class.path"/>
</javac>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
</target>
</project>
>=============================================================================
然后我们来创?JSP E序QJSP E序全部攑֜
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.*" %>
<jsp:useBean id="security" type="org.ofbiz.core.security.Security" scope="request" />
<jsp:useBean id="delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />
<script language="JavaScript">
function confirmDelete()
{
return confirm("Are your sure to delete?");
}
</script>
<%if(security.hasEntityPermission("PARTYMGR", "_VIEW", session)) {%>
<table width="600" align="center">
<ofbiz:if name="search_results">
<tr><th>Id</th><th>Name</th><th>Note</th><th></th></tr>
<ofbiz:iterator name="cust" property="search_results">
<tr>
<td><ofbiz:entityfield attribute="cust" field="customerId"/></td>
<td><ofbiz:entityfield attribute="cust" field="customerName"/></td>
<td><ofbiz:entityfield attribute="cust" field="customerNote"/></td>
<td>
<a href='<ofbiz:url>/showtest?customerId=<ofbiz:entityfield attribute="cust" field="customerId"/></ofbiz:url>' class="buttontext">[Edit]</a>
<a href='<ofbiz:url>/removetest?customerId=<ofbiz:entityfield attribute="cust" field="customerId"/></ofbiz:url>' class="buttontext" onclick="return confirmDelete()">[Remove]</a>
</td>
</tr>
</ofbiz:iterator>
</ofbiz:if>
</table>
<table width="200" align="center">
<tr>
<td><a href='<ofbiz:url>/createTestForm</ofbiz:url>'>Create customer</a></td>
</tr>
</table>
<%}else{%>
<h3>You do not have permission to view this page. ("PARTYMGR_VIEW" or "PARTYMGR_ADMIN" needed)</h3>
<%}%>
>=============================================================================
上面E序中需要说明的?
<ofbiz:if name="search_results">
?
<ofbiz:iterator name="cust" property="search_results">Q?
<ofbiz:if name="search_results"> 是用来检验在 session ?pageContext 对象
中是否包?search_results 对象Q该对象是由我们的程序放?session 中的?
<ofbiz:iterator name="cust" property="search_results"> 是用来@环读取对?
search_resultsQ是?Collection 对象Q中存储的各对象Qƈ赋给custQ然后在循环?
中,我们可以用 cust 对象来读取各个段的g?
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.*" %>
<jsp:useBean id="security" type="org.ofbiz.core.security.Security" scope="request" />
<jsp:useBean id="delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />
<%if(security.hasEntityPermission("PARTYMGR", "_VIEW", session)) {%>
<form method="post" action="<ofbiz:url>/createTest</ofbiz:url>" name="createofbiz">
<table width="300" align="center">
<tr>
<td>Id</td><td><input type="text" name="customerId" size="20"></td>
</tr>
<tr>
<td>Name</td><td><input type="text" name="customerName" size="20"></td>
</tr>
<tr>
<td>Note</td><td><input type="text" name="customerNote" size="30"></td>
</tr>
<tr>
<td></td>
<td><input type="submit"></td>
</tr>
</table>
</form>
<%}else{%>
<h3>You do not have permission to view this page. ("PARTYMGR_VIEW" or "PARTYMGR_ADMIN" needed)</h3>
<%}%>
>=============================================================================
q个E序很容易理解,需要注意的是每个文本框的名字,要跟 Schema StudyCustomer 的各
个段一_以ɽE序中跟Ҏ处理?
3.showofbiz.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.*" %>
<jsp:useBean id="security" type="org.ofbiz.core.security.Security" scope="request" />
<jsp:useBean id="delegator" type="org.ofbiz.core.entity.GenericDelegator" scope="request" />
<%if(security.hasEntityPermission("PARTYMGR", "_VIEW", session)) {%>
<form method="post" action="<ofbiz:url>/updateTest</ofbiz:url>" name="updateofbiz">
<table width="300" align="center">
<tr>
<td>Id</td><td><input type="text" name="customerId" size="20" value="<ofbiz:entityfield attribute="edit_cust" field="customerId"/>"></td>
</tr>
<tr>
<td>Name</td><td><input type="text" name="customerName" size="20" value="<ofbiz:entityfield attribute="edit_cust" field="customerName"/>"></td>
</tr>
<tr>
<td>Note</td><td><input type="text" name="customerNote" size="30" value="<ofbiz:entityfield attribute="edit_cust" field="customerNote"/>"></td>
</tr>
<tr>
<td></td>
<td><input type="submit"></td>
</tr>
</table>
</form>
<%}else{%>
<h3>You do not have permission to view this page. ("PARTYMGR_VIEW" or "PARTYMGR_ADMIN" needed)</h3>
<%}%>
>=============================================================================
q个E序中,主要是通过
<ofbiz:entityfield attribute="edit_cust" field="customerId"/>
把取到的对象的段昄出来, 对象 edit_cust 是我们在E序中取到ƈ攑ֈ session 中的?
下面我们来配|?controller.xml ?regions.xml, ?controller.xml 中加?
>=============================================================================
<request-map uri="createTestForm">
<description>Show the create form</description>
<security https="false" auth="false"/>
<response name="success" type="view" value="createTestForm"/>
</request-map>
<request-map uri="testofbiz">
<description>Test Ofbiz</description>
<security https="false" auth="false"/>
<response name="success" type="view" value="testofbiz"/>
</request-map>
<request-map uri="listtest">
<description>List all records</description>
<security https="false" auth="false"/>
<event type="java" path="com.geeyo.ofbiz.TestOfbiz" invoke="lookAllRecords" />
<response name="success" type="view" value="listAllTest"/>
</request-map>
<request-map uri="showtest">
<description>Show records</description>
<security https="false" auth="false"/>
<event type="java" path="com.geeyo.ofbiz.TestOfbiz" invoke="findRecord" />
<response name="success" type="view" value="showTest"/>
</request-map>
<request-map uri="createTest">
<security https="true" auth="true"/>
<event type="java" path="com.geeyo.ofbiz.TestOfbiz" invoke="createNewRecord"/>
<response name="success" type="request" value="listtest"/>
<response name="error" type="view" value="createTestForm"/>
</request-map>
<request-map uri="updateTest">
<description>update a record</description>
<security https="false" auth="false"/>
<event type="java" path="com.geeyo.ofbiz.TestOfbiz" invoke="updateRecord" />
<response name="success" type="request" value="listtest"/>
</request-map>
<request-map uri="removetest">
<description>remove a record</description>
<security https="false" auth="false"/>
<event type="java" path="com.geeyo.ofbiz.TestOfbiz" invoke="removeRecord" />
<response name="success" type="request" value="listtest"/>
</request-map>
<view-map name="listAllTest" type="region"/>
<view-map name="createTestForm" type="region"/>
<view-map name="showTest" type="region"/>
>=============================================================================
?regions.xml 中加入:
>=============================================================================
<define id='createTestForm' region='MAIN_REGION'>
<put section='title'>Create Ofbiz</put>
<put section='content' content='/party/createofbiz.jsp'/>
</define>
<define id='listAllTest' region='MAIN_REGION'>
<put section='title'>List Ofbiz</put>
<put section='content' content='/party/listofbiz.jsp'/>
</define>
<define id='showTest' region='MAIN_REGION'>
<put section='title'>Show Ofbiz</put>
<put section='content' content='/party/showofbiz.jsp'/>
</define>
>=============================================================================
现在完成了Q我们重新启?OfbizQ然后用 IE 讉KQ?
http://localhost:8080/partymgr/control/listtestQ用admin/ofbiz d后就可以
看到我们刚才的工作成果了Q你现在可以增加/删除/修改记录?
6.Ofbiz 通过 XML 来完成数据库操作Q非常强大的功能Q?
q是 Ofbiz 的一个非常强大的功能Q可能通过单的 XML 文g来完成数据增/?改的处理Q?
q些处理在数据库应用中是非常多的Q因为很多需要维护的数据Q所以写E序也是最花时间的Q?
Ofbiz 把这些操作通过 XML 来完成,不能不说是一大革?--使我们不用写E序可以完成大
部分处理Q这是每个程序员都向往的终极目标?
我们下面举例来讲qC下,处理的数据还是利用我们前面创建的 StudyCustomerQ?XML
配置文g来完成前面程?TestOfbiz.java 的大部分操作?
?c:\ofbiz\ofbiz\testOfbiz\com\geeyo\ofbiz 目录下创建文?TestOfbizServices.xmlQ?
该文件的内容如下Q?
>=================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE simple-methods PUBLIC "-//OFBiz//DTD Simple Methods//EN" "http://www.ofbiz.org/dtds/simple-methods.dtd">
<simple-methods>
<!-- TestOfbiz methods -->
<simple-method method-name="createNewRecord" short-description="Create a new record">
<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"/>
<set-pk-fields map-name="parameters" value-name="newEntity"/>
<set-nonpk-fields map-name="parameters" value-name="newEntity"/>
<create-value value-name="newEntity"/>
</simple-method>
<simple-method method-name="updateRecord" short-description="Update a record">
<check-permission permission="STUDYCUSTOMER" action="_UPDATE"><fail-message message="Security Error: to run updateRecord you must have the STUDYCUSTOMER_UPDATE permission"/></check-permission>
<check-errors/>
<make-value entity-name="StudyCustomer" value-name="lookupPKMap"/>
<set-pk-fields map-name="parameters" value-name="lookupPKMap"/>
<find-by-primary-key entity-name="StudyCustomer" map-name="lookupPKMap" value-name="lookedUpValue"/>
<set-nonpk-fields map-name="parameters" value-name="lookedUpValue"/>
<store-value value-name="lookedUpValue"/>
</simple-method>
<simple-method method-name="findRecord" short-description="lookup a record">
<check-errors/>
<make-value entity-name="StudyCustomer" value-name="lookupPKMap"/>
<set-pk-fields map-name="parameters" value-name="lookupPKMap"/>
<find-by-primary-key entity-name="StudyCustomer" map-name="lookupPKMap" value-name="edit_cust"/>
<field-to-session field-name="edit_cust"/>
</simple-method>
<simple-method method-name="removeRecord" short-description="Delete a record">
<check-permission permission="STUDYCUSTOMER" action="_DELETE"><fail-message message="Security Error: to run deleteRecord you must have the STUDYCUSTOMER_DELETE permission"/></check-permission>
<check-errors/>
<make-value entity-name="StudyCustomer" value-name="lookupPKMap"/>
<set-pk-fields map-name="parameters" value-name="lookupPKMap"/>
<find-by-primary-key entity-name="StudyCustomer" map-name="lookupPKMap" value-name="lookedUpValue"/>
<remove-value value-name="lookedUpValue"/>
</simple-method>
<simple-method method-name="lookAllRecords" short-description="lookup suitable records">
<check-errors/>
<find-by-and entity-name="StudyCustomer" list-name="search_results"/>
<field-to-session field-name="search_results"/>
</simple-method>
</simple-methods>
>=================================================================
上面?XML 基本是不用解释的Q定义了
createNewRecord
updateRecord
lookAllRecords
removeRecord
findRecord
q几个方法,而且都有对用h限的查,q几个方法对应于前面 TestOfbiz.java 中的几个ҎQ?
q样来做数据库操作显然比?Java E序写要单得多,
下面q需要在 controller.xmlQ具体文件得位置请参照前面的教程Q更改一?mapping 的设|,
更改如下Q以前?TestOfbiz.java 时的配置我以注释的方式保留着以做参照Q?
>=================================================================
<request-map uri="createTestForm">
<description>Show the create form</description>
<security https="false" auth="false"/>
<response name="success" type="view" value="createTestForm"/>
</request-map>
<request-map uri="listtest">
<description>List all records</description>
<security https="false" auth="false"/>
<event type="simple" path="com/geeyo/ofbiz/TestOfbizServices.xml" invoke="lookAllRecords" />
<response name="success" type="view" value="listAllTest"/>
</request-map>
<request-map uri="showtest">
<description>Show records</description>
<security https="false" auth="false"/>
<event type="simple" path="com/geeyo/ofbiz/TestOfbizServices.xml" invoke="findRecord" />
<response name="success" type="view" value="showTest"/>
</request-map>
<request-map uri="createTest">
<security https="true" auth="true"/>
<event type="simple" path="com/geeyo/ofbiz/TestOfbizServices.xml" invoke="createNewRecord"/>
<response name="success" type="request" value="listtest"/>
<response name="error" type="view" value="createTestForm"/>
</request-map>
<request-map uri="updateTest">
<description>update a record</description>
<security https="false" auth="false"/>
<event type="simple" path="com/geeyo/ofbiz/TestOfbizServices.xml" invoke="updateRecord" />
<response name="success" type="request" value="listtest"/>
</request-map>
<request-map uri="removetest">
<description>remove a record</description>
<security https="false" auth="false"/>
<event type="simple" path="com/geeyo/ofbiz/TestOfbizServices.xml" invoke="removeRecord" />
<response name="success" type="request" value="listtest"/>
</request-map>
<view-map name="listAllTest" type="region"/>
<view-map name="createTestForm" type="region"/>
<view-map name="testofbiz" type="region"/>
<view-map name="showTest" type="region"/>
>=================================================================
配置该文件的Ҏ请参照前面的教程Qregions.xml 不需改动?
配置完后L前面讲过的方法访?URL: http://localhost:8080/partymgr/control/listtest
现在我们可以看到QOfbiz ?MVC 斚w做得非常好,我们可以把后端的处理E序?java ?
成用 XMl 控制Q而其他部分(?JSPQ不需M改动Q这可以保证我们pȝ各部分的独立性?
]]>
վ֩ģ壺
ˮ |
ɽ |
|
|
|
ɽ |
|
|
|
|
|
|
ɽ |
̨ǰ |
¤ |
齭 |
|
Ǩ |
|
|
|
ƽ |
ʲ |
ǿ |
|
|
|
Դ |
̫ |
|
ͤ |
ˮ |
|
ˮ |
Ӫɽ |
|
Ͼ |
˶ |
|
|
|