commandButton未调用方法primefaces

时间:2015-12-22 10:51:58

标签: jsf

我尝试在JSF中创建selectManyCheckbox,然后按下按钮获取所有选定的项目。

@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, "Пользователь ",
                    " не создан!!! "));
        }
    }
}

这是我的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}"/>

打开页面时,我看到2个chekbox。之后我选择了它并按下按钮/但按钮没有调用方法。

0 个答案:

没有答案