Java Code Examples for org.springframework.web.servlet.view.RedirectView

The following examples show how to use org.springframework.web.servlet.view.RedirectView. These examples are extracted from open source projects. 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
@RequestMapping(value = "{slugSite}/{slugPost}/delete", method = RequestMethod.POST)
public RedirectView delete(@PathVariable String slugSite, @PathVariable String slugPost) {

    FenixFramework.atomic(() -> {
        Site s = Site.fromSlug(slugSite);
        Post post = s.postForSlug(slugPost);
        ensureCanEditPost(post);
        ensureCanDoThis(s, Permission.DELETE_POSTS);
        if(post.isVisible()) {
            ensureCanDoThis(s, Permission.DELETE_POSTS_PUBLISHED);
        }
        if(!Authenticate.getUser().equals(post.getCreatedBy())) {
            ensureCanDoThis(s, Permission.DELETE_OTHERS_POSTS);
        }
        SiteActivity.deletedPost(post, Site.fromSlug(slugSite), Authenticate.getUser());
        post.archive();
    });
    return new RedirectView("/cms/posts/" + slugSite + "", true);
}
 
Example 2
Source Project: Spring-MVC-Blueprints   Source File: AdminLoginController.java    License: MIT License 6 votes vote down vote up
@RequestMapping(method=RequestMethod.POST)
public RedirectView submitForm(Model model, @Validated @ModelAttribute LoginForm adminLoginForm, BindingResult bindingResult){
	model.addAttribute("adminLoginForm", adminLoginForm);
	RedirectView redirectView = new RedirectView();
	redirectView.setContextRelative(true);
	
	if(bindingResult.hasErrors()) {
		adminLoginForm = new LoginForm();
		redirectView.setUrl("/smp/admin_login.html");
		model.addAttribute("adminLoginForm", adminLoginForm);
	} else{
		Login login = new Login();
		login.setUserName(adminLoginForm.getUsername());
		login.setPassWord(adminLoginForm.getPassword());
		if(loginService.isAdminUser(login.getUserName(), login.getPassWord())){
			redirectView.setUrl("/smp/admin_pending.html");
		}else{
			adminLoginForm = new LoginForm();
			redirectView.setUrl("/smp/admin_login.html");
		}
	}
	return redirectView;
}
 
Example 3
@GetMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

    Player player = playerService.getPlayer(request, response);
    TransferStatus status = statusService.getStreamStatusesForPlayer(player).stream().findFirst()
            .orElseGet(() -> statusService.getInactiveStreamStatusForPlayer(player));

    String url = Optional.ofNullable(status)
            .map(s -> mediaFileService.getMediaFile(s.getFile()))
            .map(current -> mediaFileService.getParentOf(current))
            .filter(dir -> !mediaFileService.isRoot(dir))
            .map(dir -> "main.view?id=" + dir.getId())
            .orElse("home.view");

    return new ModelAndView(new RedirectView(url));
}
 
Example 4
@Test
public void invokeAndHandle_DynamicReturnValue() throws Exception {
	this.argumentResolvers.addResolver(new RequestParamMethodArgumentResolver(null, false));
	this.returnValueHandlers.addHandler(new ViewMethodReturnValueHandler());
	this.returnValueHandlers.addHandler(new ViewNameMethodReturnValueHandler());

	// Invoke without a request parameter (String return value)
	ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new Handler(), "dynamicReturnValue", String.class);
	handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer);

	assertNotNull(this.mavContainer.getView());
	assertEquals(RedirectView.class, this.mavContainer.getView().getClass());

	// Invoke with a request parameter (RedirectView return value)
	this.request.setParameter("param", "value");
	handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer);

	assertEquals("view", this.mavContainer.getViewName());
}
 
