Example usage for org.springframework.web.servlet.view RedirectView RedirectView

List of usage examples for org.springframework.web.servlet.view RedirectView RedirectView

Introduction

In this page you can find the example usage for org.springframework.web.servlet.view RedirectView RedirectView.

Prototype

public RedirectView(String url, boolean contextRelative) 

Source Link

Document

Create a new RedirectView with the given URL.

Usage

From source file:pt.ist.fenix.ui.spring.TeacherPagesController.java

@RequestMapping(value = "copyContent", method = RequestMethod.POST)
public RedirectView copyContent(@PathVariable ExecutionCourse executionCourse,
        @RequestParam ExecutionCourse previousExecutionCourse, RedirectAttributes redirectAttributes) {
    canCopyContent(executionCourse, previousExecutionCourse);
    try {//w ww.ja  v  a  2s  . c o m
        copyContent(previousExecutionCourse.getSite(), executionCourse.getSite());
    } catch (RuntimeException e) {
        LoggerFactory.getLogger(TeacherPagesController.class).error("error importing site content", e);
        //error occurred while importing content
        redirectAttributes.addFlashAttribute("importError", true);
        return new RedirectView(String.format("/teacher/%s/pages", executionCourse.getExternalId()), true);
    }
    return new RedirectView(String.format("/teacher/%s/pages", executionCourse.getExternalId()), true);
}

From source file:net.sf.sze.frontend.zeugnis.PdfController.java

/**
 * Erstellt das PDF fr einen Schler./*w w w.j  av  a  2  s  . c  om*/
 * @param halbjahrId die Id des Schulhalbjahres
 * @param klassenId die Id der Klasse
 * @param schuelerId die Id des Schuelers
 * @param isRemoteCall true wenn die Anfrage remote erfolgt.
 * @param redirectAttributes die Meldungen.
 * @return die logische View
 */
@RequestMapping(value = URL.ZeugnisPath.ONE_PDF, method = RequestMethod.GET)
public View createPDF(@PathVariable(URL.Session.P_HALBJAHR_ID) Long halbjahrId,
        @PathVariable(URL.Session.P_KLASSEN_ID) Long klassenId,
        @PathVariable(URL.Session.P_SCHUELER_ID) Long schuelerId,
        @ModelAttribute(MODELL_ATTRIBUTE_IS_REMOTE_CALL) boolean isRemoteCall,
        RedirectAttributes redirectAttributes) {
    final File zeugnisDatei = zeugnisCreatorService
            .createZeugnis(zeugnisErfassungsService.getZeugnis(halbjahrId, schuelerId));
    if (zeugnisDatei.exists() && zeugnisDatei.canRead()) {
        final Subject currentUser = SecurityUtils.getSubject();
        if (!isRemoteCall || currentUser.isPermitted("print:remoteAll")) {
            return new FileContentView(zeugnisDatei);
        } else {
            redirectAttributes.addFlashAttribute(MESSAGE,
                    "Zeugniss wurde erstellt, " + "aber Sie sind nicht berechtigt diese im Browser anzusehen.");
            LOG.info(zeugnisDatei.getAbsolutePath() + " wurde angelegt, aber "
                    + "mangels Berechtigung nicht an {} ausgeliefert.", currentUser.getPrincipal());
        }
    } else {
        redirectAttributes.addFlashAttribute(MESSAGE, "Zeugnis erstellt, aber nicht lesbar.");
        LOG.warn("Kann " + zeugnisDatei.getAbsolutePath() + " nicht lesen. " + "Exists: "
                + zeugnisDatei.exists() + ", canRead: " + zeugnisDatei.canRead());
    }
    return new RedirectView(URL.createLinkToZeugnisUrl(halbjahrId, klassenId, schuelerId), true);
}

From source file:com.persistent.cloudninja.controller.TenantTaskListController.java

@RequestMapping(value = "/redirectToHomePage.htm")
public ModelAndView showRedirectToTenantHomePage(HttpServletRequest request,
        @CookieValue("CLOUDNINJAAUTH") String cookie) {

    if (cookie == null) {
        cookie = request.getAttribute("cookieNameAttr").toString();
    }//from ww  w . j a v  a  2s  .co  m

    String tenantId = AuthFilterUtils.getFieldValueFromCookieString(CloudNinjaConstants.COOKIE_TENANTID_PREFIX,
            cookie);

    ModelAndView model = new ModelAndView(new RedirectView("/" + tenantId + "/showTenantHomePage.htm", true));
    return model;
}

From source file:org.duracloud.account.app.controller.AbstractAccountController.java

/**
 * //w w  w  .j av  a 2 s  .c om
 * @param accountId
 * @param suffix
 * @return
 */
protected View createAccountRedirectView(Long accountId, String suffix) {
    String url = MessageFormat.format("{0}{1}{2}", ACCOUNTS_PATH,
            ACCOUNT_PATH.replace("{accountId}", String.valueOf(accountId)), suffix);

    RedirectView redirectView = new RedirectView(url, true);
    redirectView.setExposeModelAttributes(false);

    return redirectView;
}

From source file:com.healthcit.cacure.web.controller.ModuleListController.java

/**
 * delete Module item from list.//w  w  w.j ava  2s  . c o  m
 * @param moduleId Long
 * @param delete boolean
 * @return view with list of Module items
 */
