JSF Coding The TaskList Backing Bean

Coding The TaskList Backing Bean

  • Creating "TaskListBean.java" file in "tool/src/java/org/sakaiproject/tool/tasklist/jsf"
    • Navigate to "tool/src/java/org/sakaiproject/tool/tasklist/jsf"
    • Select jsf and right click and select New and then Class
    • In the "New Java Class" editor enter "TaskListBean" in the "Name" field
    • Click on Finish
  • This will create the following TaskListBean.java skeleton
    • package org.sakaiproject.tool.tasklist.jsf;
      
      public class TaskListBean {
      
      }
      
  • Adding IoC setters and support to show the user's display name
    package org.sakaiproject.tool.tasklist.jsf;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.sakaiproject.tool.tasklist.api.TaskListService;
    
    public class TaskListBean {
    
    	// use commons logger
    	private final Log log = LogFactory.getLog(this.getClass());
    
    	private TaskListService taskListService;
    	private String currentUserDisplayName;
    	
    	// Constructor
    	public TaskListBean() {
    		log.debug("Constructor");
    	}
    
    	// IoC
    	public void setTaskListService(TaskListService taskListService) {
    		log.debug("setTaskListService");
    		this.taskListService = taskListService;
    		currentUserDisplayName = taskListService.getCurrentUserDisplayName(); 
    	}
    
    	public String getCurrentUserDisplayName() {
    		return currentUserDisplayName;
    	}
    
    	public void setCurrentUserDisplayName(String currentUserDisplayName) {
    		this.currentUserDisplayName = currentUserDisplayName;
    	}
    }