Java Code Examples for org.springframework.web.context.request.WebRequest#removeAttribute()

The following examples show how to use org.springframework.web.context.request.WebRequest#removeAttribute() . 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: FacultyRegistrationController.java    From zhcet-web with Apache License 2.0 6 votes vote down vote up
@PostMapping
public String uploadFacultyFile(RedirectAttributes attributes, @RequestParam MultipartFile file, HttpSession session, WebRequest webRequest) throws IOException {
    try {
        UploadResult<FacultyUpload> result = facultyUploadService.handleUpload(file);

        if (!result.getErrors().isEmpty()) {
            webRequest.removeAttribute(KEY_FACULTY_REGISTRATION, RequestAttributes.SCOPE_SESSION);
            attributes.addFlashAttribute("faculty_errors", result.getErrors());
        } else {
            attributes.addFlashAttribute("faculty_success", true);
            Confirmation<FacultyMember> confirmation = facultyUploadService.confirmUpload(result);
            session.setAttribute(KEY_FACULTY_REGISTRATION, confirmation);
        }
    } catch (IOException ioe) {
        log.error("Error registering faculty", ioe);
    }

    return "redirect:/admin/dean";
}
 
Example 2
Source File: OpenPersistenceManagerInViewInterceptor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count != null) {
		// Do not modify the PersistenceManager: just clear the marker.
		if (count > 1) {
			request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
		}
		else {
			request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		}
	}
	else {
		PersistenceManagerHolder pmHolder = (PersistenceManagerHolder)
				TransactionSynchronizationManager.unbindResource(getPersistenceManagerFactory());
		logger.debug("Closing JDO PersistenceManager in OpenPersistenceManagerInViewInterceptor");
		PersistenceManagerFactoryUtils.releasePersistenceManager(
				pmHolder.getPersistenceManager(), getPersistenceManagerFactory());
	}
}
 
Example 3
Source File: FloatedCourseController.java    From zhcet-web with Apache License 2.0 6 votes vote down vote up
@GetMapping
public String courseDetail(Model model, @PathVariable Course course, WebRequest webRequest) {
    FloatedCourse floatedCourse = floatedCourseService.getFloatedCourse(course).orElseThrow(FloatedCourseNotFoundException::new);

    if (!model.containsAttribute("success"))
        webRequest.removeAttribute("confirmRegistration", RequestAttributes.SCOPE_SESSION);

    model.addAttribute("page_title", course.getCode() + " - " + course.getTitle());
    model.addAttribute("page_subtitle", "Course management for " + course.getCode());
    model.addAttribute("page_description", "Register Students and add Faculty In-Charge for the course");
    model.addAttribute("page_path", getPath(course));

    List<CourseRegistration> courseRegistrations = floatedCourse.getCourseRegistrations();
    List<String> emails = FloatedCourseService
            .getEmailsFromCourseRegistrations(courseRegistrations.stream())
            .collect(Collectors.toList());
    SortUtils.sortCourseAttendance(courseRegistrations);
    model.addAttribute("courseRegistrations", courseRegistrations);
    model.addAttribute("floatedCourse", floatedCourse);
    model.addAttribute("sections", FloatedCourseService.getSections(floatedCourse));
    model.addAttribute("email_list", emails);

    return "department/floated_course";
}
 
Example 4
Source File: StudentRegistrationController.java    From zhcet-web with Apache License 2.0 6 votes vote down vote up
@PostMapping("/confirm")
public String uploadStudents(RedirectAttributes attributes,
                             @SessionAttribute(KEY_STUDENT_REGISTRATION) Confirmation<Student> confirmation,
                             WebRequest webRequest) {
    if (confirmation == null || !confirmation.getErrors().isEmpty()) {
        attributes.addFlashAttribute("errors", Collections.singletonList("Unknown Error"));
    } else {
        try {
            RealTimeStatus status = realTimeStatusService.install();
            studentUploadService.registerStudents(confirmation, status);
            attributes.addFlashAttribute("task_id_student", status.getId());
            attributes.addFlashAttribute("students_registered", true);
        } catch (Exception e) {
            log.error("Error registering students", e);
            attributes.addFlashAttribute("student_unknown_error", true);
        }

        webRequest.removeAttribute(KEY_STUDENT_REGISTRATION, RequestAttributes.SCOPE_SESSION);
    }

    return "redirect:/admin/dean";
}
 
