Java Code Examples for com.in28minutes.web.common.util.TodoListUtils

The following examples show how to use com.in28minutes.web.common.util.TodoListUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: MavenIn28Minutes   Source File: ListTodoServlet.java    License: MIT License 6 votes vote down vote up
@Override
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	HttpSession session = request.getSession();
	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);
	TodoItemList todoList = todoService.getTodoListByUser(user.getId());

	// todo list is request scoped to avoid storing and synchronizing it in
	// session for each CRUD operation
	request.setAttribute("todoList", todoList.getItems());
	request.setAttribute("homeTabStyle", "active");

	request.setAttribute("totalCount", todoList.getCount());
	request.setAttribute("doneCount", todoList.getDoneCount());
	request.setAttribute("todoCount", todoList.getTodoCount());

	request.getRequestDispatcher(HOME_PAGE).forward(request, response);
}
 
Example 2
@Override
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	HttpSession session = request.getSession();
	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);
	TodoItemList todoList = todoService.getTodoListByUser(user.getId());

	// todo list is request scoped to avoid storing and synchronizing it in
	// session for each CRUD operation
	request.setAttribute("todoList", todoList.getItems());
	request.setAttribute("homeTabStyle", "active");

	request.setAttribute("totalCount", todoList.getCount());
	request.setAttribute("doneCount", todoList.getDoneCount());
	request.setAttribute("todoCount", todoList.getTodoCount());

	request.getRequestDispatcher(HOME_PAGE).forward(request, response);
}
 
Example 3
Source Project: MavenIn28Minutes   Source File: CreateTodoServlet.java    License: MIT License 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {
	request.setAttribute("today", new SimpleDateFormat(
			TodoListUtils.DATE_FORMAT).format(new Date()));
	request.getRequestDispatcher(CREATE_TODO_PAGE).forward(request,
			response);
}
 
Example 4
Source Project: MavenIn28Minutes   Source File: LoginServlet.java    License: MIT License 5 votes vote down vote up
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	String email = request.getParameter("email");
	String password = request.getParameter("password");

	LoginForm loginForm = new LoginForm();
	loginForm.setEmail(email);
	loginForm.setPassword(password);

	validateCredentials(request, loginForm);

	if (isInvalid(request)) {
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
		return;
	}

	if (isValidUser(email, password)) {
		request.setAttribute("error",
				resourceBundle.getString("login.form.invalid.credentials"));
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
		return;
	}

	HttpSession session = request.getSession(true);// create session
	User user = userService.getUserByEmail(email);
	session.setAttribute(TodoListUtils.SESSION_USER, user);
	request.getRequestDispatcher(REDIRECT_HOME_PAGE).forward(request,
			response);
}
 
Example 5
Source Project: MavenIn28Minutes   Source File: SessionCheckFilter.java    License: MIT License 5 votes vote down vote up
public void doFilter(ServletRequest request, ServletResponse response,
		FilterChain chain) throws ServletException, IOException {

	HttpServletRequest req = (HttpServletRequest) request;
	HttpSession session = req.getSession();

	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

	if (user != null) {
		chain.doFilter(request, response);
	} else {
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
	}

}
 
Example 6
Source Project: MavenIn28Minutes   Source File: StatusStyleTag.java    License: MIT License 5 votes vote down vote up
@Override
public void doTag() throws JspException, IOException {

	JspWriter out = getJspContext().getOut();
	String statusStyle = TodoListUtils.getStatusStyle(status);
	out.print(statusStyle);

}
 
Example 7
Source Project: MavenIn28Minutes   Source File: StatusLabelTag.java    License: MIT License 5 votes vote down vote up
@Override
public void doTag() throws JspException, IOException {

	JspWriter out = getJspContext().getOut();
	String statusLabel = TodoListUtils.getStatusLabel(status);
	out.print(statusLabel);

}
 
Example 8
Source Project: MavenIn28Minutes   Source File: PriorityIconTag.java    License: MIT License 5 votes vote down vote up
@Override
public void doTag() throws JspException, IOException {
	JspWriter out = getJspContext().getOut();
	String priorityIcon = TodoListUtils.getPriorityIcon(Priority
			.valueOf(priority));
	out.print(priorityIcon);
}
 
Example 9
Source Project: SpringIn28Minutes   Source File: TodoController.java    License: MIT License 5 votes vote down vote up
@InitBinder
public void initBinder(WebDataBinder binder) {
	SimpleDateFormat dateFormat = new SimpleDateFormat(
			TodoListUtils.DATE_FORMAT);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(
			dateFormat, false));
	binder.registerCustomEditor(Priority.class,
			new TodoPriorityPropertyEditor());
}
 
