Java Code Examples for javax.faces.context.ExternalContext#redirect()

The following examples show how to use javax.faces.context.ExternalContext#redirect() . 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 File: ItemAuthorBean.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String addAttachmentsRedirect() {
   // 1. load resources into session for resources mgmt page
   //    then redirect to resources mgmt page

// not EMI item (ItemText) attachment  
setCurrentAnswer(null);

   try	{
     prepareMCcorrAnswers();
     List filePickerList = prepareReferenceList(attachmentList);
     ToolSession currentToolSession = SessionManager.getCurrentToolSession();
     currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
     ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
     context.redirect("sakai.filepicker.helper/tool");
   }
   catch(Exception e){
     log.error("fail to redirect to attachment page: " + e.getMessage());
   }
   return getOutcome();
 }
 
Example 2
Source File: SyllabusTool.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String processAddAttachRedirect()
{
  try
  {
    filePickerList = EntityManager.newReferenceList();
    ToolSession currentToolSession = SessionManager.getCurrentToolSession();
    currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    context.redirect("sakai.filepicker.helper/tool");
    if(context.getRequestParameterMap().get("itemId") != null){
  	  currentToolSession.setAttribute(SESSION_ATTACHMENT_DATA_ID, context.getRequestParameterMap().get("itemId"));
    }
    return null;
  }
  catch(Exception e)
  {
    log.error(this + ".processAddAttachRedirect - " + e);
    return null;
  }
}
 
Example 3
Source File: ChatTool.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * This is called from the first page to redirect the user to the proper view.
 * This is the first call after JSF creates a new instance, so initialization is 
 *   done here.
 * If the tool is set to go to the select a chat room view and there are multiple chat
 * rooms, then it will go to the select a room page.  If the user is to select a room and
 * there is only one room, then it will go to that room.
 * 
 * @return String
 */
public String getEnterTool() {
   
setupTool();
 
   // if there is no room selected to enter then go to select a room
   String url = PAGE_ENTER_ROOM;

   if(currentChannel == null)
      url = PAGE_LIST_ROOMS;
            
   ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
   
   HttpServletRequest req = (HttpServletRequest) context.getRequest();
   req.setAttribute(Tool.NATIVE_URL, null); //signal to WrappedRequest that we want the Sakai managed
   setToolContext(req.getContextPath());
   req.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL);
   
   try {
        context.redirect(url);
   }
   catch (IOException e) {
        throw new RuntimeException("Failed to redirect to " + url, e);
   }
   return "";
}
 
Example 4
Source File: AttachmentHandler.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Redirect the add/remove attachment to Sakai's help page.
 * 
 * @param attachList -
 *            a list of attachment objects
 * @param sMeeting -
 *            SignupMeeting object
 * @param isOrganizer -
 *            a boolean value
 * @return null value
 */
public String processAddAttachRedirect(List attachList, SignupMeeting sMeeting,
		boolean isOrganizer) {
	this.attachments = attachList;
	try {
		List filePickerList = prepareReferenceList(attachments, sMeeting, isOrganizer);
		ToolSession currentToolSession = SessionManager.getCurrentToolSession();
		currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS,
				filePickerList);
		ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
		context.redirect("sakai.filepicker.helper/tool");
	} catch (Exception e) {
		log.error("fail to redirect to attachment page: " + e.getMessage());
	}
	return null;
}
 
Example 5
Source File: AgentResults.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String addAssessmentAttachmentsRedirect() {
 // 1. redirect to add attachment
 try	{
  List<Reference> filePickerList = new ArrayList<>();
  if (assessmentGradingAttachmentList != null){
	  AttachmentUtil attachmentUtil = new AttachmentUtil();
	  filePickerList = attachmentUtil.prepareReferenceList(assessmentGradingAttachmentList);
  }
  ToolSession currentToolSession = SessionManager.getCurrentToolSession();
  currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
  
  currentToolSession.setAttribute("assessmentGradingId", assessmentGradingId);
  ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
  context.redirect("sakai.filepicker.helper/tool");
 }
 catch(Exception e){
  log.error("fail to redirect to attachment page: " + e.getMessage());
 }
 return "sakai.filepicker.helper";
}
 
