我需要您的帮助,以将列表的值分成两个变量。我的清单上有说明和代码。但是,我需要将描述放在一个变量中,将代码放在一个不同的变量中,所以我该如何实现。
我的代码是
private String[] selectedCertificates;
private List<SelectItem> Certificates;
public List<SelectItem> getCertificatesList(){
Certificates = new ArrayList<SelectItem>();
Certificates.add(new SelectItem("Certificate A","A"));
Certificates.add(new SelectItem("Certificate B","B"));
return bankCertificates;
}
public void setCertificates(List<SelectItem> Certificates) {
this.Certificates = Certificates;
}
// Setters and Getters
选择项目代码:
<p:selectManyCheckbox id="Certificates" value="#{user.selectedCertificates}"
layout="pageDirection" disabled="#{user.secondToggle}">
<f:selectItems value="#{user.Certificates}" var="bankCertificates"
itemLabel="#{user.CertificatesString}" itemValue="#{user.CertificatesCode}"/>
</p:selectManyCheckbox>
在哪里可以定义列表中的描述应该是第一个值,代码应该是第二个值,我可以在页面中使用它们。
谢谢
尝试
class SelectItem {
private String code;
private String description;
SelectItem (String code, String description) {
this.code = code;
this.description = description;
}
public String getCode () {
return code;
}
public String getDescription () {
return description;
}
}
这是你的主班
class MainClass {
public static void main (String...arg) {
//construct your list here using SelectItem class objects
List<SelectItem> certificates = = new ArrayList<SelectItem>();
certificates.add(new SelectItem("Certificate A","A"));
certificates.add(new SelectItem("Certificate B","B"));
//now first read the SelectItem objects you have added to the list
//or you can also iterate through the list, modify accordingly
SelectItem si1 = certificates.get(0);
//to read the code and description use the getters defined in SelectItem
si1.getCode(); si1.getDescription();
}
}
您也可以选择创建一种方法,可以将希望从列表中读取的索引传递给该方法。希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句