Example 5
@RequestMapping(value = "{slugSite}/{slugMenu}/down", method = RequestMethod.POST)
public RedirectView moveMenuDown(Model model, @PathVariable String slugSite, @PathVariable String slugMenu) {
    FenixFramework.atomic(() -> {
        Site site = Site.fromSlug(slugSite);
        ensureCanDoThis(site, Permission.LIST_MENUS, Permission.EDIT_MENU);
        Menu menu = site.menuForSlug(slugMenu);
        if(menu.getPrivileged()) {
            ensureCanDoThis(site, EDIT_PRIVILEGED_MENU,
                    Permission.DELETE_PRIVILEGED_MENU);
        }
        Integer oldOrder = menu.getOrder();
        if(oldOrder<site.getMenusSet().size()) {
            site.getOrderedMenusSet().stream().filter(m -> m.getOrder() == oldOrder + 1).forEach(m -> m.setOrder(oldOrder));
            menu.setOrder(oldOrder + 1);
        }
    });
    return new RedirectView("/cms/menus/" + slugSite, true);
}
 
Example 6
Source Project: Spring-MVC-Blueprints   Source File: AdminFacultyFormController.java    License: MIT License 6 votes vote down vote up
@RequestMapping(method=RequestMethod.POST)
public RedirectView submitForm(Model model, @Validated @ModelAttribute("facultyForm") FacultyForm facultyForm, BindingResult bindingResult){
	model.addAttribute("facultyForm", facultyForm);
	
	RedirectView redirectView = new RedirectView();
	redirectView.setContextRelative(true);
	redirectView.setUrl("/smp/admin_add_faculty.html");
	
	List<Tblfaculty> faculty = reportService.getAllFaculty();
	model.addAttribute("faculty", faculty);
	
    references(model);
    
	if(bindingResult.hasErrors()) {
		facultyForm = new FacultyForm();
		model.addAttribute("facultyForm", facultyForm);
		
	} else{
		managementService.addFaculty(facultyForm);
		facultyForm = new FacultyForm();
		model.addAttribute("facultyForm", facultyForm);
		
	}
	return redirectView;
}
 
Example 7
Source Project: subsonic   Source File: MultiController.java    License: GNU General Public License v3.0 6 votes vote down vote up
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception {

        // Auto-login if "user" and "password" parameters are given.
        String username = request.getParameter("user");
        String password = request.getParameter("password");
        if (username != null && password != null) {
            username = StringUtil.urlEncode(username);
            password = StringUtil.urlEncode(password);
            return new ModelAndView(new RedirectView("j_acegi_security_check?j_username=" + username +
                    "&j_password=" + password + "&_acegi_security_remember_me=checked"));
        }

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("logout", request.getParameter("logout") != null);
        map.put("error", request.getParameter("error") != null);
        map.put("brand", settingsService.getBrand());
        map.put("loginMessage", settingsService.getLoginMessage());

        User admin = securityService.getUserByName(User.USERNAME_ADMIN);
        if (User.USERNAME_ADMIN.equals(admin.getPassword())) {
            map.put("insecure", true);
        }

        return new ModelAndView("login", "model", map);
    }
 
Example 8
Source Project: Spring-MVC-Blueprints   Source File: AdminCourseFormController.java    License: MIT License 6 votes vote down vote up
@RequestMapping(method=RequestMethod.POST)
public RedirectView submitForm(Model model, @Validated @ModelAttribute("courseForm") CourseForm courseForm, BindingResult bindingResult){
	model.addAttribute("courseForm", courseForm);
	
	RedirectView redirectView = new RedirectView();
	redirectView.setContextRelative(true);
	redirectView.setUrl("/smp/admin_add_course.html");
	
	List<Tblcourses> courses = reportService.getAllCourses();
	model.addAttribute("courses", courses);
	
    references(model);
    
	if(bindingResult.hasErrors()) {
		courseForm =  new CourseForm();
		model.addAttribute("courseForm", courseForm);
		
	} else{
		managementService.addCourse(courseForm);
		courseForm =  new CourseForm();	
		model.addAttribute("courseForm", courseForm);
		
	}
	return redirectView;
}
 
