开发者

h:selectManyCheckbox with POJO problem

开发者 https://www.devze.com 2023-03-21 11:15 出处:网络
I tried some ways to achieve this simple thing : Show a collection of POJOs in form of checkboxes When i click on one of the checkboxes, a method should be executed

I tried some ways to achieve this simple thing :

  1. Show a collection of POJOs in form of checkboxes
  2. When i click on one of the checkboxes, a method should be executed
  3. The method will be able to access the pojo/checkbox that was clicked

I tried to implement it this way :

<h:selectManyCheckbox id="groupUsers" layout="pageDirection" value="#{timetableBean.selectedUsers}">
    <f:ajax listener="#{timetableBean.processUserEvents}" render="@this" />
    &l开发者_运维知识库t;f:selectItems value="#{timetableBean.group.users}" 
            var="user" itemLabel="#{user.userId} - #{user.name}" itemValue="#{user}">
        <f:attribute name="user" value="#{user}" /> 
    </f:selectItems>
</h:selectManyCheckbox>

And my method is :

public void processUserEvents(AjaxBehaviorEvent e) {
  User user = (User) e.getComponent().getAttributes().get("user");
  ...
}

The user fetched from e.getComponent().getAttributes().get("user"); is sadly null

In what way can i accomplish this ?

Thank you !

0

精彩评论

暂无评论...
验证码 换一张
取 消