burnmyheaven
burnmyheaven

Reputation: 137

How can i get value from <h:selectManyCheckbox>

I have one collection , which I'm displaying in my .xhtml page by <h:dataTable>. I want to reach a few goals: at first I want to set list.check value by <h:selectManyCheckbox>, at second I want whatever the values remains selected until the end of current session. Now It displays correctly, but when I select some value it doesn't transmit it in list.check property. I'm using JSF v.2.2.

Code in JSF bean:

private List<AnswerDTO> answerListDto;
//getters and setters

Code in .xhtml

<h:form> 
    <h:dataTable value="#{main.answerListDto}" var="list">
        <h:column>
            <h:selectManyCheckbox value="#{list.check}">
                <f:selectItem itemValue="1" itemLabel="#{list.ansValue}" />
            </h:selectManyCheckbox> 
        </h:column>
    </h:dataTable>
</h:form>

AnswerDTO class:

public class AnswerDTO implements Serializable, DTO {

    private static final long serialVersionUID = 1L;

    private Integer     id;
    private Question    questId;
    private String      ansValue;
    private String      ansStatus;
    private String      check;    

    //getters and setters
}

Upvotes: 0

Views: 1954

Answers (1)

partlov
partlov

Reputation: 14277

Strange use of selectManyCheckbox I must say. Concrete problem is that value of selectManyCheckbox must be an array.

My opinion is that selectBooleanCheckbox should be used instead of selectManyCheckbox. Your check property can have only two values, an empty array (if checkbox is not selected), and array of length 1 with value which is equal to ansValue (if checkbox is selected).

Upvotes: 1

Related Questions