Example 5
Source File: DeanController.java    From zhcet-web with Apache License 2.0 6 votes vote down vote up
@GetMapping
public String deanAdmin(Model model, WebRequest webRequest) {
    model.addAttribute("page_title", "Administration Panel");
    model.addAttribute("page_subtitle", "Dean Administration Panel");
    model.addAttribute("page_description", "Register Students and Faculty, manage roles and users");

    if (!model.containsAttribute("faculty_success"))
        webRequest.removeAttribute(FacultyRegistrationController.KEY_FACULTY_REGISTRATION,
                RequestAttributes.SCOPE_SESSION);

    if (!model.containsAttribute("students_success"))
        webRequest.removeAttribute(StudentRegistrationController.KEY_STUDENT_REGISTRATION,
                RequestAttributes.SCOPE_SESSION);

    model.addAttribute("users", userService.getAll());
    if (!model.containsAttribute("department"))
        model.addAttribute("department", new Department());
    model.addAttribute("departments", departmentService.findAll());

    return "dean/admin";
}
 
Example 6
Source File: FloatedCourseEditController.java    From zhcet-web with Apache License 2.0 6 votes vote down vote up
@GetMapping("/{course}")
public String courseDetail(Model model, @PathVariable Course course, WebRequest webRequest) {
    FloatedCourse floatedCourse = floatedCourseService.getFloatedCourse(course).orElseThrow(FloatedCourseNotFoundException::new);

    if (!model.containsAttribute("success"))
        webRequest.removeAttribute("confirmRegistration", RequestAttributes.SCOPE_SESSION);

    model.addAttribute("page_title", course.getCode() + " - " + course.getTitle());
    model.addAttribute("page_subtitle", "Course management for " + course.getCode());
    model.addAttribute("page_description", "Register Students for the Floated course");

    List<CourseRegistration> courseRegistrations = floatedCourse.getCourseRegistrations();
    List<String> emails = FloatedCourseService
            .getEmailsFromCourseRegistrations(courseRegistrations.stream())
            .collect(Collectors.toList());
    SortUtils.sortCourseAttendance(courseRegistrations);
    model.addAttribute("courseRegistrations", courseRegistrations);
    model.addAttribute("floatedCourse", floatedCourse);
    model.addAttribute("email_list", emails);

    return "dean/floated_course";
}
 
Example 7
Source File: DefaultSessionAttributeStore.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void cleanupAttribute(WebRequest request, String attributeName) {
	Assert.notNull(request, "WebRequest must not be null");
	Assert.notNull(attributeName, "Attribute name must not be null");
	String storeAttributeName = getAttributeNameInSession(request, attributeName);
	request.removeAttribute(storeAttributeName, WebRequest.SCOPE_SESSION);
}
 
Example 8
Source File: OpenSessionInViewInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private boolean decrementParticipateCount(WebRequest request) {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count == null) {
		return false;
	}
	// Do not modify the Session: just clear the marker.
	if (count > 1) {
		request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
	}
	else {
		request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	}
	return true;
}
 
Example 9
Source File: SessionConversationAttributeStore.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @param request
 * @param attributeName
 * @param fullAttributeName
 */
private void removeEntityFromSession(WebRequest request, String attributeName, 
    String conversationId) {
    
    // calculate the full session store attribute name.
    String fullAttributeName = calculateSessionLookupKey(attributeName, conversationId);
    
    // remove the attribute from the session.
    request.removeAttribute(fullAttributeName, WebRequest.SCOPE_SESSION);
    
    // remove the conversation from the queue
    if (getNumConversationsToKeep() > 0) {
        
        // get reference to the 
        Map<String, Queue<String>> conversationQueueHolder = 
            getConversationsMap(request);

        // get conversation queue for the given attribute name
        Queue<String> queue = conversationQueueHolder.get(attributeName);
        
        // create queue if necessary.
        if (queue != null) {
            if (conversationId != null && conversationId.trim().length() > 0) {
                queue.remove(conversationId);
            }
        }
    }
}
 
