Jsf 如何在h:selectOneListbox中设置标签?

Jsf 如何在h:selectOneListbox中设置标签?,jsf,listbox,label,Jsf,Listbox,Label,我必须显示一个标签为“name”的列表框&我使用的是h:selectOneListbox 我的代码是: <h:selectOneListbox id="select" value"#{trial.trials}" size="1" title="Select Item..."> <f:selectItems value="#{trial.trials}/> </h:selectOneListbox> 你可以这样用。我不确定它是否会工作,因为我使用了标记,它

我必须显示一个标签为“name”的列表框&我使用的是h:selectOneListbox

我的代码是:

<h:selectOneListbox id="select" value"#{trial.trials}" size="1" title="Select Item...">
<f:selectItems value="#{trial.trials}/>
</h:selectOneListbox>


你可以这样用。我不确定它是否会工作,因为我使用了
标记,它工作得非常好

<ice:selectOneListbox 
    id="paymnent" rows="10" tabindex="4"
    value="#{paymentVoucherReportAction.reportType}"
    style="width: 200px;height: 20px;">
    <f:selectItems id="AutoCmpTasdfasdfasdxtItms11"
        value="#{paymentVoucherReportAction.lstKeyValueData}" />
</ice:selectOneListbox>

//Bean(操作)文件

private List lstKeyValueData=new ArrayList();//getter+setter
私有字符串reportType;//getter+setter
//把它放在init方法中
ListList=newarrayList();
添加(新选择项(“PDF格式”、“PDF格式”);
添加(新选择项(“XLS格式”、“XLS格式”);
setLstKeyValueData(列表);
//把这个打印到你想要的地方
System.out.println(报表类型);

在JSF 1.x中,您需要基于您的
列表创建一个
列表。的构造函数可以将选项值作为第一个参数,将选项标签作为第二个参数

public class Bean {

    private Trial selectedTrial;
    private List<Trial> trials;
    private List<SelectItem> selectTrials;

    public Bean() {
        trials = loadItSomehow();
        selectTrials = new ArrayList<SelectItem>();
        for (Trial trial : trials) {
            selectTrials.add(new SelectItem(trial, trial.getName()));
        }
    }

    // ...
}

刚刚从JSF1切换到JSF2,并且喜欢h:selectOneListbox上的新var属性。你知道我是否可以以及如何处理双击一个项目吗?我正在遵循你(BalusC)为JSF2所做的操作,但是当我检查chrome中的元素时,我的每个选项都将整个列表作为其值。这是我的代码:Java私有连接用户连接到删除;连接用户的私有列表;在表单提交中,我想从
已连接用户
列表中删除连接。JSP:@edhedges:那么您实际上没有使用JSF2.x,或者由于配置不正确,您正在JSF1.x回退模式中运行JSF2.x。
    private List<SelectItem> lstKeyValueData = new ArrayList<SelectItem>(); // getter + setter

    private String reportType;  // getter + setter

    // put this in your init method

    List< SelectItem> list = new ArrayList< SelectItem>();

    list.add(new SelectItem("PDF Format","PDF Format"));

    list.add(new SelectItem("XLS Format","XLS Format"));

    setLstKeyValueData(list);

  // print this where you want

   System.out.println(reportType);
public class Bean {

    private Trial selectedTrial;
    private List<Trial> trials;
    private List<SelectItem> selectTrials;

    public Bean() {
        trials = loadItSomehow();
        selectTrials = new ArrayList<SelectItem>();
        for (Trial trial : trials) {
            selectTrials.add(new SelectItem(trial, trial.getName()));
        }
    }

    // ...
}
<h:selectOneListbox value="#{bean.selectedTrial}" converter="trialConverter">
    <f:selectItems value="#{bean.selectTrials}" />
</h:selectOneListbox>
<h:selectOneListbox value="#{bean.selectedTrial}" converter="trialConverter">
    <f:selectItems value="#{bean.trials}" var="trial"
        itemValue="#{trial}" itemLabel="#{trial.name}" />
</h:selectOneListbox>