src/java/br/org/catolicasc/fcgf/projprog4/web/cmds/ProductCRUDCmd.java
//Para criar e voltar a view de List

Para criar e voltar a view de List
Para criar e voltar a view de List
public String makeAndList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        setCmdName(request);
        EntityManagerFactory factory = EntityManagerFactoryManager.getEntityManagerFactory();
        CategoryDAO categoryDao = new CategoryDAO(factory);
        ProductDAO productDao = new ProductDAO(factory);
        String name = request.getParameter(NOME);
        String description = request.getParameter(DESCRIPTION);
        String price = request.getParameter(PRICE);
        String categoryId = request.getParameter(CATEGORY);
        Category category = categoryDao.findCategory(Long.parseLong(categoryId));
        Product product = new Product(name, description, Double.parseDouble(price), category);
        productDao.create(product);
        request.setAttribute(MESSAGE, "Product created successfully.");
        return list(request, response);
    }
public String makeAndList ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { setCmdName ( request ) ; EntityManagerFactory factory = EntityManagerFactoryManager . getEntityManagerFactory ( ) ; CategoryDAO categoryDao = new CategoryDAO ( factory ) ; ProductDAO productDao = new ProductDAO ( factory ) ; String name = request . getParameter ( NOME ) ; String description = request . getParameter ( DESCRIPTION ) ; String price = request . getParameter ( PRICE ) ; String categoryId = request . getParameter ( CATEGORY ) ; Category category = categoryDao . findCategory ( Long . parseLong ( categoryId ) ) ; Product product = new Product ( name , description , Double . parseDouble ( price ) , category ) ; productDao . create ( product ) ; request . setAttribute ( MESSAGE , "Product created successfully." ) ; return list ( request , response ) ; }
Para criar e voltar a view de List
Para criar e voltar a view de List