您的位置:首页 > 其它

OFBiz 快速入门——续二

2011-05-27 15:36 190 查看
OFBiz 快速入门——续二

2011年03月17日 星期四 00:03

OFBiz 快速入门
2.5 创建一个文件,取名为(controller.xml),被OFBiz webapp控制器使用的。在没有额外增加功能时,这个文件内容非常的小与简单,如下:
<?xml version="1.0" encoding="UTF-8"?>
<site-conf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/site-conf.xsd">
<include
location="component://common/webcommon/WEB-INF/common-controller.xml"/>
<description>Practice Component Site Configuration File</description>
<owner>Copyright 2001-2009 The Apache Software Foundation</owner>
<handler name="screen" type="view"
class="org.ofbiz.widget.screen.ScreenWidgetViewHandler"/>
<!-- Request Mappings -->
<request-map uri="main">
<security https="false" auth="false"/>
<response name="success" type="view" value="main"/>
</request-map>
<!-- end of request mappings -->
<!-- View Mappings -->
<view-map name="main" type="screen"
page="component://practice/widget/PracticeScreens.xml#main"/>
<!-- end of view mappings -->
</site-conf>

2.6 回到上一级目录,创建一个(error)目录,
完整路径是(hot-deploy/practice/webapp/practice/error)
2.6.1 在(error)目录中创建一个(error.jsp)文件。文件的内容,可以从 example或其他的组件拷贝过来。
这个目录结构,就是你在上一步骤中在controller.xml文件中的<errorpage>/error/error.jsp</errorpage>的位置。你会需要用到这个目录去显示一个错误信息给用户。内容如下(省去一些HTML代码,只贴出与OFBiz有关的,详细的请自己浏览):
<%@ page import="org.ofbiz.base.util.*" %>
先获得request中的错误信息,并保存在一个errorMsg的变量中
<% String errorMsg = (String) request.getAttribute("_ERROR_MESSAGE_"); %>
最后,在HTML页面中某处合适的位置,输出其错误信息:
<%=UtilFormatOut.replaceString(errorMsg, "\n", "<br/>")%>

2.7 在组件目录(practice)中创建目录,命名为(widget),完整路径是,(hot-deploy/practice/widget)。这个目录的作用,包含你应用将要创建的UI,有forms、menus和screens等。

2.8 在(widget)目录中创建一个命名为(PracticeScreens.xml)的文件。类似地,其文件内容也可以从Example组件中获取并拷贝到这文件中。
在创建Views前,推荐你先去阅读以下有关内容(注意,这个是告诉我自己要去阅读的)
² HTML and CSS Best Practice
² Managing Your Source Differences
² Methodology Recommendations
² User Interface Layout Best Practices
阅读以上文档后,会对你产生莫大的帮助,但在这里,可以先使用下面的代码:
<?xml version="1.0" encoding="UTF-8"?>

3ff0
<screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation
="http://ofbiz.apache.org/dtds/widget-screen.xsd">
<screen name="main">
<section>
<widgets>
<label text="This is first practice"/>
</widgets>
</section>
</screen>
</screens>

2.9 完成了一个基本应用(practice)。首先,客户端的一个request会去查看一个特定的资源,举个例子:localhost:8080/practice/cntrol/main。

当OFBiz接收到这个请求,就会查看/practice这个项。为什么呢?因为我们在ofbiz-component.xml已经声明webapps加载点是/practice。现在OFBiz知道处理(practice)组件请求的剩余部分了。
经历了OFBiz在ofbiz-component.xml查找到挂载点(/practice)后,OFBiz这时将会查看controller.xml文件。这个文件里,我们已经定义了request-maps和view-maps。如果找到request-map是路径后面的(main),就会使用相关联的view-map,其他也如此。在request-map中,能或者指定一个view或者是一个事件或一个服务这都将会在后面所见到的。如果指定的是一个view,就会进一步查看request-map元素中查找到指定的名称并返回。看如下xml内容:
<request-map uri="main">
<security https="false" auth="false"/>
<response name="success" type="view" value="main"/>
</request-map>
<view-map name="main" type="screen"
page="component://practice/widget/PracticeScreens.xml#main"/>
在这里就可很清楚的知道,如果uri是main的时候,就会在request-map标签中进行下一步的查找,如果是success时,就会得到一个类型为view值为main的返回。那么,OFBiz就会索引到view-map中与其(main)值相等的标签。跟着,就会在PracticeScreens.xml文件中读取元素名为main的内容(#)
最后,就可以启动OFBiz,在浏览器中输入以下的URL:
http://localhost:8080/practice/control/main

2.11 在webapp(practice)目录创建一个名为(index.jsp)的文件。当然,类似地,其文件内容也可以从Example组件中拷贝过来。这个文件的作用是为了响应如下的URL的http://localhost:8080/practice/。如果你给了一个错误的URL,如http://localhost:8080/practice/unknown/request将会重定向到在web.xml定义好的redirectPath中的文件路径。
In the case, ContextFilter will filter out the request and use the redirect path to redirect the request.

第二部分
3.做进一步的一些操作
待续待续ing

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: