Example usage for org.springframework.validation BindingResult setNestedPath

List of usage examples for org.springframework.validation BindingResult setNestedPath

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult setNestedPath.

Prototype

void setNestedPath(String nestedPath);

Source Link

Document

Allow context to be changed so that standard validators can validate subtrees.

Usage

From source file:org.jdal.ui.bind.ViewBinder.java

public void doUpdate() {
    View<Object> view = getView();
    BindingResult br = view.getBindingResult();

    if (br != null) {
        br.setNestedPath(propertyName);
    }// w  w  w  .j av a2  s.c o  m

    view.update();
    setValue(view.getModel());

    if (br != null && view.getBindingResult().hasErrors()) {
        for (ObjectError oe : view.getBindingResult().getAllErrors()) {
            getBindingResult().addError(oe);
        }
    }
}

From source file:org.anyframe.iam.admin.users.web.AnnotationUsersController.java

/**
 * add Users data/*from ww  w. j  a v  a2s .  co m*/
 * @param users Users domain object
 * @param bindingResult an object to check input data with validation rules
 * @param groupId group Id
 * @param roleIds array of Role Ids
 * @param status SessionStatus object to block double submit
 * @return move to "/userdetail/list.do?" page
 * @throws Exception fail to add data
 */
@RequestMapping("/users/add.do")
public String add(@ModelAttribute("users") Users users, BindingResult bindingResult,
        GroupsUsersId groupsUsersId, @RequestParam("groupId") String groupId,
        @RequestParam(value = "roleId", required = false) String[] roleId, SessionStatus status)
        throws Exception {

    beanValidator.validate(users, bindingResult);
    if (bindingResult.hasErrors()) {
        return "/users/userdetail";
    }
    String currentTime = DateUtil.getCurrentTime("yyyyMMdd");

    users.setPassword(users.getUserId());
    users.setCreateDate(currentTime);

    GroupsUsers groupUsers = new GroupsUsers();
    //      GroupsUsersId groupsUsersId = new GroupsUsersId();
    //
    //      groupsUsersId.setUserId(users.getUserId());
    //      groupsUsersId.setGroupId(groupId);

    groupUsers.setId(groupsUsersId);
    groupUsers.setUsers(users);
    groupUsers.setCreateDate(currentTime);

    Set<GroupsUsers> groups = new HashSet<GroupsUsers>();

    groups.add(groupUsers);

    users.setGroupsUserses(groups);

    bindingResult.setNestedPath("groupsUserses[0].id");
    beanValidator.validate(users.getGroupsUserses().iterator().next().getId(), bindingResult);
    bindingResult.setNestedPath(null);
    if (bindingResult.hasErrors()) {
        return "/users/userdetail";
    }

    Authorities[] authorities = null;

    if (roleId != null) {
        authorities = new Authorities[roleId.length];
        for (int i = 0; i < roleId.length; i++) {
            authorities[i] = new Authorities();

            AuthoritiesId authoritiesId = new AuthoritiesId();

            authoritiesId.setRoleId(roleId[i]);
            authoritiesId.setSubjectId(users.getUserId());

            authorities[i].setId(authoritiesId);
            authorities[i].setType("U");
            authorities[i].setCreateDate(currentTime);
        }
    }

    usersService.save(users, authorities);

    status.setComplete();

    return "forward:/userdetail/list.do?&groupId=" + groupId;
}