gpt4 book ai didi

jsf - 如何将默认值设置为

转载 作者:行者123 更新时间:2023-12-02 07:47:28 25 4
gpt4 key购买 nike

我正在尝试将默认值设置为 h:selectOneMenu。但是,它不起作用。

这是我的代码

index.xhtml

<h:body>
<h:form id="test">
<h:selectOneMenu value="#{selectMenuBean.selectedItem}"
title="select version"
onchange="submit()"
disabled="false" id="combo">

<f:selectItems value="#{selectMenuBean.selectItems}" />
</h:selectOneMenu>

</h:form>
</h:body>

BackingBean

private String selectedItem;
private List selectItems;
private int version=3;

public List getSelectItems() {

List<Version> selectedItems = ExportDao.getVersionsList();
System.out.println("List size: "+selectedItems.size());
selectItems = new ArrayList();

for (Version v1 : selectedItems) {
String DATE_FORMAT = "yyyy-MM-dd HH:mm";
//Create object of SimpleDateFormat and pass the desired date format.
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
selectItems.add(new SelectItem(v1.getVersion(), "V" + v1.getVersion() + "/" + sdf.format(v1.getDate())));
if(version = v1.getVersion()) // I have to check the version and set the matching version as selected.
selectedItem = "V" + v1.getVersion() + "/" + sdf.format(v1.getDate());

}
return selectItems;
}

最佳答案

您正在使用项目标签而不是项目值设置 selectedItem

替换

selectedItem = "V" + v1.getVersion() + "/" + sdf.format(v1.getDate());

通过

selectedItem = v1.getVersion();

关于jsf - 如何将默认值设置为 <h :selectOneMenu>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5865296/

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