@RequestMapping(value = Constants.MODULE_LISTING_URI, method = RequestMethod.GET, params = { "moduleId",
        "delete" })
public View deleteModule(@RequestParam(value = "moduleId", required = true) Long moduleId,
        @RequestParam(value = "delete", required = true) boolean delete) {

    BaseModule moduleToDelete = (BaseModule) moduleManager.getModule(moduleId);

    if (!isEditable(moduleToDelete)) {
        // The UI should never get the user here
        throw new UnauthorizedException("The module is not editable in the current context");
    }

    if (delete) {
        moduleManager.deleteModuleWithEmptyForms(moduleId);
    }
    if (moduleToDelete.isLibrary()) {
        return new RedirectView(Constants.LIBRARY_MANAGE_URI, true);
    } else {
        return new RedirectView(Constants.MODULE_LISTING_URI, true);
    }
}

From source file:architecture.user.spring.controller.SecurityController.java

@RequestMapping(value = "/logout", method = { RequestMethod.POST, RequestMethod.GET })
public View logout(@RequestParam(value = "url", defaultValue = "/", required = false) String url,
        HttpSession session, NativeWebRequest request) throws NotFoundException, IOException {
    session.invalidate();/*from   w  ww . ja va  2s . c o  m*/
    return new RedirectView(url, true);
}

From source file:org.duracloud.account.app.controller.AbstractCrudController.java

@RequestMapping(value = BY_ID_DELETE_MAPPING, method = RequestMethod.POST)
@Transactional//from   w  w  w .  j  a v  a 2s  .c  om
public ModelAndView delete(@PathVariable Long id, RedirectAttributes redirectAttributes) {

    delete(id);
    setSuccessFeedback(deleteSuccessMessage(), redirectAttributes);
    log.info("deleted object: id={}", id);

    return new ModelAndView(new RedirectView(getBaseViewId(), true));
}

From source file:nl.surfnet.coin.selfservice.control.identity.IdentityController.java

@RequestMapping(value = "/do-switch.shtml", method = RequestMethod.POST, params = "reset=true")
public RedirectView resetIdentity(HttpServletRequest request) {
    CoinUser currentUser = SpringSecurity.getCurrentUser();
    InstitutionIdentityProvider provider = SpringSecurity.getImpersonatedIdentityProvider();
    currentUser.setIdp(provider);/*  w w w . j av  a  2s. co m*/

    newIdentity(null, request, provider);

    clearAuthorities(currentUser, isDashBoard(request));

    return new RedirectView("/app-overview.shtml", true);
}

From source file:cherry.sqlapp.controller.sqltool.load.SqltoolLoadIdControllerImpl.java

@Override
public ModelAndView execute(int id, SqltoolLoadForm form, BindingResult binding, Authentication auth,
        Locale locale, SitePreference sitePref, HttpServletRequest request, RedirectAttributes redirAttr) {

    if (binding.hasErrors()) {
        ModelAndView mav = new ModelAndView(PathDef.VIEW_SQLTOOL_LOAD_ID_INIT);
        mav.addObject(PathDef.PATH_VAR_ID, id);
        return mav;
    }/*from  ww  w . j av  a  2  s.co  m*/

    long asyncId = asyncProcessFacade.launchFileProcess(auth.getName(), "SqltoolLoadIdController",
            form.getFile(), "execLoadFileProcessHandler", form.getDatabaseName(), form.getSql());

    redirAttr.addFlashAttribute(ASYNC_PARAM, asyncId);

    UriComponents uc = fromMethodCall(
            on(SqltoolLoadIdController.class).finish(id, auth, locale, sitePref, request)).build();

    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView(uc.toUriString(), true));
    return mav;
}

From source file:cherry.entree.secure.passwd.PasswdControllerImpl.java

@Override
public ModelAndView execute(PasswdForm form, BindingResult binding, Authentication auth, Locale locale,
        SitePreference sitePref, HttpServletRequest request, RedirectAttributes redirAttr) {

    if (binding.hasErrors()) {
        ModelAndView mav = new ModelAndView(PathDef.VIEW_PASSWD_INIT);
        return mav;
    }//  w  w w.j a  va2s .com

    if (!validateForm(form, binding)) {
        ModelAndView mav = new ModelAndView(PathDef.VIEW_PASSWD_INIT);
        return mav;
    }

    if (!auth.getName().equals(form.getLoginId())) {
        rejectOnCurAuthFailed(binding);
        ModelAndView mav = new ModelAndView(PathDef.VIEW_PASSWD_INIT);
        return mav;
    }

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(auth.getName(),
            form.getPassword());
    try {
        Authentication a = authenticationManager.authenticate(token);
        checkNotNull(a, "AuthenticationManager#authenticate(token): null");
    } catch (AuthenticationException ex) {
        rejectOnCurAuthFailed(binding);
        ModelAndView mav = new ModelAndView(PathDef.VIEW_PASSWD_INIT);
        return mav;
    }

    String password = passwordEncoder.encode(form.getNewPassword());
    if (!passwdService.changePassword(auth.getName(), password)) {
        if (log.isDebugEnabled()) {
            log.debug("Password has not been updated: loginId={0}, password={1}", auth.getName(), password);
        }
        throw new IllegalStateException("");
    }

    UriComponents uc = fromMethodCall(on(PasswdController.class).finish(auth, locale, sitePref, request))
            .build();

    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView(uc.toUriString(), true));
    return mav;
}