Java Code Examples for org.springframework.web.servlet.mvc.support.RedirectAttributes

The following are top voted examples for showing how to use org.springframework.web.servlet.mvc.support.RedirectAttributes. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Spring-Security-Third-Edition   File: EventsController.java   View source code 9 votes vote down vote up
@RequestMapping(value = "/new", method = RequestMethod.POST)
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
Example 2
Project: Spring-Security-Third-Edition   File: EventsController.java   View source code 7 votes vote down vote up
@PostMapping(value = "/new")
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
Example 3
Project: Spring-Security-Third-Edition   File: EventsController.java   View source code 6 votes vote down vote up
@PostMapping(value = "/new")
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
Example 4
Project: Spring-Security-Third-Edition   File: EventsController.java   View source code 6 votes vote down vote up
@PostMapping(value = "/new")
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
Example 5
Project: Spring-Security-Third-Edition   File: EventsController.java   View source code 6 votes vote down vote up
@PostMapping(value = "/new")
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
Example 6
Project: lemon   File: BusinessInfoController.java   View source code 6 votes vote down vote up
@RequestMapping("business-info-save")
public String save(@ModelAttribute BusinessInfo businessInfo,
        @RequestParam Map<String, Object> parameterMap,
        RedirectAttributes redirectAttributes) {
    String tenantId = tenantHolder.getTenantId();
    BusinessInfo dest = null;

    Long id = businessInfo.getId();

    if (id != null) {
        dest = businessInfoManager.get(id);
        beanMapper.copy(businessInfo, dest);
    } else {
        dest = businessInfo;
        dest.setTenantId(tenantId);
    }

    businessInfoManager.save(dest);

    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/business/business-info-list.do";
}
 
Example 7
Project: Spring-Security-Third-Edition   File: EventsController.java   View source code 6 votes vote down vote up
@PostMapping(value = "/new")
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
Example 8
Project: Smart-Shopping   File: MvcController.java   View source code 6 votes vote down vote up
/**
 * adds new shopping list for the current user
 * 
 * @param newList
 *            ShoppingListDTO with basic information about new list (must
 *            include list name)
 */
@RequestMapping(value = "/list", method = RequestMethod.POST)
public String addList(Principal principal, @Valid @ModelAttribute("newList") ShoppingListDTO newList, BindingResult binding, RedirectAttributes attr, HttpSession session) {
	LOGGER.debug("addList() method of MvcController called for user: {}", principal.getName());
	if(!binding.hasErrors()) 
		repositoryService.addShoppingListToUserByName(principal.getName(), newList.getListName());
	else {
		attr.addFlashAttribute("org.springframework.validation.BindingResult.newList", binding);
		attr.addFlashAttribute("newList", newList);
		for(FieldError ferr:binding.getFieldErrors()) {
			LOGGER.info("addList(): field error: " + ferr.getDefaultMessage());
		}
	}
	
	return "redirect:/list";
}
 
Example 9
Project: Spring-Security-Third-Edition   File: EventsController.java   View source code 6 votes vote down vote up
@PostMapping(value = "/new")
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message",
            "Successfully added the new event");
    return "redirect:/events/my";
}
 
Example 10
Project: airsonic   File: UserSettingsController.java   View source code 6 votes vote down vote up
@RequestMapping(method = RequestMethod.POST)
protected String doSubmitAction(@ModelAttribute("command") @Validated UserSettingsCommand command, BindingResult bindingResult, RedirectAttributes redirectAttributes) throws Exception {

    if(!bindingResult.hasErrors()) {
        if (command.isDeleteUser()) {
            deleteUser(command);
        } else if (command.isNewUser()) {
            createUser(command);
        } else {
            updateUser(command);
        }
        redirectAttributes.addFlashAttribute("settings_reload", true);
        redirectAttributes.addFlashAttribute("settings_toast", true);
    } else {
        redirectAttributes.addFlashAttribute("command", command);
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.command", bindingResult);
        redirectAttributes.addFlashAttribute("userIndex", getUserIndex(command));
    }

    return "redirect:userSettings.view";
}
 
Example 11
Project: lemon   File: JobGradeController.java   View source code 6 votes vote down vote up
@RequestMapping("job-grade-save")
public String save(@ModelAttribute JobGrade jobGrade,
        RedirectAttributes redirectAttributes) {
    String tenantId = tenantHolder.getTenantId();
    JobGrade dest = null;
    Long id = jobGrade.getId();

    if (id != null) {
        dest = jobGradeManager.get(id);
        beanMapper.copy(jobGrade, dest);
    } else {
        dest = jobGrade;
        dest.setTenantId(tenantId);
    }

    jobGradeManager.save(dest);

    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/org/job-grade-list.do";
}
 
