Package com.ateam.webstore.ui.forms

Examples of com.ateam.webstore.ui.forms.FormSubmission


   * @param prodId
   * @return
   */
  public FormSubmission addProduct(String prodId) {
   
    FormSubmission add = new FormSubmission();
   
    if (prodId == null) {
      prodId = req.getParameter(Parameters.PRODUCT_ID.getId());
    }
   
    req.getSession().setAttribute(SESSION_ATTRIBUTE_PRODUCT_TO_WISHLIST, prodId);
   
    //Check auth
    Visitor v = (Visitor) req.getSession().getAttribute(SESSION_ATTRIBUTE_VISITOR);
    if (v == null || !v.isAuthenticated()) {
      l.info("not authenticated for product add ");
      CustomerHandler ch = new CustomerHandler(req);
      add.setResultView(ch.getLoginView("Please first login"));
      return add;
    }
   
    WishList wl = getWishList();
    if (wl == null) {
      wl = new WishList(v.getCustomer());
      wl.setName("My Wish List");
      wl = service.store(wl);
    }
   
    l.fine("adding prodId :"+prodId);

    ProductsInWishList prodInList = new ProductsInWishList(1, wl,new ProductService().getById(new Long(prodId)));
    wl.addProduct(prodInList);
    service.store(wl);

    add.setResultView(getWishListView());
   
    return add;
  }
View Full Code Here


  public FormSubmission moveSelectedToCart() {

    WishList wl = getWishList();
    CartHandler ch = new CartHandler(req);
    ProductsInWishListService pinwl = new ProductsInWishListService();
    FormSubmission fs = new FormSubmission();
   
    int i = 0;
   
    for (ProductsInWishList p : wl.getProducts()) {
      String prodId = p.getProduct().getId()+"";
      if (req.getParameter(prodId) != null) {
        l.fine("moving prodId :"+prodId+" to cart");
        ch.addProduct(prodId);
        pinwl.remove(p);
        i++;
      }
    }
   
    if (i > 0) {
      fs.setResultView(ch.getCartView())
      fs.setResultMessage(i+" products moved to your cart");
    }
    else {
      fs.setResultView(getWishListView())
      fs.setResultMessage("No products were selected");
    }

    return fs;
  }
View Full Code Here

   
  }

  public FormSubmission processEditProductRequest() {
   
    FormSubmission fs = new FormSubmission();

    Long id = Long.parseLong(req.getParameter(Parameters.PRODUCT_ID.getId()));

    l.info("edit product "+id);
   
    Product p = service.getById(id);

   

    try {

      String action = req.getParameter(Parameters.PRODUCT_ACTION.getId());
      if (action.equals("Update Product")) {
        Double price = Double.parseDouble(req.getParameter(Parameters.PRODUCT_PRICE.getId()));
        p.setPrice(price);
       
        String description = req.getParameter(Parameters.PRODUCT_DESC.getId());
        p.setDescription(description);
       
        String onSale = req.getParameter(Parameters.ON_SALE.getId());
        if (onSale != null && onSale.equals("on")) {
          p.setSaleInd("T")
        }
        else {
          p.setSaleInd("F");
        }
       
        String active = req.getParameter(Parameters.ON_SALE.getId());
        p.setActive(active != null && active.equals("on"));
       
        fs.setForm(FormName.EDIT_PRODUCT);
      }
      else if (action.equals("")) {
       
      }

      fs.setResultMessage("Update sucessful!");
      service.store(p);
     
    } catch (Exception e) {
      l.log(Level.WARNING, "Error updating product", e);
     
      fs.setResultMessage(e.getMessage());
 
    }
   
    View fv = getProductView(true, p);
    fs.setResultView(fv);
   
    return fs;
  }
View Full Code Here

  public FormSubmission search() {
    return search(false);
  }
  public FormSubmission search(boolean admin) {

    FormSubmission fs = new FormSubmission();
   
    String query = req.getParameter(Parameters.SEARCH_QUERY.getId());
   
    if (fs.validString(query)) {
     
      View main = null;
      if (admin) {
        main = getMainAdminView();
      }
      else {
        main = getMainView();
      }
      ProductListingView pl = new ProductListingView(main);
     
      pl.setProducts(service.searchProductsByNameOrDescription(query));
      pl.addContentView(new ContentView(JSP_PRODUCT_LISTING, "Search results for: "+query));
     
      fs.setResultView(pl);
     
    }
    else {
      fs.setResultView(getHomePageView());
    }
   
    return fs;
  }
View Full Code Here

TOP

Related Classes of com.ateam.webstore.ui.forms.FormSubmission

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.