wxynxyo 发表于 2013-1-29 10:30:11

使用JSF <h:selectManyListbox>做的一个列表框

页面如下:
<div class="float-left" style="position:relative;"><h:selectManyListbox value="#{page.counterFirstNames}" size="10" immediate="true" id="firstName">   <f:ajax event="change" immediate="false" listener="#{page.getSecondName}"/>   <f:selectItems value="#{page.counterFirstNamesList}" /></h:selectManyListbox></div>
其中<f:selectItems value="#{page.counterFirstNamesList}" />为展示在列表框里面的LIST,counterFirstNamesList为List<SelectItem>并且存放的是SelectItem,构造方法为SelectItem(Object,String),如果每次只取一个值Object就放成String。注意f:selectItem 和 f:selectItems区别,少一个S就是报转型错误的。

<h:selectManyListbox value="#{page.counterFirstNames}"这个VALUE存放的是你点击的值,若多选考虑使用LIST或数组。(效果见附件)

使用f:ajax出发change事件,每次点击一个值,都会得到点击的值,LOG如下
12:56:06.578 INFO- c.d.s.w.m.XXXXBean: counterFirstNames length :112:56:06.578 INFO- c.d.s.w.m.XXXXBean: Accounting
页: [1]
查看完整版本: 使用JSF <h:selectManyListbox>做的一个列表框