Example 12
Project: lemon   File: SendmailHistoryController.java   View source code 6 votes vote down vote up
@RequestMapping("sendmail-history-save")
public String save(@ModelAttribute SendmailHistory sendmailHistory,
        RedirectAttributes redirectAttributes) {
    String tenantId = tenantHolder.getTenantId();
    Long id = sendmailHistory.getId();
    SendmailHistory dest = null;

    if (id != null) {
        dest = sendmailHistoryManager.get(id);
        beanMapper.copy(sendmailHistory, dest);
    } else {
        dest = sendmailHistory;
        dest.setTenantId(tenantId);
    }

    sendmailHistoryManager.save(dest);
    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/sendmail/sendmail-history-list.do";
}
 
Example 13
Project: lemon   File: PermTypeController.java   View source code 6 votes vote down vote up
@RequestMapping("perm-type-save")
public String save(@ModelAttribute PermType permType,
        RedirectAttributes redirectAttributes) {
    // copy
    PermType dest = null;
    Long id = permType.getId();

    if (id != null) {
        dest = permTypeManager.get(id);
        beanMapper.copy(permType, dest);
    } else {
        dest = permType;
    }

    if (id == null) {
        dest.setTenantId(tenantHolder.getTenantId());
    }

    // save
    permTypeManager.save(dest);

    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/auth/perm-type-list.do";
}
 
Example 14
Project: lemon   File: LeaveInfoController.java   View source code 6 votes vote down vote up
@RequestMapping("leave-info-save")
public String save(@ModelAttribute LeaveInfo leaveInfo,
        @RequestParam Map<String, Object> parameterMap,
        RedirectAttributes redirectAttributes) {
    String tenantId = tenantHolder.getTenantId();
    LeaveInfo dest = null;

    Long id = leaveInfo.getId();

    if (id != null) {
        dest = leaveInfoManager.get(id);
        beanMapper.copy(leaveInfo, dest);
    } else {
        dest = leaveInfo;
        dest.setTenantId(tenantId);
    }

    leaveInfoManager.save(dest);

    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/leave/leave-info-list.do";
}
 
Example 15
Project: lemon   File: AuditBaseController.java   View source code 6 votes vote down vote up
@RequestMapping("audit-base-save")
public String save(@ModelAttribute AuditBase auditBase,
        @RequestParam Map<String, Object> parameterMap,
        RedirectAttributes redirectAttributes) {
    String tenantId = tenantHolder.getTenantId();
    AuditBase dest = null;

    Long id = auditBase.getId();

    if (id != null) {
        dest = auditBaseManager.get(id);
        beanMapper.copy(auditBase, dest);
    } else {
        dest = auditBase;
        dest.setTenantId(tenantId);
    }

    auditBaseManager.save(dest);

    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/audit/audit-base-list.do";
}
 
Example 16
Project: lemon   File: PartyEntityController.java   View source code 6 votes vote down vote up
@RequestMapping("party-entity-save")
public String save(@ModelAttribute PartyEntity partyEntity,
        @RequestParam("partyTypeId") Long partyTypeId,
        RedirectAttributes redirectAttributes) {
    String tenantId = tenantHolder.getTenantId();
    PartyEntity dest = null;
    Long id = partyEntity.getId();

    if (id != null) {
        dest = partyEntityManager.get(id);
        beanMapper.copy(partyEntity, dest);
    } else {
        dest = partyEntity;
        dest.setTenantId(tenantId);
    }

    dest.setPartyType(partyTypeManager.get(partyTypeId));
    partyEntityManager.save(dest);

    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/party/party-entity-list.do";
}
 
Example 17
Project: nixmash-blog   File: AdminController.java   View source code 6 votes vote down vote up
@RequestMapping(value = "/roles/update/{Id}", method = RequestMethod.POST)
public String updateRole(@Valid @ModelAttribute(value = "authority") RoleDTO roleDTO, BindingResult result,
                         RedirectAttributes attributes, Model model) {
    if (result.hasErrors()) {
        webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_ERROR);
        return "redirect:/admin/roles";
    } else {
        Authority authority = userService.getAuthorityById(roleDTO.getId());
        if (authority.isLocked()) {
            webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_IS_LOCKED, roleDTO.getAuthority().toUpperCase());
            return "redirect:/admin/roles";
        } else {
            userService.updateAuthority(roleDTO);
            webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_UPDATED, roleDTO.getAuthority());
            return "redirect:/admin/roles";
        }
    }
}
 