Example 10
Source Project: SpringIn28Minutes   Source File: TodoController.java    License: MIT License 5 votes vote down vote up
@RequestMapping(value = "/user/todos/new", method = RequestMethod.GET)
public String showCreateTodo(Model model) {
	model.addAttribute("today", new SimpleDateFormat(
			TodoListUtils.DATE_FORMAT).format(new Date()));
	model.addAttribute("todo", new TodoItem());
	return "todo/create";
}
 
Example 11
Source Project: SpringIn28Minutes   Source File: StatusStyleTag.java    License: MIT License 5 votes vote down vote up
@Override
public void doTag() throws JspException, IOException {

	JspWriter out = getJspContext().getOut();
	String statusStyle = TodoListUtils.getStatusStyle(status);
	out.print(statusStyle);

}
 
Example 12
Source Project: SpringIn28Minutes   Source File: StatusLabelTag.java    License: MIT License 5 votes vote down vote up
@Override
public void doTag() throws JspException, IOException {

	JspWriter out = getJspContext().getOut();
	String statusLabel = TodoListUtils.getStatusLabel(status);
	out.print(statusLabel);

}
 
Example 13
Source Project: SpringIn28Minutes   Source File: PriorityIconTag.java    License: MIT License 5 votes vote down vote up
@Override
public void doTag() throws JspException, IOException {
	JspWriter out = getJspContext().getOut();
	String priorityIcon = TodoListUtils.getPriorityIcon(Priority
			.valueOf(priority));
	out.print(priorityIcon);
}
 
Example 14
@Override
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {
	request.setAttribute("today", new SimpleDateFormat(
			TodoListUtils.DATE_FORMAT).format(new Date()));
	request.getRequestDispatcher(CREATE_TODO_PAGE).forward(request,
			response);
}
 
Example 15
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	String email = request.getParameter("email");
	String password = request.getParameter("password");

	LoginForm loginForm = new LoginForm();
	loginForm.setEmail(email);
	loginForm.setPassword(password);

	validateCredentials(request, loginForm);

	if (isInvalid(request)) {
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
		return;
	}

	if (isValidUser(email, password)) {
		request.setAttribute("error",
				resourceBundle.getString("login.form.invalid.credentials"));
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
		return;
	}

	HttpSession session = request.getSession(true);// create session
	User user = userService.getUserByEmail(email);
	session.setAttribute(TodoListUtils.SESSION_USER, user);
	request.getRequestDispatcher(REDIRECT_HOME_PAGE).forward(request,
			response);
}
 
Example 16
public void doFilter(ServletRequest request, ServletResponse response,
		FilterChain chain) throws ServletException, IOException {

	HttpServletRequest req = (HttpServletRequest) request;
	HttpSession session = req.getSession();

	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

	if (user != null) {
		chain.doFilter(request, response);
	} else {
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
	}

}
 
Example 17
@Override
public void doTag() throws JspException, IOException {

	JspWriter out = getJspContext().getOut();
	String statusStyle = TodoListUtils.getStatusStyle(status);
	out.print(statusStyle);

}
 
Example 18
@Override
public void doTag() throws JspException, IOException {

	JspWriter out = getJspContext().getOut();
	String statusLabel = TodoListUtils.getStatusLabel(status);
	out.print(statusLabel);

}
 
Example 19
@Override
public void doTag() throws JspException, IOException {
	JspWriter out = getJspContext().getOut();
	String priorityIcon = TodoListUtils.getPriorityIcon(Priority
			.valueOf(priority));
	out.print(priorityIcon);
}
 
Example 20
Source Project: MavenIn28Minutes   Source File: CreateTodoServlet.java    License: MIT License 4 votes vote down vote up
@Override
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	HttpSession session = request.getSession();
	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

	String title = request.getParameter("title");
	String dueDate = request.getParameter("dueDate");
	String priority = request.getParameter("priority");

	TodoItem todoItem = new TodoItem(user.getId(), title, false,
			Priority.valueOf(priority), new Date(dueDate));

	todoService.create(todoItem);

	request.getRequestDispatcher("/todos").forward(request, response);

}
 
Example 21
@Override
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	HttpSession session = request.getSession();
	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

	String title = request.getParameter("title");
	String dueDate = request.getParameter("dueDate");
	String priority = request.getParameter("priority");

	TodoItem todoItem = new TodoItem(user.getId(), title, false,
			Priority.valueOf(priority), new Date(dueDate));

	todoService.create(todoItem);

	request.getRequestDispatcher("/todos").forward(request, response);

}
 
Example 22
Source Project: MavenIn28Minutes   Source File: LoginServlet.java    License: MIT License 3 votes vote down vote up
private boolean doesValidSessionExist(HttpServletRequest request) {

		HttpSession session = request.getSession(false);

		if (session != null) {

			User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

			if (user != null) {
				return true;
			}

		}
		return false;
	}
 
Example 23
private boolean doesValidSessionExist(HttpServletRequest request) {

		HttpSession session = request.getSession(false);

		if (session != null) {

			User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

			if (user != null) {
				return true;
			}

		}
		return false;
	}