Example 9
Source Project: cloud-service   Source File: WechatController.java    License: MIT License 6 votes vote down vote up
/**
 * 授权后,微信跳转到此接口
 *
 * @return
 */
@GetMapping(value = "/{app}/back", params = {"code", "state"})
public RedirectView wechatBack(HttpServletRequest request, @PathVariable String app, String code, String state,
                               @RequestParam String toUrl) {
    if (StringUtils.isBlank(code)) {
        throw new IllegalArgumentException("code不能为空");
    }

    if (StringUtils.isBlank(state)) {
        throw new IllegalArgumentException("state不能为空");
    }

    WechatUserInfo wechatUserInfo = wechatService.getWechatUserInfo(app, request, code, state);

    toUrl = wechatService.getToUrl(toUrl, wechatUserInfo);

    return new RedirectView(toUrl);
}
 
Example 10
Source Project: Spring-MVC-Blueprints   Source File: AdminLoginController.java    License: MIT License 6 votes vote down vote up
@RequestMapping(method=RequestMethod.POST)
public RedirectView submitForm(Model model, @Validated @ModelAttribute LoginForm adminLoginForm, BindingResult bindingResult){
	model.addAttribute("adminLoginForm", adminLoginForm);
	RedirectView redirectView = new RedirectView();
	redirectView.setContextRelative(true);
	
	if(bindingResult.hasErrors()) {
		adminLoginForm = new LoginForm();
		redirectView.setUrl("/smp/admin_login.html");
		model.addAttribute("adminLoginForm", adminLoginForm);
	} else{
		Login login = new Login();
		login.setUserName(adminLoginForm.getUsername());
		login.setPassWord(adminLoginForm.getPassword());
		if(loginService.isAdminUser(login)){
			redirectView.setUrl("/smp/admin_pending.html");
		}else{
			adminLoginForm = new LoginForm();
			redirectView.setUrl("/smp/admin_login.html");
		}
	}
	return redirectView;
}
 
Example 11
private RootBeanDefinition getRedirectView(Element element, @Nullable HttpStatus status, @Nullable Object source) {
	RootBeanDefinition redirectView = new RootBeanDefinition(RedirectView.class);
	redirectView.setSource(source);
	redirectView.getConstructorArgumentValues().addIndexedArgumentValue(0, element.getAttribute("redirect-url"));

	if (status != null) {
		redirectView.getPropertyValues().add("statusCode", status);
	}

	if (element.hasAttribute("context-relative")) {
		redirectView.getPropertyValues().add("contextRelative", element.getAttribute("context-relative"));
	}
	else {
		redirectView.getPropertyValues().add("contextRelative", true);
	}

	if (element.hasAttribute("keep-query-params")) {
		redirectView.getPropertyValues().add("propagateQueryParams", element.getAttribute("keep-query-params"));
	}

	return redirectView;
}
 
Example 12
Source Project: jeewx   Source File: LoginController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @Title: top
 * @author gaofeng
 * @Description: shortcut头部菜单请求
 * @param request
 * @return ModelAndView
 * @throws
 */
@RequestMapping(params = "shortcut_top")
public ModelAndView shortcut_top(HttpServletRequest request) {
	TSUser user = ResourceUtil.getSessionUserName();
	HttpSession session = ContextHolderUtils.getSession();
	// 登陆者的权限
	if (user.getId() == null) {
		session.removeAttribute(Globals.USER_SESSION);
		return new ModelAndView(
				new RedirectView("loginController.do?login"));
	}
	request.setAttribute("menuMap", getFunctionMap(user));
	List<TSConfig> configs = userService.loadAll(TSConfig.class);
	for (TSConfig tsConfig : configs) {
		request.setAttribute(tsConfig.getCode(), tsConfig.getContents());
	}
	return new ModelAndView("main/shortcut_top");
}
 