Example 18
Project: nixmash-blog   File: AdminController.java   View source code 6 votes vote down vote up
@RequestMapping(value = "/roles/update/{Id}", params = {"deleteRole"}, method = RequestMethod.POST)
public String deleteRole(@Valid @ModelAttribute(value = "authority") RoleDTO roleDTO, BindingResult result,
                         RedirectAttributes attributes, Model model) {
    if (result.hasErrors()) {
        webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_ERROR);
        return "redirect:/admin/roles";
    } else {
        Authority authority = userService.getAuthorityById(roleDTO.getId());

        if (authority.isLocked()) {
            webUI.addFeedbackMessage(attributes,
                    FEEDBACK_MESSAGE_KEY_ROLE_IS_LOCKED, roleDTO.getAuthority());
        } else {
            Collection<User> users = userService.getUsersByAuthorityId(roleDTO.getId());
            userService.deleteAuthority(authority, users);
            webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_ROLE_DELETED,
                    roleDTO.getAuthority(), users.size());
        }

        return "redirect:/admin/roles";
    }
}
 
Example 19
Project: Spring-Security-Third-Edition   File: EventsController.java   View source code 6 votes vote down vote up
@RequestMapping(value = "/new", method = RequestMethod.POST)
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
Example 20
Project: lemon   File: MyController.java   View source code 6 votes vote down vote up
/**
 * 修改密码.
 */
@RequestMapping("my-change-password-save")
public String changePasswordSave(
        @RequestParam("oldPassword") String oldPassword,
        @RequestParam("newPassword") String newPassword,
        @RequestParam("confirmPassword") String confirmPassword,
        RedirectAttributes redirectAttributes) {
    Long accountId = Long.parseLong(currentUserHolder.getUserId());
    ChangePasswordResult changePasswordResult = changePasswordService
            .changePassword(accountId, oldPassword, newPassword,
                    confirmPassword);

    if (changePasswordResult.isSuccess()) {
        messageHelper.addFlashMessage(redirectAttributes,
                changePasswordResult.getCode(),
                changePasswordResult.getMessage());

        return "redirect:/user/my-change-password-input.do";
    } else {
        messageHelper.addFlashMessage(redirectAttributes,
                changePasswordResult.getCode(),
                changePasswordResult.getMessage());

        return "redirect:/user/my-change-password-input.do";
    }
}
 
Example 21
Project: Spring-Security-Third-Edition   File: EventsController.java   View source code 6 votes vote down vote up
@PostMapping(value = "/new")
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
Example 22
Project: lemon   File: PimPlanController.java   View source code 6 votes vote down vote up
@RequestMapping("pim-plan-save")
 public String save(@ModelAttribute PimPlan pimPlan,
         RedirectAttributes redirectAttributes) {
     String userId = currentUserHolder.getUserId();
     String tenantId = tenantHolder.getTenantId();
     Long id = pimPlan.getId();
     PimPlan dest = null;

     if (id != null) {
         dest = pimPlanManager.get(id);
         beanMapper.copy(pimPlan, dest);
     } else {
         dest = pimPlan;
         dest.setUserId(userId);
         dest.setCreateTime(new Date());
dest.setStatus("active");
     }

     pimPlanManager.save(dest);
     messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
             "保存成功");

     return "redirect:/pim/pim-plan-list.do";
 }
 
Example 23
Project: lemon   File: DictSchemaController.java   View source code 6 votes vote down vote up
@RequestMapping("dict-schema-save")
public String save(@ModelAttribute DictSchema dictSchema,
        @RequestParam("typeId") Long typeId,
        RedirectAttributes redirectAttributes) {
    String tenantId = tenantHolder.getTenantId();
    DictSchema dest = null;

    Long id = dictSchema.getId();

    if (id != null) {
        dest = dictSchemaManager.get(id);
        beanMapper.copy(dictSchema, dest);
    } else {
        dest = dictSchema;
        dest.setTenantId(tenantId);
    }

    dest.setDictType(dictTypeManager.get(typeId));

    dictSchemaManager.save(dest);

    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/dict/dict-schema-config.do?typeId=" + typeId;
}
 
