Search code examples
jsfseamfacelets

Seam and JSF: How to post multiple values instead of single


We have this ui:repeat:

<ui:repeat value="#{notAssigned}" var="pair">
   #{pair.data.processName}<br/>
   <s:button value="assign" action="#{mypage.assign}">
        <f:param name="taskId" value="#{pair.task.id}"/>
   </s:button>
</ui:repeat>

Now I can assign one and one elements but pushing the assign button. But I want to refactor this and add a checkbox, so that you can choose all that you want to assign, and then push one button that will assign all.

How can I modify this code to support checkbox that contains the taskId (which is a Long) and one button to submit.

UPDATE

I tried changing the code to use <h:selectManyCheckbox>

<h:selectManyCheckbox value="#{mypage.notAssignedTaskIds}">
    <f:selectItem itemValue="#{pair.task.id}" itemLabel="#{messages['choose']}" />
</h:selectManyCheckbox>
#{pair.data.processName}


<h:commandButton action="#{mypage.test}" value="Assign"/>

And in my bean:

@Setter @Getter
List<String> notAssignedTaskIds = new ArrayList<String>();

public void test() {
    log.info("Inside test, size of list #0", notAssignedTaskIds.size());
    for(String id : notAssignedTaskIds) {
        log.info("TaskId's chosen #0", id);
    }
}

But notAssignedTaskids is always empty


Solution

  • My suggestion is, create a boolean flag in pair object. Then

    <a:region>
    
        <ui:repeat value="#{notAssigned}" var="pair">
            <h:selectBooleanCheckbox value="#{pair.booleanFlag}">
    
            #{pair.data.processName}
        </ui:repeat>
    
        <a:commandLink action="#{yourBean.assignAll()}" value="assignAll">
        </a:commandLink>
    
    </a:region>
    

    In your bean, iterate over notAssigned list.

    public void assignAll() {
    .
    .
    .
        for (Pair pair : notAssigned) {
            if (pair.booleanFlag) {
                mypage.assign(pair);
            }
        }
    
    
    }
    

    And modify your assign method to get a pair object. By the way you can do it without ajax support. Just remove region and convert your a:commandLink to h:commandLink.