Example 13
Source Project: Spring-MVC-Blueprints   Source File: StudentLoginController.java    License: MIT License 6 votes vote down vote up
@RequestMapping(method=RequestMethod.POST)
public RedirectView submitForm(Model model, @Validated @ModelAttribute LoginForm studLoginForm, BindingResult bindingResult){
	model.addAttribute("studLoginForm", studLoginForm);
	RedirectView redirectView = new RedirectView();
	redirectView.setContextRelative(true);
	
	if(bindingResult.hasErrors()) {
		studLoginForm = new LoginForm();
		redirectView.setUrl("/smp/stud_login.html");
		model.addAttribute("studLoginForm", studLoginForm);
	} else{
		Login login = new Login();
		login.setUserName(studLoginForm.getUsername());
		login.setPassWord(studLoginForm.getPassword());
		if(loginService.isStudentUser(login.getUserName(), login.getPassWord())){
			redirectView.setUrl("/smp/stud_enroll.html");
			model.addAttribute("studId", reportService.getStudentId(login.getUserName()).getStudentId());
		}else{
			studLoginForm = new LoginForm();
			redirectView.setUrl("/smp/stud_login.html");
		}
	}
	return redirectView;
}
 
Example 14
Source Project: Spring-MVC-Blueprints   Source File: AdminFacultyFormController.java    License: MIT License 6 votes vote down vote up
@RequestMapping(method=RequestMethod.POST)
public RedirectView submitForm(Model model, @Validated @ModelAttribute("facultyForm") FacultyForm facultyForm, BindingResult bindingResult){
	model.addAttribute("facultyForm", facultyForm);
	
	RedirectView redirectView = new RedirectView();
	redirectView.setContextRelative(true);
	redirectView.setUrl("/smp/admin_add_faculty.html");
	
	List<Tblfaculty> faculty = reportService.getAllFaculty();
	model.addAttribute("faculty", faculty);
	
    references(model);
    
	if(bindingResult.hasErrors()) {
		facultyForm = new FacultyForm();
		model.addAttribute("facultyForm", facultyForm);
		
	} else{
		managementService.addFaculty(facultyForm);
		facultyForm = new FacultyForm();
		model.addAttribute("facultyForm", facultyForm);
		
	}
	return redirectView;
}
 
Example 15
Source Project: spring-cloud-gcp   Source File: WebController.java    License: Apache License 2.0 6 votes vote down vote up
@GetMapping("/pull")
public RedirectView pull(@RequestParam("subscription1") String subscriptionName) {

	Collection<AcknowledgeablePubsubMessage> messages = this.pubSubTemplate.pull(subscriptionName, 10, true);

	if (messages.isEmpty()) {
		return buildStatusView("No messages available for retrieval.");
	}

	RedirectView returnView;
	try {
		ListenableFuture<Void> ackFuture = this.pubSubTemplate.ack(messages);
		ackFuture.get();
		returnView = buildStatusView(String.format("Pulled and acked %s message(s)", messages.size()));
	}
	catch (Exception ex) {
		LOGGER.warn("Acking failed.", ex);
		returnView = buildStatusView("Acking failed");
	}

	return returnView;
}
 
Example 16
Source Project: Spring-MVC-Blueprints   Source File: AdminController.java    License: MIT License 6 votes vote down vote up
@RequestMapping("/smp/admin_logout.html")
public RedirectView logout(Model model, HttpServletRequest req){
	RedirectView redirectView = new RedirectView();
	redirectView.setContextRelative(true);
	redirectView.setUrl("/smp/admin_login.html");
	long end = 0;
	long start = 0;
	try{
		end = (Long) req.getSession().getAttribute("timeUsed");
		start = (Long) req.getSession().getAttribute("timeStarted");
	}catch(NullPointerException e){
		end = 0;
		start = 0;
	}
	
	long accessTime = (start-end)/1000;
	model.addAttribute("accessTime", accessTime);
	
	return redirectView;
}
 
Example 17
Source Project: jeewx   Source File: LoginController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @Title: top
 * @Description: bootstrap头部菜单请求
 * @param request
 * @return ModelAndView
 * @throws
 */