Example 24
Project: lemon   File: JobTitleController.java   View source code 6 votes vote down vote up
@RequestMapping("job-title-save")
public String save(@ModelAttribute JobTitle jobTitle,
        RedirectAttributes redirectAttributes) {
    String tenantId = tenantHolder.getTenantId();
    JobTitle dest = null;
    Long id = jobTitle.getId();

    if (id != null) {
        dest = jobTitleManager.get(id);
        beanMapper.copy(jobTitle, dest);
    } else {
        dest = jobTitle;
        dest.setTenantId(tenantId);
    }

    jobTitleManager.save(dest);

    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/org/job-title-list.do";
}
 
Example 25
Project: lemon   File: PimRemindController.java   View source code 6 votes vote down vote up
@RequestMapping("pim-remind-save")
public String save(@ModelAttribute PimRemind pimRemind,
        RedirectAttributes redirectAttributes) {
    String userId = currentUserHolder.getUserId();
    String tenantId = tenantHolder.getTenantId();
    Long id = pimRemind.getId();
    PimRemind dest = null;

    if (id != null) {
        dest = pimRemindManager.get(id);
        beanMapper.copy(pimRemind, dest);
    } else {
        dest = pimRemind;
        dest.setUserId(userId);
        dest.setCreateTime(new Date());
        dest.setStatus("active");
    }

    pimRemindManager.save(dest);
    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/pim/pim-remind-list.do";
}
 
Example 26
Project: lemon   File: PartyStructTypeController.java   View source code 6 votes vote down vote up
@RequestMapping("party-struct-type-save")
public String save(@ModelAttribute PartyStructType partyStructType,
        RedirectAttributes redirectAttributes) {
    String tenantId = tenantHolder.getTenantId();
    PartyStructType dest = null;
    Long id = partyStructType.getId();

    if (id != null) {
        dest = partyStructTypeManager.get(id);
        beanMapper.copy(partyStructType, dest);
    } else {
        dest = partyStructType;
        dest.setTenantId(tenantId);
    }

    partyStructTypeManager.save(dest);
    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/party/party-struct-type-list.do";
}
 
Example 27
Project: uis   File: AdminUsersController.java   View source code 6 votes vote down vote up
@PostMapping("/create")
public String createUser(@Valid CreateUserForm form,
                         BindingResult bindingResult,
                         RedirectAttributes redirectAttributes) {
    if (bindingResult.hasErrors()) {
        redirectAttributes.addFlashAttribute("flashMessage", "admin.users.create.error." + bindingResult.getFieldError().getField());

        return "redirect:/admin/users";
    }
    boolean error = false;
    try{
    	userCreationService.create(form.toUisUser());
    }catch(ValidationException e){
    	error = true;
        redirectAttributes.addFlashAttribute("flashMessage", "admin.users.create.error.email");
    }
    if(!error){
    	redirectAttributes.addFlashAttribute("flashMessage", "admin.users.create.success");
    }
    
    return "redirect:/admin/users";
}
 
Example 28
Project: saluki   File: ClientDetailsAdminController.java   View source code 6 votes vote down vote up
private boolean checkScopeValidation(List<String> scopes, RedirectAttributes attributes) {
    if (scopes.isEmpty()) {
        addErrorMessage(attributes, "授权范围至少选择一个");
        return false;
    }else{
        List<String> invalidScopes = new ArrayList<>();
        scopes.forEach(scope -> {
            if (!scopeRepository.findOneByValue(scope).isPresent()) {
                invalidScopes.add(scope);
            }
        });

        invalidScopes.forEach(scope -> addErrorMessage(attributes, "授权范围 " + scope + " 无效。"));

        return invalidScopes.isEmpty();
    }
   
}
 
Example 29
Project: lemon   File: MeetingInfoController.java   View source code 6 votes vote down vote up
@RequestMapping("meeting-info-remove")
public String remove(@RequestParam("selectedItem") List<Long> selectedItem,
        RedirectAttributes redirectAttributes) {
    List<MeetingInfo> meetingInfos = meetingInfoManager
            .findByIds(selectedItem);

    for (MeetingInfo meetingInfo : meetingInfos) {
        meetingAttendeeManager.removeAll(meetingInfo.getMeetingAttendees());
        meetingItemManager.removeAll(meetingInfo.getMeetingItems());
        meetingInfoManager.remove(meetingInfo);
    }

    messageHelper.addFlashMessage(redirectAttributes,
            "core.success.delete", "删除成功");

    return "redirect:/meeting/meeting-info-list.do";
}
 