Example 6
Source File: EmailBean.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String addAttachmentsRedirect() {
    try	{
      List filePickerList = new ArrayList();
      if (attachmentList != null){
        filePickerList = prepareReferenceList(attachmentList);
      }
      log.debug("**filePicker list="+filePickerList.size());
      ToolSession currentToolSession = SessionManager.getCurrentToolSession();
      currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
      ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
      context.redirect("sakai.filepicker.helper/tool");
    }
    catch(Exception e){
      log.error("fail to redirect to attachment page: " + e.getMessage());
    }
    return "email";
}
 
Example 7
Source File: SectionBean.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String addAttachmentsRedirect() {
  // 1. then redirect to add attachment
  try	{
    List filePickerList = new ArrayList();
    if (attachmentList != null){
      filePickerList = prepareReferenceList(attachmentList);
    }
    log.debug("**filePicker list="+filePickerList.size());
    ToolSession currentToolSession = SessionManager.getCurrentToolSession();
    currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    context.redirect("sakai.filepicker.helper/tool");
  }
  catch(Exception e){
    log.error("fail to redirect to attachment page: " + e.getMessage());
  }
  return getOutcome();
}
 
Example 8
Source File: AttachmentHandler.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Redirect the add/remove attachment to Sakai's help page.
 * 
 * @param attachList -
 *            a list of attachment objects
 * @param sMeeting -
 *            SignupMeeting object
 * @param isOrganizer -
 *            a boolean value
 * @return null value
 */
public String processAddAttachRedirect(List attachList, SignupMeeting sMeeting,
		boolean isOrganizer) {
	this.attachments = attachList;
	try {
		List filePickerList = prepareReferenceList(attachments, sMeeting, isOrganizer);
		ToolSession currentToolSession = SessionManager.getCurrentToolSession();
		currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS,
				filePickerList);
		ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
		context.redirect("sakai.filepicker.helper/tool");
	} catch (Exception e) {
		log.error("fail to redirect to attachment page: " + e.getMessage());
	}
	return null;
}
 
Example 9
Source File: ItemAuthorBean.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String addAttachmentsRedirect() {
   // 1. load resources into session for resources mgmt page
   //    then redirect to resources mgmt page

// not EMI item (ItemText) attachment  
setCurrentAnswer(null);

   try	{
     prepareMCcorrAnswers();
     List filePickerList = prepareReferenceList(attachmentList);
     ToolSession currentToolSession = SessionManager.getCurrentToolSession();
     currentToolSession.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS, filePickerList);
     ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
     context.redirect("sakai.filepicker.helper/tool");
   }
   catch(Exception e){
     log.error("fail to redirect to attachment page: " + e.getMessage());
   }
   return getOutcome();
 }
 
Example 10
Source File: SignupPermissionsUpdateBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Delegate the permission update job to sakai-permissions-helper tool
 */
private String doPermissions(String siteRef, String description) {
	try {
		ToolSession currentToolSession = SessionManager.getCurrentToolSession();
		currentToolSession.setAttribute(PermissionsHelper.PREFIX, "signup.");
		currentToolSession.setAttribute(PermissionsHelper.TARGET_REF, siteRef);
		currentToolSession.setAttribute(PermissionsHelper.DESCRIPTION, description);
		ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
		context.redirect("sakai.permissions.helper.helper/tool");
	} catch (Exception e) {
		log.error(this + ".processPermissionUpdateRedirect - " + e);
	}

	return null;
}
 
Example 11
Source File: PrivateMessagesTool.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public String processAddAttachmentRedirect()
{
  log.debug("processAddAttachmentRedirect()");
  try
  {
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    context.redirect("sakai.filepicker.helper/tool");
    return null;
  }
  catch(Exception e)
  {
    log.debug("processAddAttachmentRedirect() - Exception");
    return null;
  }
}
 
