0

I tried create selectManyCheckbox in JSF and after press button get all selected items.

@ManagedBean
@RequestScoped
public class AddUser {

    private String login;
    private Set<Role> rolesSet;
    private List<Role> roles;
    private Role role;

    public AddUser() {
    }

    @PostConstruct
    public void init() {
        roles = ShiroDao.me().getRolesList();
        rolesSet = new HashSet<>();
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }


    public List<Role> getRoles() {
        return roles;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
        rolesSet.add(role);
    }

    public void createUser() {
        User user = new User();
        user.setLogin(login);
        user.setRoles(rolesSet);
        if (ShiroDao.me().createNewUser(user)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Пользователь ", "создан!"));
        } else {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Пользователь ",
                    " не создан!!! "));
        }
    }
}

It is my jsf:

<p:selectManyCheckbox id="rolesForNewUser" value="#{addUser.role}" layout="grid" columns="3"
                                              converter="#{roleConverter}">
                            <f:selectItems value="#{addUser.roles}" var="roles" itemLabel="#{roles.roleName}"
                                           itemValue="#{roles}"/>
                        </p:selectManyCheckbox>

                        <h:outputLabel for="createUserCommandButton" value=""/>
                        <p:commandButton id="createUserCommandButton"
                                         value="Создать пользователя" action="#{addUser.createUser}"/>

When opened page I see 2 chekbox. After that I selected it and press button/ But button not called method.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user5620472
  • 2,722
  • 8
  • 44
  • 97
  • 2
    There are about a couple of dozen questions with an almost identical topic. Please read all of them and check which one solves your problem. If **none** do, please come back here, post all links to all questions you read and why it did not solve **your** problem. – Kukeltje Dec 22 '15 at 11:10
  • Add `` to your form and use the error as search keyword for the answer. – BalusC Dec 22 '15 at 11:29
  • I have it not help – user5620472 Dec 23 '15 at 03:57

0 Answers0