Package com.arrgsocal.servlets.crud

Source Code of com.arrgsocal.servlets.crud.UpdateTodo

package com.arrgsocal.servlets.crud;

import java.io.IOException;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.arrgsocal.entities.Todo;
import com.arrgsocal.managers.TodoManager;

/**
* Servlet implementation class UpdateTodo
*/
@WebServlet("/UpdateTodo")
public class UpdateTodo extends HttpServlet
{
  private static final long serialVersionUID = 1L;
  @EJB
  TodoManager todoManager;
 
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {
    int id = -1;
    try
    {
      id = Integer.parseInt(request.getParameter("id"));
      if (request.getParameter("update") != null)
      {
        Todo t = todoManager.getTodo(id);
        t.setName(request.getParameter("name"));
        t.setDescription(request.getParameter("description"));
        t.setPriority(Integer.parseInt(request.getParameter("priority")));
        todoManager.update(t);
      }
      else if (request.getParameter("delete") != null)
      {
        todoManager.delete(id);
      }
      response.sendRedirect(getServletContext().getContextPath());
      return;
    }
    catch (Exception e)
    {
    }
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to find/modify event!");
  }
}
TOP

Related Classes of com.arrgsocal.servlets.crud.UpdateTodo

TOP
Copyright © 2018 www.massapi.com. 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.