Example 30
Project: tdd-pingpong   File: TaskController.java   View source code 6 votes vote down vote up
@RequestMapping("/skip/{taskInstanceId}")
public RedirectView skip(RedirectAttributes redirectAttributes,
    @PathVariable long taskInstanceId) {
  logger.debug("Request to /skip/{}", taskInstanceId);

  TaskInstance skippedTaskInstance = taskInstanceService.findOne(taskInstanceId);
  if (!gameplayService.canPlayOrSkip(skippedTaskInstance, userService.getCurrentUser())) {
    logger.debug("Can't play or skip");
    return new RedirectView("/error");
  }

  Challenge currentChallenge = skippedTaskInstance.getChallenge();
  if (currentChallenge.getType() == ChallengeType.ARCADE || !currentChallenge.getIsOpen()) {
    logger.debug("Dropping arcade challenge");

    skippedTaskInstance.setStatus(CodeStatus.DROPPED);
    taskInstanceService.save(skippedTaskInstance);
    return new RedirectView("/playChallenge/" + currentChallenge.getId());
  }

  logger.debug("Redirecting to error");
  return new RedirectView("/error");
}
 
Example 31
Project: saluki   File: ScopeAdminController.java   View source code 6 votes vote down vote up
@RequestMapping(path = "/_remove/{scopeValue}", method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE,
                                                                                         MediaType.APPLICATION_XHTML_XML_VALUE })
public String remove(@PathVariable("scopeValue") String scopeValue, RedirectAttributes attributes) {

    scopeRepository.findOneByValue(scopeValue).map(scopeEntity -> {

        Set<ClientDetailsToScopesXrefEntity> xref = scopeEntity.getClientDetailsToScopesXrefs();
        if (xref.isEmpty()) {

            scopeRepository.delete(scopeEntity);
            addSuccessMessage(attributes, "已成功删除 " + scopeValue + " 授权范围。");

        } else {
            addErrorMessage(attributes, "有" + xref.size() + "个客户端正在使用该授权范围,无法删除。");
        }

        return scopeEntity;

    }).orElseGet(() -> {
        addWarningMessage(attributes, "没有找到 " + scopeValue + " 授权范围");
        return null;
    });

    return "redirect:/scopes.html";
}
 
Example 32
Project: lemon   File: BpmCategoryController.java   View source code 6 votes vote down vote up
@RequestMapping("bpm-category-save")
public String save(@ModelAttribute BpmCategory bpmCategory,
        RedirectAttributes redirectAttributes) {
    BpmCategory dest = null;
    Long id = bpmCategory.getId();

    if (id != null) {
        dest = bpmCategoryManager.get(id);
        beanMapper.copy(bpmCategory, dest);
    } else {
        dest = bpmCategory;

        String tenantId = tenantHolder.getTenantId();
        dest.setTenantId(tenantId);
    }

    bpmCategoryManager.save(dest);

    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/bpm/bpm-category-list.do";
}
 
Example 33
Project: Spring-Security-Third-Edition   File: EventsController.java   View source code 6 votes vote down vote up
@PostMapping(value = "/new")
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
Example 34
Project: AntiSocial-Platform   File: FileUploadController.java   View source code 6 votes vote down vote up
@RequestMapping(value="/user/{ssoId}/upload", method = RequestMethod.POST, consumes = "multipart/form-data")
public String singleFileUpload(@Valid FileUpload fileUpload, BindingResult br, Model model, @PathVariable String ssoId, @RequestParam("source") String source, RedirectAttributes attr) throws IOException {
    if(!userService.getPrincipal().equalsIgnoreCase(ssoId)){
        return "redirect:/error";
    }
    if (br.hasErrors()) {
        attr.addFlashAttribute("uploadError", "Please upload a PNG or JPEG formatted file less than 1024 KB.");
        return "redirect:/user/"+ssoId+"?uploadError";
    }

    String SAVE_LOCATION;
    if(source.equalsIgnoreCase("bg")){
        SAVE_LOCATION = servletContext.getRealPath("/resources/") + "pic/bg/" + ssoId + ".jpg";
    }else if(source.equalsIgnoreCase("pp")){
        SAVE_LOCATION = servletContext.getRealPath("/resources/") + "pic/" + ssoId + ".jpg";
    }else {
        attr.addFlashAttribute("uploadError", "Unsupported URL. Please refresh the page and try again.");
        return "redirect:/user/"+ssoId+"?uploadError";
    }

    imageService.saveImage(fileUpload.getFile(),SAVE_LOCATION);

    return "redirect:/user/"+ssoId+"?successup";

}
 
