30.38. <w:multiSelect>

MultiSelect提供一种可以多选的列表,与h:selectManyListBox功能类似。

30.38.1. 构件信息

表 30.96. 构件信息

Component Type org.operamasks.faces.component.form.impl.UIMultiSelect
Component Family javax.faces.Input
Component Class org.operamasks.faces.component.form.impl.UIMultiSelect
Tag Class org.operamasks.faces.webapp.form.UIMultiSelectTag
Renderer Type org.operamasks.faces.component.form.impl.UIMultiSelect
Renderer Class(AJAX) org.operamasks.faces.render.widget.ajax.AjaxMultiSelectRenderer

继承体系

+java.lang.Object

++javax.faces.component.UIComponent

+++javax.faces.component.UIComponentBase

++++javax.faces.component.UIOutput

+++++javax.faces.component.UIInput

++++++org.operamasks.faces.component.form.base.UIFieldBase

+++++++org.operamasks.faces.component.form.impl.UIField

++++++++org.operamasks.faces.component.form.base.UITextFieldBase

+++++++++org.operamasks.faces.component.form.impl.UITextField

++++++++++org.operamasks.faces.component.form.base.UIMultiSelectBase

+++++++++++org.operamasks.faces.component.form.impl.UIMultiSelect

30.38.2. 属性

表 30.97. 属性

