TaskListController.java

package org.sakaiproject.tool.tasklist;

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.tool.tasklist.api.TaskListService;
import org.sakaiproject.tool.api.Tool;

import org.sakaiproject.component.cover.ComponentManager;

/**
 * This servlet takes requests for the tasklist tool, invokes suitable methods
 * on the TaskListService, and forwards to an appropriate view.
 */
public class TaskListController extends HttpServlet { 

	private static final long serialVersionUID = 1L;

	private TaskListService taskListService;
	
	private static Log log = LogFactory.getLog("TaskListController"); 
	
	public void init() {
		log.info("TaskListController init()");
		org.sakaiproject.component.api.ComponentManager componentMgr = ComponentManager.getInstance();
		taskListService = (TaskListService) componentMgr.get("org.sakaiproject.tool.tasklist.api.TaskListService");
	}

	public void doGet(HttpServletRequest req, HttpServletResponse res)
	    throws ServletException, IOException
	  {
		finish(req,res);
	  }
	
	public void doPost(HttpServletRequest req, HttpServletResponse res)
	    throws ServletException, IOException
	  {
		String taskText = (String)req.getAttribute("taskText");
		taskListService.addTask(taskListService.createTask(taskText));
		
		finish(req, res);
	
	  }
	
	private void finish(HttpServletRequest req, HttpServletResponse res) 
		throws ServletException, IOException 
	{
		
		req.setAttribute("tasks", taskListService.getAllTasks());
		req.setAttribute("username", taskListService.getCurrentUserDisplayName());
		
		// set the sakai request object wrappers to provide the native, not Sakai set up, URL information
		// - this assures that the FacesServlet can dispatch to the proper view based on the path info
		req.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL);

		// dispatch to the target
		String target = "/tasklist/TaskList.jsp";
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(target);
		dispatcher.forward(req, res);
	}



}
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.