gpt4 book ai didi

java - 我如何从 获取值(value)

转载 作者:行者123 更新时间:2023-12-01 14:50:52 25 4
gpt4 key购买 nike

我有一个集合,我正在我的 .xhtml 页面中显示 <h:dataTable> 。我想达到几个目标:首先我想通过 <h:selectManyCheckbox> 设置 list.check 值,第二次我希望任何值都保持选中状态,直到当前 session 结束。现在它显示正确,但是当我选择某个值时,它不会在 list.check 属性中传输它。我正在使用 JSF v.2.2。

JSF bean 中的代码:

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

.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>

回答DTO类:

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
}

最佳答案

我必须说的是 selectManyCheckbox 的奇怪使用。具体问题是 selectManyCheckbox 的值必须是一个数组。

我的意见是应该使用selectBooleanCheckbox而不是selectManyCheckbox。您的 check 属性只能有两个值,一个是空数组(如果未选中复选框),另一个是长度为 1 且值等于 ansValue 的数组(如果复选框为已选择)。

关于java - 我如何从 <h :selectManyCheckbox> 获取值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14870051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com