@RequestMapping(params = "top")
public ModelAndView top(HttpServletRequest request) {
	TSUser user = ResourceUtil.getSessionUserName();
	HttpSession session = ContextHolderUtils.getSession();
	// 登陆者的权限
	if (user.getId() == null) {
		session.removeAttribute(Globals.USER_SESSION);
		return new ModelAndView(
				new RedirectView("loginController.do?login"));
	}
	request.setAttribute("menuMap", getFunctionMap(user));
	List<TSConfig> configs = userService.loadAll(TSConfig.class);
	for (TSConfig tsConfig : configs) {
		request.setAttribute(tsConfig.getCode(), tsConfig.getContents());
	}
	return new ModelAndView("main/bootstrap_top");
}
 
Example 18
@RequestMapping(value = "{slugSite}/{slugCategory}", method = RequestMethod.POST)
public RedirectView editCategory(@PathVariable String slugSite, @PathVariable String slugCategory,
                                 @RequestParam LocalizedString name,
                                 @RequestParam(required = false, defaultValue = "false") boolean privileged) {
    Site s = Site.fromSlug(slugSite);
    Category c = s.categoryForSlug(slugCategory);
    FenixFramework.atomic(()->{
        ensureCanDoThis(s, Permission.LIST_CATEGORIES, Permission.EDIT_CATEGORY);
        if(c.getPrivileged()) {
            ensureCanDoThis(s, Permission.USE_PRIVILEGED_CATEGORY, Permission.EDIT_PRIVILEGED_CATEGORY);
        }
        c.setPrivileged(privileged);
        c.setName(name);
    });
    Signal.emit(Category.SIGNAL_EDITED, new DomainObjectEvent<>(c));
    return new RedirectView("/cms/categories/" + s.getSlug() + "/" + c.getSlug(), true);
}
 
Example 19
Source Project: Spring-MVC-Blueprints   Source File: FacultyLoginController.java    License: MIT License 6 votes vote down vote up
@RequestMapping(method=RequestMethod.POST)
public RedirectView submitForm(Model model, @Validated @ModelAttribute LoginForm facultyLoginForm, BindingResult bindingResult){
	model.addAttribute("facultyLoginForm", facultyLoginForm);
	RedirectView redirectView = new RedirectView();
	redirectView.setContextRelative(true);
	
	if(bindingResult.hasErrors()) {
		facultyLoginForm = new LoginForm();
		redirectView.setUrl("/smp/faculty_login.html");
		model.addAttribute("facultyLoginForm", facultyLoginForm);
	} else{
		Login login = new Login();
		login.setUserName(facultyLoginForm.getUsername());
		login.setPassWord(facultyLoginForm.getPassword());
		if(loginService.isFacultyUser(login)){
			model.addAttribute("facultyId", reportService.getFacultyId(login.getUserName()).getFacultyId());
			redirectView.setUrl("/smp/faculty_masterlist.html");
		}else{
			facultyLoginForm = new LoginForm();
			redirectView.setUrl("/smp/faculty_login.html");
		}
	}
	return redirectView;
}
 
Example 20
Source Project: web-sso   Source File: LogoutActionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testLogoutWithCredentialAndService() throws IOException {
	String servce  = "http://app.com/logoutSucess.do";
	
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setParameter(WebConstants.SERVICE_PARAM_NAME, servce);
	MockHttpServletResponse response = new MockHttpServletResponse();
	HttpSession session = request.getSession();
	CredentialResolver credentialResolver = Mockito.mock(CredentialResolver.class);
	logoutAction.setCredentialResolver(credentialResolver);
	Ki4soService ki4soService = Mockito.mock(Ki4soService.class);
	logoutAction.setKi4soService(ki4soService);
	
	//测试存在cookie,登出后要清除cookie值,但是service参数的值是null的情况。
	request.setCookies(new Cookie(WebConstants.KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY, "dddsd"));
	
	ModelAndView mv = logoutAction.logout(request, response,session);
	Assert.assertEquals(1, response.getCookies().length);
	Assert.assertEquals(0, response.getCookies()[0].getMaxAge());
	RedirectView view = (RedirectView) mv.getView();
	Assert.assertEquals(servce, view.getUrl());
}
 
