解剖Petstore用户资料修改流程

update_customer.screen

查找screendefinitions_en_US.xml
由于petsotre的界面使用了一个模板taglib,这个模板将屏幕分成:
title 标题
banner 广告
sidebar 菜单边
body 正文
mylist 特殊显示
footer 页脚
这个思路可以借鉴到我们系统中。
从其中找到update_customer.screen的真正程序名是:
<parameter key="body" value="/edit_customer.jsp" />
也就是是edit_customer.jsp

打开edit_customer.jsp 发现其form action又是自己定义的,
action="customer.do"
也就是说update_customer.screen页面是提交到customer.do程序的。

再查询customer.do是什么?

在mappings.xml中查询到:
<url-mapping url="customer.do" screen="customer.screen" >
<web-action-class>com.sun.j2ee.blueprints.petstore.controller.web.actions.CustomerHTMLAction</web-action-class>
</url-mapping>
customer.do实际是com.sun.j2ee.blueprints.petstore.controller.web.actions.CustomerHTMLAction这个servlet
那么打开com.sun.j2ee.blueprints.petstore.controller.web.actions.CustomerHTMLAction:

这个servlet主要是处理update_customer.screen提交form中的参数,
ContactInfo info = extractContactInfo(request, "_a");
CreditCard creditCard = extractCreditCard(request);
ProfileInfo profileInfo = extractProfileInfo(request);
将这些从前台用户那里输入的新数据打包在一个叫CustomerEvent类中:
event = new CustomerEvent(CustomerEvent.UPDATE, info, profileInfo, creditCard);

这个CustomerEvent很重要,是承接前台和后台EJB处理的中间枢纽。

从mappings.xml可以查询到:
<event-mapping>
<event-class>com.sun.j2ee.blueprints.petstore.controller.events.CustomerEvent</event-class>
<ejb-action-class>com.sun.j2ee.blueprints.petstore.controller.ejb.actions.CustomerEJBAction</ejb-action-class>
</event-mapping>
CustomerEvent实际是激活 CustomerEJBAction.

打开CustomerEJBAction,我们发现了updateCustomer(CustomerEvent ce)
这个方法将前台用户的新数据set到EJB中。
CustomerEJBAction也并不是直接和entity bean打交道,而是通过ShoppingClientFacadeLocalEJB
这是个Facade模式。

下次我们讨论MainServlet
这个MainServlet实际上是petstore MVC的总controller,但是它和具体数据又没有关系,上面的customer.do实际是通过MainServlet激活的。

update_customer.screen在http://deployathon.trifork.com:8080/petstore/update_customer.screen

理解了Struts,对上面pet store这些门槛都一样理解。

看了半天,总算明白点,底子薄啊
用户资料修改的CustomerHTMLAction相当于struts里的Action类,逻辑名custom,按照斑竹所介绍,CustomerEvent为ActionForm,收集前台信息。至于后台的EJB,个人认为如果把bean换成ejb,也就相当于加了ejb层,就象<web-action-class>和<ejb-action-class>,所以这已经不是struts所能解决的,只不过在web层有struts的影子

什么鸟话?

这处流程是SUN提供的一个Framework:WAF(Web Application Framework)

请问一下,可否有在jboss环境下配置petstore的文档,谢谢!

真希望看到全部的解释

能少走很多弯路 啊

banq


:)

看不出SUN的Framework:WAF
与apche struts的区别

请高手指教

TO: salmongq

SUN 的 Framework 是 JATO,不是 WAF.
WAF 只是演示目的,商用的是 JATO

还是打不开呀.

做B/S的应用一年多了,
感觉也没什么复杂的

就是技术太多,
而且很多是相似的
无论是在web层上
还是在持久层上

在web层上而言,
java application基本都是MVC结构
虽然出了很多的framework但其本质还是MVC
不过是白骨精变了脸
只要搞懂了servlet jsp JNDI javabean 和OO
能够分析XML文档
甚至你可以自己写一个framework
叫aaaa

但是不一定有struts等的移植性好
效率高
更何况又出现了很多的辅助技术来帮助你使用struts呢?


搞定了web层
业务层技术要求不是很强
剩下的就是持久层了

有很多 EJB JDO hibernate
EJB 如果懂点J2EE的话,就应该不是问题,EJB是核心
虽然类比较多
如果使用辅助工具的话
也很容易
自己也可以写一个代码生成工具(生成接口和实现类)
有了这些东西之后,基本是纯粹的J2SE的东西
最好能掌握EQL

hibernate
尤其是出现了xdoclet后,
是非常方便也非常简单的。

有了这些后
再来一个service/业务层也好,什么层都行,作为业务的处理
那么这三层结构就出现了