예제 #1
0
파일: Products.cpp 프로젝트: rzymek/cxxsp
void Products::process(HttpServletRequest& request, HttpServletResponse &response) {
    map<string,string> params;
    params["category_id"]=request.getParameter("category_id");
    params["s_keyword"]=request.getParameter("s_keyword");
    params["price_from"]=request.getParameter("price_from");
    params["price_to"]=request.getParameter("price_to");

    const string WHERE = where_part(params) ;
    string query = "SELECT * FROM store_products"
        + WHERE
        + order_part(request.getParameter("productsOrder"), request.getParameter("productsDir"))
        + limit_part(request.getParameter("productsPageSize"), request.getParameter("productsPage"));

    products_t products = fetch(query);
    request.setAttribute("products", products);

    query = "SELECT COUNT(*) FROM store_products" + WHERE;
    int ResultsFound = count(query);
    request.setAttribute("ResultsFound", ResultsFound);

    int pageSize = getPageSize(request.getParameter("productsPageSize"));
    int pageCount = static_cast<int>( ceilf(static_cast<float>(ResultsFound)/pageSize) );
    request.setAttribute("pageCount", pageCount);

    int currentPage = 1;
    string s_currentPage = request.getParameter("productsPage");
    if(!s_currentPage.empty())
        currentPage = lexical_cast<int>(s_currentPage);
    request.setAttribute("currentPage", currentPage);

    request.setAttribute("naviLink",make_naviLink(request));
}
예제 #2
0
파일: Products.cpp 프로젝트: rzymek/cxxsp
void Products::doGet(HttpServletRequest& request, HttpServletResponse &response) {
    try{
        request.setAttribute("categories", fetch_categories());
        process(request, response);
    }catch(const exception& ex) {
        request.setAttribute<string>("error",ex.what());
        request.setAttribute("ResultsFound", 0);
        request.setAttribute("products", products_t());
        request.setAttribute("naviLink",string());
        request.setAttribute("currentPage", 0);
    }
    request.getRequestDispatcher("ProductsView.csp")->forward(request,response);
}
예제 #3
0
void ProductDetails::show_product(HttpServletRequest& request, HttpServletResponse &response) {
    string id = request.getParameter("product_id");
    if(id.empty())
        throw runtime_error("ProductDetails: product_id parameter not supplyed");
    Product product = fetch(id);
    request.setAttribute("product", product);
    request.getRequestDispatcher("ProductDetailsView.csp")->forward(request,response);
}
예제 #4
0
void ProductDetails::doGet(HttpServletRequest& request, HttpServletResponse &response) {
    try{
        request.getSession(true); //start session
        show_product(request, response);
    }catch(const exception& ex) {
        request.setAttribute<string>("error",ex.what());
        request.setAttribute("product",Product());
        request.getRequestDispatcher("ProductDetailsView.csp")->forward(request,response);
    }
}
예제 #5
0
void ProductDetails::doPost(HttpServletRequest& request, HttpServletResponse &response) {
    try{
        try{
            add_to_cart(request, response);
        }catch(const exception& ex) {
            request.setAttribute<string>("error",ex.what());
            show_product(request, response);
        }
    }catch(const exception& ex) {
        request.setAttribute<string>("error",ex.what());
        request.setAttribute("product",Product());
        request.getRequestDispatcher("ProductDetailsView.csp")->forward(request,response);
    }
}