Example 35
Project: lemon   File: WorkcalPartController.java   View source code 6 votes vote down vote up
@RequestMapping("workcal-part-save")
public String save(@ModelAttribute WorkcalPart workcalPart,
        @RequestParam("workcalRuleId") Long workcalRuleId,
        RedirectAttributes redirectAttributes) {
    String tenantId = tenantHolder.getTenantId();
    Long id = workcalPart.getId();
    WorkcalPart dest = null;

    if (id != null) {
        dest = workcalPartManager.get(id);
        beanMapper.copy(workcalPart, dest);
    } else {
        dest = workcalPart;
        dest.setTenantId(tenantId);
    }

    dest.setWorkcalRule(workcalRuleManager.get(workcalRuleId));

    workcalPartManager.save(dest);
    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/workcal/workcal-part-list.do";
}
 
Example 36
Project: lemon   File: ReportDimController.java   View source code 6 votes vote down vote up
@RequestMapping("report-dim-save")
public String save(@ModelAttribute ReportDim reportDim,
        @RequestParam("queryId") Long queryId,
        RedirectAttributes redirectAttributes) {
    String userId = currentUserHolder.getUserId();
    String tenantId = tenantHolder.getTenantId();
    Long id = reportDim.getId();
    ReportDim dest = null;

    if (id != null) {
        dest = reportDimManager.get(id);
        beanMapper.copy(reportDim, dest);
    } else {
        dest = reportDim;
    }

    dest.setReportQuery(reportQueryManager.get(queryId));
    reportDimManager.save(dest);
    messageHelper.addFlashMessage(redirectAttributes, "core.success.save",
            "保存成功");

    return "redirect:/report/report-dim-list.do";
}
 
Example 37
Project: Spring-Security-Third-Edition   File: EventsController.java   View source code 6 votes vote down vote up
@PostMapping(value = "/new")
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
Example 38
Project: esup-sgc   File: UserCardController.java   View source code 5 votes vote down vote up
@RequestMapping(value="/enableEuropeanCard", method=RequestMethod.POST)
public String enableEuropeanCard(final RedirectAttributes redirectAttributes) {
	Authentication auth = SecurityContextHolder.getContext().getAuthentication();
	String eppn = auth.getName();
	User user = User.findUser(eppn);
	user.setEuropeanStudentCard(true);
	user.merge();
	logService.log(user.getCards().get(0).getId(), ACTION.ENABLEEUROPEANCARD, RETCODE.SUCCESS, "", eppn, null);
	redirectAttributes.addFlashAttribute("messageInfo", SUCCESS_MSG + "european");
	return "redirect:/user";
}
 
Example 39
Project: Spring-Security-Third-Edition   File: SignupController.java   View source code 5 votes vote down vote up
@RequestMapping(value="/signup/new",method=RequestMethod.POST)
public String signup(@Valid SignupForm signupForm, BindingResult result, RedirectAttributes redirectAttributes) {
    if(result.hasErrors()) {
        return "signup/form";
    }

    String email = signupForm.getEmail();
    if(calendarService.findUserByEmail(email) != null) {
        result.rejectValue("email", "errors.signup.email", "Email address is already in use.");
        return "signup/form";
    }

    CalendarUser user = new CalendarUser();
    user.setEmail(email);
    user.setFirstName(signupForm.getFirstName());
    user.setLastName(signupForm.getLastName());
    user.setPassword(signupForm.getPassword());

    logger.info("CalendarUser: {}", user);

    int id = calendarService.createUser(user);
    user.setId(id);
    userContext.setCurrentUser(user);

    redirectAttributes.addFlashAttribute("message", "You have successfully signed up and logged in.");
    return "redirect:/";
}
 
Example 40
Project: spring-boot-boilerplate   File: UserController.java   View source code 5 votes vote down vote up
/**
 * 提交注册信息并处理
 *
 * @param userInfo
 * @return
 */
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(final UserInfo userInfo, final RedirectAttributes redirectAttributes) {

    userInfo.setId(new ID().toHexString());
    userInfo.setStatus(0);
    Result<UserInfo> result = userInfoService.save(userInfo);
    result.setMessage("注册成功!");

    //传递信息给重定向页面
    redirectAttributes.addFlashAttribute("result", result);

    //重定向到列表页面
    return "redirect:/user.html/list";
}