解剖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激活的。