Example 12
Source File: AuthorBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void setCurrentFormTime(long formTime) {
 if (formTime != currentFormTime) {
  try {
	  ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
	  context.redirect("discrepancyInData");
  } catch (Exception e) {};
 }
}
 
Example 13
Source File: ApplicationBean.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void redirect(String uri) {
    try {
        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
        if (context != null) {
            context.redirect(uri);
        }
    } catch (IOException ioe) {
        // nothing to do
    }
}
 
Example 14
Source File: AuthorBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void setCurrentFormTime(long formTime) {
 if (formTime != currentFormTime) {
  try {
	  ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
	  context.redirect("discrepancyInData");
  } catch (Exception e) {};
 }
}
 
Example 15
Source File: GlobalExceptionHandler.java    From oxAuth with MIT License 5 votes vote down vote up
private void performRedirect(ExternalContext externalContext, String viewId) {
    try {
        externalContext.redirect(externalContext.getRequestContextPath() + viewId);
    } catch (Exception e) {
        log.error("Can't perform redirect to viewId: " + viewId, e);
    }
}
 
Example 16
Source File: LogoutMB.java    From admin-template with MIT License 5 votes vote down vote up
public void doLogout() throws IOException {
    String loginPage = adminConfig.getLoginPage();
    if (loginPage == null || "".equals(loginPage)) {
        loginPage = Constants.DEFAULT_LOGIN_PAGE;
    }
    if (!loginPage.startsWith("/")) {
        loginPage = "/" + loginPage;
    }
    Faces.getSession().invalidate();
    ExternalContext ec = Faces.getExternalContext();
    ec.redirect(ec.getRequestContextPath() + loginPage);
}
 
Example 17
Source File: orgDataMgt.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void forceRefresh() {
    ExternalContext externalContext = getFacesContext().getExternalContext();
    if (externalContext != null) {
        try {
            externalContext.redirect("userWorkQueues.jsp");
        }
        catch (IOException ioe) {}
    }
}
 
Example 18
Source File: AuthBean.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public void logout() throws IOException {
	ExternalContext externalContext = FacesContext.getCurrentInstance()
			.getExternalContext();
	externalContext.invalidateSession();
	externalContext.redirect(externalContext.getRequestContextPath()
			+ "/index.xhtml");
	externalContext.getSessionMap().remove(BeanUtil.KEY_USER);
}
 
Example 19
Source File: UserMB.java    From ipst with Mozilla Public License 2.0 4 votes vote down vote up
public void logOut() throws IOException {
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    ec.invalidateSession();
    ec.redirect(ec.getRequestContextPath() + "/index.jsf");
}
 
Example 20
Source File: AuthBean.java    From sailfish-core with Apache License 2.0 3 votes vote down vote up
public void login() throws IOException {

		FacesContext context = FacesContext.getCurrentInstance();
		ExternalContext externalContext = context.getExternalContext();
		HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();

		try {

			request.login(username, password + PasswordHasher.getSalt());

			User user = BeanUtil.getSfContext().getAuthStorage().getUser(username);

			if (user == null) {

                logger.error("User with login [{}] not found in storage!", username);

				BeanUtil.showMessage(FacesMessage.SEVERITY_ERROR,
						"Invalid login/password pair", "");

				return;
			}

			externalContext.getSessionMap().put(BeanUtil.KEY_USER, user);

			externalContext.redirect(originalURL);

		} catch (ServletException e) {

			// Handle unknown username/password in request.login().
            logger.warn("Bad login attempt with username [{}]; message: {}", username, e.getMessage());
			BeanUtil.showMessage(FacesMessage.SEVERITY_ERROR, "Invalid login/password pair", "");

			return;
		}

		logger.info("Successful login for user [{}]", username);
	}