Package com.arrgsocal.servlets.crud

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

package com.arrgsocal.servlets.crud;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

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.Event;
import com.arrgsocal.managers.EventManager;

/**
* Servlet implementation class CreateEvent
*/
@WebServlet("/createEvent")
public class CreateEvent extends HttpServlet {
  private static final long serialVersionUID = 1L;

  @EJB
  EventManager eventManager;
 
  @SuppressWarnings("unused")
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    List<String> errors = new ArrayList<>();
    Date startDate = new Date();request.getParameter("startdate");
    if (startDate == null){
      errors.add("You didn't input a start date!");
    }
   
    Date endDate = new Date();
    if (endDate == null){
      errors.add("You didn't input an end date!");
    }
   
    String title = request.getParameter("title");
    if (title == null || title.isEmpty()){
      errors.add("You didn't input a title date!");
    }
   
    String description = request.getParameter("description");
   
    int recurrance = Integer.parseInt(request.getParameter("recurrance"));
   
    if (errors.size() > 0){
      request.setAttribute("errors", errors);
      request.getRequestDispatcher("/WEB-INF/.jsp").forward(request, response);
      return;
    }
   
    Event e = new Event();
    e.setStartDate(startDate);
    e.setEndDate(endDate);
    e.setTitle(title);
    e.setDescription(description);
    e.setRecurrance(recurrance);
   
    response.sendRedirect("./");
  }

}
TOP

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

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.