• 大小: 1.67MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-31
  • 语言: 其他
  • 标签: jsf  

资源简介

JSF实例学习--比萨(pizza)订购系统

资源截图

代码片段和文件信息

package pizzaria;

import java.util.Map;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import javax.faces.component.UICommand;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import javax.servlet.ServletContext;


public class AppActionListener implements ActionListener {

  public void processAction(ActionEvent event) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    String localValue = (String) ((UICommand) event.getComponent()).getValue();

    if (“Buy“.equals(localValue)) {
      String productId = (String)
        facesContext.getExternalContext().getRequestParameterMap().get(“myForm:productId“);
      Map sessionMap = facesContext.getExternalContext().getSessionMap();
      ShoppingCartBean cart = (ShoppingCartBean) sessionMap.get(“shoppingCartBean“);
      if (cart==null) {
        cart = new ShoppingCartBean();
        sessionMap.put(“shoppingCartBean“ cart);
      }
      
      ProductBean product = getDatabaseUtil().getProductDetails(productId);
      ShoppingItemBean shoppingItem = new
        ShoppingItemBean(product.getId() product.getName() product.getPrice() 1);
      cart.addShoppingItem(shoppingItem);
    }
    else if (“Pay“.equals(localValue)) {
      // insert a record into the database

      OrderBean order = (OrderBean) getValueBinding(“#{orderBean}“).getValue(facesContext);
      ShoppingCartBean cart = (ShoppingCartBean) 
        getValueBinding(“#{shoppingCartBean}“).getValue(facesContext);
      if (cart!=null && order!=null) {
        getDatabaseUtil().insertOrder(order cart);
        // empty shopping cart
        cart.removeShoppingItems();
      }

    }

  }

  private ValueBinding getValueBinding(String valueRef) {
    ApplicationFactory factory =
(ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
    Application application = factory.getApplication();
    return application.createValueBinding(valueRef);
  }

  private DatabaseUtil getDatabaseUtil() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ServletContext servletContext = (ServletContext)
facesContext.getExternalContext().getContext();
    return (DatabaseUtil) servletContext.getAttribute(“DATAbase_UTIL“);
  }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2005-07-29 13:57  pizza\
     文件         307  2005-05-27 22:20  pizza\test.jsp
     文件        1330  2005-05-27 22:56  pizza\index.jsp
     文件        2190  2004-01-03 18:20  pizza\styles.css
     文件          80  2004-01-01 11:45  pizza\footer.jsp
     文件         651  2005-05-27 22:50  pizza\menu.jsp
     文件         321  2005-05-27 22:30  pizza\header.jsp
     文件        1473  2005-05-28 11:31  pizza\details.jsp
     文件        2316  2005-05-28 21:34  pizza\checkOut.jsp
     文件        1089  2005-05-29 08:06  pizza\order.jsp
     文件        1915  2005-05-29 08:03  pizza\shoppingCart.jsp
     目录           0  2005-07-29 13:57  pizza\WEB-INF\
     文件        1713  2005-05-27 11:10  pizza\WEB-INF\faces-config.xml
     文件        1385  2005-05-27 11:09  pizza\WEB-INF\web.xml
     文件      237568  2005-07-30 14:19  pizza\WEB-INF\pizzaria.mdb
     文件        1473  2003-12-08 21:05  pizza\WEB-INF\pizzaria-oracle.sql
     目录           0  2005-07-29 13:57  pizza\WEB-INF\classes\
     目录           0  2005-07-29 13:57  pizza\WEB-INF\classes\pizzaria\
     文件        2775  2005-05-28 14:22  pizza\WEB-INF\classes\pizzaria\AppActionListener.class
     文件        1109  2005-05-28 14:22  pizza\WEB-INF\classes\pizzaria\AppContextListener.class
     文件        4155  2005-05-28 14:22  pizza\WEB-INF\classes\pizzaria\DatabaseUtil.class
     文件        1742  2005-05-28 14:22  pizza\WEB-INF\classes\pizzaria\MenuBean.class
     文件        1121  2005-05-28 14:22  pizza\WEB-INF\classes\pizzaria\OrderBean.class
     文件        1983  2005-05-28 14:22  pizza\WEB-INF\classes\pizzaria\ProductBean.class
     文件         656  2005-05-28 14:22  pizza\WEB-INF\classes\pizzaria\ProductSummary.class
     文件        1116  2005-05-28 14:22  pizza\WEB-INF\classes\pizzaria\ShoppingCartBean.class
     文件         997  2005-05-28 14:22  pizza\WEB-INF\classes\pizzaria\ShoppingItemBean.class
     文件         796  2005-05-09 10:09  pizza\WEB-INF\classes\pizzaria\messages.properties
     文件        1266  2005-05-27 21:50  pizza\WEB-INF\classes\pizzaria\MenuBean.java
     文件        1183  2004-01-03 19:06  pizza\WEB-INF\classes\pizzaria\OrderBean.java
     文件        1850  2004-01-02 13:13  pizza\WEB-INF\classes\pizzaria\ProductBean.java
............此处省略36个文件信息

评论

共有 条评论