Example 10
Source File: OpenEntityManagerInViewInterceptor.java    From java-technology-stack with MIT License 5 votes vote down vote up
private boolean decrementParticipateCount(WebRequest request) {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count == null) {
		return false;
	}
	// Do not modify the Session: just clear the marker.
	if (count > 1) {
		request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
	}
	else {
		request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	}
	return true;
}
 
Example 11
Source File: OpenEntityManagerInViewInterceptor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private boolean decrementParticipateCount(WebRequest request) {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count == null) {
		return false;
	}
	// Do not modify the Session: just clear the marker.
	if (count > 1) {
		request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
	}
	else {
		request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	}
	return true;
}
 
Example 12
Source File: DefaultSessionAttributeStore.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void cleanupAttribute(WebRequest request, String attributeName) {
	Assert.notNull(request, "WebRequest must not be null");
	Assert.notNull(attributeName, "Attribute name must not be null");
	String storeAttributeName = getAttributeNameInSession(request, attributeName);
	request.removeAttribute(storeAttributeName, WebRequest.SCOPE_SESSION);
}
 
Example 13
Source File: DefaultSessionAttributeStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void cleanupAttribute(WebRequest request, String attributeName) {
	Assert.notNull(request, "WebRequest must not be null");
	Assert.notNull(attributeName, "Attribute name must not be null");
	String storeAttributeName = getAttributeNameInSession(request, attributeName);
	request.removeAttribute(storeAttributeName, WebRequest.SCOPE_SESSION);
}
 
Example 14
Source File: OpenEntityManagerInViewInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private boolean decrementParticipateCount(WebRequest request) {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count == null) {
		return false;
	}
	// Do not modify the Session: just clear the marker.
	if (count > 1) {
		request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
	}
	else {
		request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	}
	return true;
}
 
Example 15
Source File: OpenSessionInViewInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private boolean decrementParticipateCount(WebRequest request) {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count == null) {
		return false;
	}
	// Do not modify the Session: just clear the marker.
	if (count > 1) {
		request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
	}
	else {
		request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	}
	return true;
}
 
Example 16
Source File: DefaultSessionAttributeStore.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void cleanupAttribute(WebRequest request, String attributeName) {
	Assert.notNull(request, "WebRequest must not be null");
	Assert.notNull(attributeName, "Attribute name must not be null");
	String storeAttributeName = getAttributeNameInSession(request, attributeName);
	request.removeAttribute(storeAttributeName, WebRequest.SCOPE_SESSION);
}
 
Example 17
Source File: OpenSessionInViewInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private boolean decrementParticipateCount(WebRequest request) {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count == null) {
		return false;
	}
	// Do not modify the Session: just clear the marker.
	if (count > 1) {
		request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
	}
	else {
		request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	}
	return true;
}
 
Example 18
Source File: OpenSessionInViewInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private boolean decrementParticipateCount(WebRequest request) {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count == null) {
		return false;
	}
	// Do not modify the Session: just clear the marker.
	if (count > 1) {
		request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
	}
	else {
		request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	}
	return true;
}
 
Example 19
Source File: OpenEntityManagerInViewInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private boolean decrementParticipateCount(WebRequest request) {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count == null) {
		return false;
	}
	// Do not modify the Session: just clear the marker.
	if (count > 1) {
		request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
	}
	else {
		request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	}
	return true;
}
 
Example 20
Source File: OpenSessionInViewInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private boolean decrementParticipateCount(WebRequest request) {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count == null) {
		return false;
	}
	// Do not modify the Session: just clear the marker.
	if (count > 1) {
		request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
	}
	else {
		request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	}
	return true;
}