Example 21
Source Project: Spring-MVC-Blueprints   Source File: AdminLoginController.java    License: MIT License 6 votes vote down vote up
@RequestMapping(method=RequestMethod.POST)
public RedirectView submitForm(Model model, @Validated @ModelAttribute LoginForm adminLoginForm, BindingResult bindingResult){
	model.addAttribute("adminLoginForm", adminLoginForm);
	RedirectView redirectView = new RedirectView();
	redirectView.setContextRelative(true);
	
	if(bindingResult.hasErrors()) {
		adminLoginForm = new LoginForm();
		redirectView.setUrl("/smp/admin_login.html");
		model.addAttribute("adminLoginForm", adminLoginForm);
	} else{
		Login login = new Login();
		login.setUserName(adminLoginForm.getUsername());
		login.setPassWord(adminLoginForm.getPassword());
		if(loginService.isAdminUser(login)){
			redirectView.setUrl("/smp/admin_pending.html");
		}else{
			adminLoginForm = new LoginForm();
			redirectView.setUrl("/smp/admin_login.html");
		}
	}
	return redirectView;
}
 
Example 22
Source Project: forum   Source File: TopicController.java    License: MIT License 6 votes vote down vote up
@PostMapping("topic")
public View addAnswer(@RequestParam("content") String content, @RequestParam("code") String code,
                      @RequestParam("id_topic") String id_topic, @RequestParam("id_user") String id_user,
                      HttpServletRequest request) {
    Answer answer = new Answer();
    answer.setContent(content);

    // I know that it can be blank field, but I did it on purpose to find out about Optionals:
    if (Objects.equals(code, ""))
        answer.setCode(null);
    else
        answer.setCode(code);
    answer.setCreatedDate(LocalDateTime.now());
    answer.setUseful(false);
    answer.setTopic(topicRepository.findTopicById(Long.valueOf(id_topic)));
    answer.setUser(userRepository.getUserById(Long.parseLong(id_user)));

    answerRepository.save(answer);
    String contextPath = request.getContextPath();
    return new RedirectView(contextPath + "/topic/" + id_topic);
}
 
Example 23
@PostMapping("/manage_audience/add_audience/{audienceGroupId}")
public CompletableFuture<RedirectView> postAddAudience(
        @PathVariable Long audienceGroupId,
        @RequestParam(required = false) String uploadDescription,
        @RequestParam String audiences) {
    List<Audience> audienceList = Arrays.stream(audiences.split("\r?\n"))
                                        .map(it -> it.replaceAll("\\s+", ""))
                                        .filter(it -> it.length() > 0)
                                        .map(Audience::new)
                                        .collect(Collectors.toList());
    AddAudienceToAudienceGroupRequest request = AddAudienceToAudienceGroupRequest
            .builder()
            .audienceGroupId(audienceGroupId)
            .audiences(audienceList)
            .uploadDescription(uploadDescription)
            .build();
    return client.addAudienceToAudienceGroup(request)
                 .thenApply(it -> new RedirectView("/manage_audience/" + audienceGroupId));
}
 
Example 24
Source Project: airsonic   Source File: LoginController.java    License: GNU General Public License v3.0 5 votes vote down vote up
@GetMapping
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) {

    // Auto-login if "user" and "password" parameters are given.
    String username = request.getParameter("user");
    String password = request.getParameter("password");
    if (username != null && password != null) {
        username = StringUtil.urlEncode(username);
        password = StringUtil.urlEncode(password);
        return new ModelAndView(new RedirectView("/login?" +
                UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY + "=" + username +
                "&" + UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY + "=" + password
        ));
    }

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("logout", request.getParameter("logout") != null);
    map.put("error", request.getParameter("error") != null);
    map.put("brand", settingsService.getBrand());
    map.put("loginMessage", settingsService.getLoginMessage());

    User admin = securityService.getUserByName("admin");
    if (admin != null) {
        if (admin.getUsername().equals(admin.getPassword())) {
            map.put("insecure", true);
        }
    }

    return new ModelAndView("login", "model", map);
}
 