allowBlank 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
是否允许为空 (默认是true)
alwaysSubmit 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(boolean)
是否必须 延时求值
构件是否总是提交,与readOnly,disabled属性结合使用。 当一个输入组件的readOnly或disabled设为true时,它的值无法提交到后台。 但如果同时将alwaysSubmit设为true,则它的值可以提交到后台
appendOnly 定义类 org.operamasks.faces.component.form.impl.UIMultiSelect
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
当ddReorder=true时是否只能拖动到末端(默认值:false)
binding 定义类 javax.faces.component.UIComponentBase
类型 javax.el.ValueExpression(javax.faces.component.UIComponent)
是否必须 延时求值
一个值表达式,用于把该组件链接到一个ManagedBean的某个属性。
blankText 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当设置不允许为空而文本框的内容是空的时候,出错提示的内容
clientValidate 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
构件是否进行客户端校验
cls 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的css样式类名
converter 定义类 javax.faces.component.UIOutput
类型 java.lang.String
是否必须 延时求值
构件注册的转换器
converterMessage 定义类 javax.faces.component.UIInput
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件中值转换失败时,构件的提示信息
ddReorder 定义类 org.operamasks.faces.component.form.impl.UIMultiSelect
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
是否支持项的可拖动位置(默认值:false)
delimiter 定义类 org.operamasks.faces.component.form.impl.UIMultiSelect
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当选择多个值时中间的分隔符(默认值:',')
disabled 定义类 org.operamasks.faces.component.form.base.UIFieldBase
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
构件是否设置为disabled(默认值:false),disabled属性设置为true后,需设置alwaysSubmit="true",页面值才会提交
emptyClass 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当文本框内容为空时的样式(默认是'x-form-empty-field')
emptyText 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当文本框内容为空时显示的文本(默认是null)
fieldClass 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
field的默认样式(默认值:"x-form-field")
fieldLabel 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的label
focusClass 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当field收到焦点时的样式(默认值:"x-form-focus")
grow 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
是否允许构件的长度随其内容自动增长和收缩
growMax 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
当grow属性为true是构件允许宽度的最大值(默认值为800)
growMin 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
当grow属性为true是构件允许宽度的最小值(默认值为30)
height 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
构件的高度,以象素为单位。
hidden 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
构件是否可见。
hideLabel 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
是否完全隐藏构件的label(默认值:false)
id 定义类 javax.faces.component.UIComponentBase
类型 java.lang.String
是否必须 延时求值
这个组件的组件标识符。这个值在最近的命名容器类型的父组件范围内,必须是唯一的。
immediate 定义类 javax.faces.component.UIInput
类型 javax.el.ValueExpression(boolean)
是否必须 延时求值
如果该属性设置为true,该构件的校验和转换就会在应用请求值阶段进行,反之,在处理验证阶段执行
initConfig 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
初始化对象,取值可以是ExtConfig对象, 或String,表示一个JavaScript对象,比如:{"a": "avalue", "b":true, "c":200, "d":"var::dvalue"} 如果取值是表示一个JavaScript对象的String,则key必须用(双)引号包起来,比如"a"。
inputType 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
field的类型
invalidClass 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当field被标记为invalid时的样式(默认值:"x-form-invalid")
jsvar 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
客户端脚本使用的javascript变量名,使用此变量名可以在客户端脚本中引用构件对应的客户端对象
labelSeparator 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
显示在label后面的分隔符(默认值:':')。
labelStyle 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
field的label的CSS样式(默认值:如果设置了父容器的labelStyle就使用父容器的labelStyle,否则为'')
maskRe 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
用来限制用户输入的字符类型的正则表达式,只有敲入的字符符合正则表达式时,才显示出来 (默认是null)
maxLength 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
当文本框内容的最大长度
maxLengthText 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当文本框内容的长度大于设置的最大长度值时,出错提示的内容
maxSelections 定义类 org.operamasks.faces.component.form.impl.UIMultiSelect
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
最多选择几个选项(默认值:Integer.MAX_VALUE)
maxSelectionsText 定义类 org.operamasks.faces.component.form.impl.UIMultiSelect
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当选择的项数多于maxSelections时的提示文本
minLength 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
文本框内容的最小长度 (默认是0)
minLengthText 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当文本框内容的长度小于设置的最小长度值时,出错提示的内容
minSelections 定义类 org.operamasks.faces.component.form.impl.UIMultiSelect
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
最少选择几个选项(默认值:0)
minSelectionsText 定义类 org.operamasks.faces.component.form.impl.UIMultiSelect
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当选择的项数少于minSelections时的提示文本
msgTarget 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
错误信息文本的显示位置
onblur 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onblur事件发生(构件失去输入焦点时触发)时执行的JavaScript代码
onchange 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onchange事件发生(内容改变时触发)时执行的JavaScript代码
onclick 定义类 org.operamasks.faces.component.form.impl.UIMultiSelect
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onclick事件发生(构件被单击)时执行的JavaScript代码
ondblclick 定义类 org.operamasks.faces.component.form.impl.UIMultiSelect
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onclick事件发生(构件被双击)时执行的JavaScript代码
ondisable 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的ondisable事件发生(构件变为无效时触发)时执行的JavaScript代码
ondrop 定义类 org.operamasks.faces.component.form.impl.UIMultiSelect
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onclick事件发生(构件内容项被拖动)时执行的JavaScript代码
onenable 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onenable事件发生(构件变为有效时触发)时执行的JavaScript代码
onfocus 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onfocus事件发生(构件获取焦点时触发)时执行的JavaScript代码
onhide 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onhide事件发生(构件隐藏时触发)时执行的JavaScript代码
onkeydown 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onkeydown事件发生(键盘按下时触发)时执行的JavaScript代码
onkeypress 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onkeypress事件发生(键盘按下时触发)时执行的JavaScript代码
onkeyup 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onkeyup事件发生(键盘抬起时触发)时执行的JavaScript代码
onshow 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件的onshow事件发生(构件显示时触发)时执行的JavaScript代码
readOnly 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
是否在HTML中将field标识为readOnly(默认值:false),readOnly属性设置为true后,需设置alwaysSubmit="true",页面值才会提交。此属性暂不支持w:simpleHtmlEditor、w:radioGroup、w:checkBoxGroup
regex 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
用于验证时测试域值的一个JavaScript RegExp对象,允许使用Perl风格的语法。如果提供了该属性值,这个正则表达式仅当基本Ext验证器都返回true时被调用,调用时会传给它当前的域值。如果测试失败,这个域将用regexText指定的文本标记为不合法
regexText 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
regex属性校验失败后,出错提示的内容
rendered 定义类 javax.faces.component.UIComponentBase
类型 boolean(boolean)
是否必须 延时求值
一个标志,指出该组件是否要在任何随后的form提交过程中被渲染或处理。 这个属性的缺省值是true。
required 定义类 javax.faces.component.UIInput
类型 javax.el.ValueExpression(boolean)
是否必须 延时求值
构件是否不允许提交空值
requiredMessage 定义类 javax.faces.component.UIInput
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当requried属性为真,构件如果提交了空值导致校验失败时构件的提示信息
requiredTrim 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(boolean)
是否必须 延时求值
构件进行required校验时是否将输入的值作trim操作后校验
selectOnFocus 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
当获得焦点的时候,选中所有文本(默认是false)
style 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件渲染后最外层DOM元素的样式。
styleClass 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件渲染后最外层DOM元素的样式类名。若有多个,以空格分隔。
tabIndex 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
当用户使用tab键时页面上构件获得焦点的顺序索引
tooltip 定义类 org.operamasks.faces.component.form.base.UIFieldBase
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
鼠标经过时的弹出信息。
validateEvents 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
构件客户端校验发生的时机
validator 定义类 javax.faces.component.UIInput
类型 javax.el.MethodExpression(javax.el.MethodExpression)
是否必须 延时求值
指定一个校验器id或用EL表达式指定一个校验方法。引擎使用该校验器对用户输入进行有效性校验
validatorMessage 定义类 javax.faces.component.UIInput
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
校验失败时的提示信息
value 定义类 javax.faces.component.UIInput
类型 java.lang.String
是否必须 延时求值
构件的当前值
valueChangeListener 定义类 javax.faces.component.UIInput
类型 javax.el.MethodExpression(javax.el.MethodExpression)
是否必须 延时求值
该属性为一个EL表达式(MethodBinding),表示当值改变时响应事件的方法。表达式所指定的方法必须是void valueChange(javax.faces.event.ValueChangeEvent)形式
vtype 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
输入值的验证类型,取值为alpha,alphanum,email,url
vtypeText 定义类 org.operamasks.faces.component.form.impl.UITextField
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
当输入值类型验证失败时显示的信息
width 定义类 org.operamasks.faces.component.form.impl.UIField
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
构件的宽度,以象素为单位。

30.38.3. 示例

下面的例子演示了多项选择器的使用方法。其选择项可以通过页面指定(如本例所示),也可以后台指定;既可以使用多个f:selectItem实现,也可以用一个f:selectItems实现,也可以混合使用(如本例所示)

<w:form>
			<w:multiSelect id="multi" width="200" height="120" ddReorder="true">
				<f:selectItem id="item1" itemValue="1" itemLabel="one" />
				<f:selectItems id="items" />
				<f:selectItem id="item2" itemValue="4" itemLabel="four" />
				<f:selectItem id="item3" itemValue="5" itemLabel="five" />
			</w:multiSelect>
			<br/>
			<h:outputText id="result" />
			<w:button id="submit" value="提交" />
		</w:form>

ManagedBean:

@ManagedBean(name = "ux.multiSelector.multiSelectorBean", scope = ManagedBeanScope.REQUEST)
public class MultiSelectorBean {
    @Bind
    private SelectItem[] items =
        new SelectItem[] { new SelectItem(2, "two"), new SelectItem(3, "three") };
    @Bind
    private String result;
    @Bind
    private UIMultiSelect multi;
    @Action(id = "submit")
    public void submit() {
        result = "您提交的值为:" + multi.getValue().toString();
    }
}