001: package com.sun.portal.app.sharedtasks.faces.beans;
002:
003: import java.util.Map;
004:
005: import com.sun.portal.app.sharedtasks.util.SharedConstants;
006: import com.sun.portal.log.common.PortalLogger;
007: import java.util.logging.Logger;
008:
009: import javax.faces.context.FacesContext;
010: import javax.portlet.PortletRequest;
011: import javax.portlet.PortletSession;
012:
013: /**
014: * Backing bean for task details page session info.
015: *
016: * @author ashwin.mathew@sun.com
017: */
018: public class TaskSessionBackingBean {
019:
020: public static final String BEAN_NAME = "TaskSessionBean";
021:
022: private String taskId;
023:
024: private String taskRid;
025:
026: private Boolean isEdit = Boolean.FALSE;
027:
028: private boolean isCommSearchResultRequested = false;
029:
030: private static Logger logger = PortalLogger
031: .getLogger(TaskSessionBackingBean.class);
032:
033: private static final String PAGE_NEW_TASK = "newTask";
034: private static final String PAGE_EDIT_TASK = "editTask";
035:
036: public String getTaskId() {
037: return taskId;
038: }
039:
040: public void setTaskId(String taskId) {
041: this .taskId = taskId;
042: }
043:
044: public String getTaskRid() {
045: return taskRid;
046: }
047:
048: public void setTaskRid(String taskRid) {
049: this .taskRid = taskRid;
050: }
051:
052: public Boolean getIsEdit() {
053: return isEdit;
054: }
055:
056: public void setIsEdit(Boolean isEdit) {
057: this .isEdit = isEdit;
058: if (isEdit == Boolean.FALSE) {
059: isCommSearchResultRequested = false;
060: }
061: }
062:
063: public String setNewTask() {
064: setIsEdit(Boolean.FALSE);
065: setTaskId(null);
066: setTaskRid(null);
067:
068: return PAGE_NEW_TASK;
069: }
070:
071: public String setEditTask() {
072: setIsEdit(Boolean.TRUE);
073:
074: FacesContext context = FacesContext.getCurrentInstance();
075:
076: Map requestMap = context.getExternalContext()
077: .getRequestParameterMap();
078: String tempTaskId = (String) requestMap
079: .get(SharedConstants.REQ_PARAM_TASKID);
080: if (tempTaskId != null) {
081: taskId = tempTaskId;
082: taskRid = (String) requestMap
083: .get(SharedConstants.REQ_PARAM_TASKRID);
084: }
085:
086: logger.fine("Editing task, id [" + taskId + "], rid ["
087: + taskRid + "]");
088:
089: return PAGE_EDIT_TASK;
090: }
091:
092: private static Object getPortletSessionAttribute(String key) {
093: FacesContext context = FacesContext.getCurrentInstance();
094: Object pReq = context.getExternalContext().getRequest();
095: if (pReq instanceof PortletRequest) {
096: PortletSession pSession = ((PortletRequest) pReq)
097: .getPortletSession();
098: if (pSession != null) {
099: return pSession.getAttribute(key);
100: }
101: }
102: return null;
103: }
104:
105: private static void removePortletSessionAttribute(String key) {
106: FacesContext context = FacesContext.getCurrentInstance();
107: Object pReq = context.getExternalContext().getRequest();
108: if (pReq instanceof PortletRequest) {
109: PortletSession pSession = ((PortletRequest) pReq)
110: .getPortletSession();
111: if (pSession != null) {
112: pSession.removeAttribute(key);
113: }
114: }
115: }
116:
117: private boolean checkPortletSessionForSearchResult() {
118: String searchSt = (String) getPortletSessionAttribute(SharedConstants.URL_COMM_SEARCH_TASKS);
119: if ((searchSt != null)
120: && (Boolean.valueOf(searchSt) == Boolean.TRUE)) {
121: taskId = (String) getPortletSessionAttribute(SharedConstants.REQ_PARAM_TASKID);
122: taskRid = (String) getPortletSessionAttribute(SharedConstants.REQ_PARAM_TASKRID);
123: setIsEdit(Boolean.TRUE);
124: isCommSearchResultRequested = true;
125: removePortletSessionAttribute(SharedConstants.URL_COMM_SEARCH_TASKS);
126: removePortletSessionAttribute(SharedConstants.REQ_PARAM_TASKID);
127: removePortletSessionAttribute(SharedConstants.REQ_PARAM_TASKRID);
128: }
129: return isCommSearchResultRequested;
130:
131: }
132:
133: public boolean isSearchResultRequested() {
134: checkPortletSessionForSearchResult();
135: logger.exiting(TaskSessionBackingBean.BEAN_NAME,
136: "isSearchResultRequested()="
137: + isCommSearchResultRequested);
138: return isCommSearchResultRequested;
139: }
140:
141: /*
142: * This is just a mechanism to invoke isSearchResultRequested
143: * it is used at those places, where it expectes a return of true.
144: *
145: */
146:
147: public boolean isShowTaskDetail() {
148: isSearchResultRequested();
149: return true;
150: }
151:
152: }
|