Example 25
@RequestMapping(value = "{type}/deleteDir", method = RequestMethod.POST)
public RedirectView deleteDir(@PathVariable(value = "type") String type, @RequestParam(value = "path") String path) {
    CmsSettings.getInstance().ensureCanManageThemes();

    CMSTheme theme = CMSTheme.forType(type);
    deleteDirectory(theme, path);
    return new RedirectView("/cms/themes/" + type + "/see#templates", true);
}
 
Example 26
Source Project: wallride   Source File: DefaultModelAttributeInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void postHandle(
		HttpServletRequest request,
		HttpServletResponse response,
		Object handler,
		ModelAndView mv)
		throws Exception {
	if (mv == null) return;
	if (mv.getView() instanceof RedirectView) return;
	if (mv.getViewName().startsWith("redirect:")) return;

	Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
	mv.addObject("BLOG", blog);

	List<String> languages = new ArrayList<>();
	if (blog != null) {
		for (BlogLanguage blogLanguage : blog.getLanguages()) {
			languages.add(blogLanguage.getLanguage());
		}
	}

	String currentLanguage = LocaleContextHolder.getLocale().getLanguage();

	mv.addObject("LANGUAGES", languages.toArray(new String[languages.size()]));
	mv.addObject("LANGUAGE_LINKS", buildLanguageLinks(currentLanguage, languages, request));

	Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	AuthorizedUser authorizedUser = null;
	if (authentication != null && authentication.getPrincipal() instanceof AuthorizedUser) {
		authorizedUser = (AuthorizedUser) authentication.getPrincipal();
	}
	mv.addObject("USER", authorizedUser);

	mv.addObject("WEBSITE_TITLE", blog != null ? blog.getTitle(currentLanguage) : null);
	mv.addObject("WEBSITE_LINK", buildGuestLink());
	mv.addObject("WEBSITE_PATH", buildGuestPath(currentLanguage, languages));

	mv.addObject("ADMIN_LINK", buildAdminLink());
	mv.addObject("ADMIN_PATH", buildAdminPath(currentLanguage));
}
 
Example 27
@PostMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    String action = request.getParameter("action");

    MediaFile mediaFile = mediaFileService.getMediaFile(id);

    if ("comment".equals(action)) {
        mediaFile.setComment(StringEscapeUtils.escapeHtml(request.getParameter("comment")));
        mediaFileService.updateMediaFile(mediaFile);
    }

    String url = "main.view?id=" + id;
    return new ModelAndView(new RedirectView(url));
}
 
Example 28
@PostMapping
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    String action = request.getParameter("action");

    MediaFile mediaFile = mediaFileService.getMediaFile(id);

    if ("comment".equals(action)) {
        mediaFile.setComment(StringEscapeUtils.escapeHtml(request.getParameter("comment")));
        mediaFileService.updateMediaFile(mediaFile);
    }

    String url = "main.view?id=" + id;
    return new ModelAndView(new RedirectView(url));
}
 
Example 29
@Test
public void handleViewInstance() throws Exception {
	ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue");
	handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);

	assertEquals(RedirectView.class, mavContainer.getView().getClass());
	assertEquals("attrValue", mavContainer.getModel().get("attrName"));
}
 
Example 30
Source Project: Spring-Boot-2-Fundamentals   Source File: BlogPostController.java    License: MIT License 5 votes vote down vote up
@PostMapping("/")
public RedirectView addBlogPost() {
    blogPostService.addBlogPost(
            new BlogPost(LocalDateTime.now(),
                    "added-post",
                    "An fresh post",
                    "This post has been added.")
    );

    return new RedirectView("/", true);
}