UISelectMany (Java EE 5)

Java EE API


javax.faces.component Class UISelectMany

java.lang.Object
  extended by javax.faces.component.UIComponent
      extended by javax.faces.component.UIComponentBase
          extended by javax.faces.component.UIOutput
              extended by javax.faces.component.UIInput
                  extended by javax.faces.component.UISelectMany
All Implemented Interfaces:
EditableValueHolder, StateHolder, ValueHolder
Direct Known Subclasses:
HtmlSelectManyCheckbox, HtmlSelectManyListbox, HtmlSelectManyMenu

public class UISelectMany
extends UIInput


UISelectMany 是表示用户从离散的可用选项集合中选择 0 或多个项的 UIComponent。用户可以修改选定的值。(可选)通过将 0 或多个当前选定项存储为该组件的 value 属性中的数组,可以使用它们预配置组件。

此组件通常呈现为一个选择框或一组复选框。

默认情况下,rendererType 属性必须设置为 "javax.faces.Listbox"。可以调用 setRendererType() 方法更改此值。

此组件的 javax.faces.render.Renderer 必须在 getConvertedValue() 上执行以下逻辑:

    使用下面的算法获取 javax.faces.convert.Converter

      如果组件有连接的 javax.faces.convert.Converter,则使用它。

      如果没有,则查找 valueValueExpression(如果有)。ValueExpression 必须指向以下各项:

      • 基本类型数组(如 int[])。查找为此基本类型注册的按类转换的 javax.faces.convert.Converter
      • 对象数组(如 Integer[]String[])。查找为底层元素类型注册的按类转换的 javax.faces.convert.Converter
      • java.util.List。假定该元素类型为 java.lang.String,因此不需要转换。

      如果由于任何原因无法找到 Converter,则假定类型为 String 数组。

    使用选定的 javax.faces.convert.Converter(如果有)将请求中的值数组或列表中的每个元素转换为正确的类型。如果组件的 valueValueBinding,则创建所需类型的数组来存放转换的值。如果组件的 value 没有 ValueBinding,则创建类型为 Object 的数组。将创建的数组存储为组件的本地值,将组件的 valid 状态设置为 true,然后返回。

英文文档:

UISelectMany is a UIComponent that represents the user's choice of a zero or more items from among a discrete set of available options. The user can modify the selected values. Optionally, the component can be preconfigured with zero or more currently selected items, by storing them as an array in the value property of the component.

This component is generally rendered as a select box or a group of checkboxes.

By default, the rendererType property must be set to "javax.faces.Listbox". This value can be changed by calling the setRendererType() method.

The Renderer for this component must perform the following logic on getConvertedValue():

    Obtain the Converter using the following algorithm:

      If the component has an attached Converter, use it.

      If not, look for a ValueExpression for value (if any). The ValueExpression must point to something that is:

      • An array of primitives (such as int[]). Look up the registered by-class Converter for this primitive type.
      • An array of objects (such as Integer[] or String[]). Look up the registered by-class Converter for the underlying element type.
      • A java.util.List. Assume that the element type is java.lang.String, so no conversion is required.

      If for any reason a Converter cannot be found, assume the type to be a String array.

    Use the selected Converter (if any) to convert each element in the values array or list from the request to the proper type. If the component has a ValueBinding for value, create an array of the expected type to hold the converted values. If the component does not have a ValueBinding for value, create an array of type Object. Store the created array as the local value of the component, set the component's valid state to true and return.


Field Summary
static String
static String
static String
 
Fields inherited from class javax.faces.component.UIInput
 
Fields inherited from class javax.faces.component.UIComponent
 
Constructor Summary
 
Method Summary
protected  boolean
 String
 Object[]
 ValueBinding
 ValueExpression
 void
 void
 void
protected  void
 
Methods inherited from class javax.faces.component.UIInput
 
Methods inherited from class javax.faces.component.UIOutput
 
Methods inherited from class javax.faces.component.UIComponentBase
 
Methods inherited from class javax.faces.component.UIComponent
 
Methods inherited from class java.lang.Object
 
Methods inherited from interface javax.faces.component.ValueHolder
 

Field Detail

英文文档:

COMPONENT_TYPE

public static final String COMPONENT_TYPE

The standard component type for this component.

See Also:
Constant Field Values


英文文档:

COMPONENT_FAMILY

public static final String COMPONENT_FAMILY

The standard component family for this component.

See Also:
Constant Field Values


英文文档:

INVALID_MESSAGE_ID

public static final String INVALID_MESSAGE_ID

The message identifier of the FacesMessage to be created if a value not matching the available options is specified.

See Also:
Constant Field Values

Constructor Detail

public UISelectMany()

使用默认属性值创建新的 UISelectMany 实例。

英文文档:

UISelectMany

public UISelectMany()

Create a new UISelectMany instance with default property values.

Method Detail

public String getFamily()
英文文档:

getFamily

public String getFamily()
Description copied from class: UIComponent

Return the identifier of the component family to which this component belongs. This identifier, in conjunction with the value of the rendererType property, may be used to select the appropriate Renderer for this component instance.

Overrides:
getFamily in class UIInput

public Object[] getSelectedValues()

返回当前选定的值,或如果没有当前选定的值,则返回 null。这是 getValue() 的类型安全别名。

英文文档:

getSelectedValues

public Object[] getSelectedValues()

Return the currently selected values, or null if there are no currently selected values. This is a typesafe alias for getValue().


public void setSelectedValues(Object[] selectedValues)

设置当前选定的值,或为 null 以指示没有当前选定的值。这是 setValue() 的类型安全别名。

selectedValues 新的选定值(如果有)
英文文档:

setSelectedValues

public void setSelectedValues(Object[] selectedValues)

Set the currently selected values, or null to indicate that there are no currently selected values. This is a typesafe alias for setValue().

Parameters:
selectedValues - The new selected values (if any)

public ValueBinding getValueBinding(String name)

如果请求 selectedValuesValueBinding,则返回任何为 value 设置的 ValueBinding;否则,执行此方法的默认超类处理。

此方法依赖于超类将 ValueExpression 提供给 ValueBinding 包装。

name 要为其获取 ValueBinding 的属性的名称
ThrowsNullPointerException: 如果 namenull
deprecated 此方法已由 #getValueExpression(java.lang.String) 替代。
英文文档:

getValueBinding

public ValueBinding getValueBinding(String name)
Deprecated. this has been replaced by getValueExpression(java.lang.String).

Return any ValueBinding set for value if a ValueBinding for selectedValues is requested; otherwise, perform the default superclass processing for this method.

This method relies on the superclass to provide the ValueExpression to ValueBinding wrapping.

Overrides:
getValueBinding in class UIComponentBase
Parameters:
name - Name of the attribute or property for which to retrieve a ValueBinding
Throws:
NullPointerException - if name is null

public void setValueBinding(String name, ValueBinding binding)

存储 value 下为 selectedValues 指定的任何 ValueBinding;否则,执行此方法的默认超类处理。

此方法依赖于超类来包装 ValueExpression 中的参数 ValueBinding

name 要为其设置 ValueBinding 的属性的名称
binding 要设置的 ValueBinding,或为 null 以移除任何当前设置的 ValueBinding
ThrowsNullPointerException: 如果 namenull
deprecated 此方法已由 #setValueExpression(java.lang.String, javax.el.ValueExpression) 替代。
英文文档:

setValueBinding

public void setValueBinding(String name,
                            ValueBinding binding)
Deprecated. This has been replaced by setValueExpression(java.lang.String, javax.el.ValueExpression).

Store any ValueBinding specified for selectedValues under value instead; otherwise, perform the default superclass processing for this method.

This method relies on the superclass to wrap the argument ValueBinding in a ValueExpression.

Overrides:
setValueBinding in class UIComponentBase
Parameters:
name - Name of the attribute or property for which to set a ValueBinding
binding - The ValueBinding to set, or null to remove any currently set ValueBinding
Throws:
NullPointerException - if name is null

public ValueExpression getValueExpression(String name)

如果请求 selectedValuesValueExpression,则返回任何为 value 设置的 ValueExpression;否则,执行此方法的默认超类处理。

name 要为其获取 ValueExpression 的属性的名称
ThrowsNullPointerException: 如果 namenull
since1.2
英文文档:

getValueExpression

public ValueExpression getValueExpression(String name)

Return any ValueExpression set for value if a ValueExpression for selectedValues is requested; otherwise, perform the default superclass processing for this method.

Overrides:
getValueExpression in class UIComponent
Parameters:
name - Name of the attribute or property for which to retrieve a ValueExpression
Throws:
NullPointerException - if name is null
Since:
1.2

public void setValueExpression(String name, ValueExpression binding)

存储 value 下为 selectedValues 指定的任何 ValueExpression;否则,执行此方法的默认超类处理。

name 要为其设置 ValueExpression 的属性的名称
binding 要设置的 ValueExpression,或为 null 以移除任何当前设置的 ValueExpression
ThrowsNullPointerException: 如果 namenull
since1.2
英文文档:

setValueExpression

public void setValueExpression(String name,
                               ValueExpression binding)

Store any ValueExpression specified for selectedValues under value instead; otherwise, perform the default superclass processing for this method.

Overrides:
setValueExpression in class UIComponent
Parameters:
name - Name of the attribute or property for which to set a ValueExpression
binding - The ValueExpression to set, or null to remove any currently set ValueExpression
Throws:
NullPointerException - if name is null
Since:
1.2

protected boolean compareValues(Object previous, Object value)

如果新值与以前的值不同,则返回 true。值比较不能对元素顺序敏感。

previous 此组件以前的值
value 此组件的新值
英文文档:

compareValues

protected boolean compareValues(Object previous,
                                Object value)

Return true if the new value is different from the previous value. Value comparison must not be sensitive to element order.

Overrides:
compareValues in class UIInput
Parameters:
previous - old value of this component
value - new value of this component

protected void validateValue(FacesContext context, Object value)

除继承自 UIInput 的标准验证行为外,还确保任何指定的值等于可用选项之一。在比较每个选项前,将根据 Expression 语言强制匹配规则强制匹配选项值类型与此组件值的类型。如果指定的值不等于任何选项,则将错误消息加入队列并将 valid 属性设置为 false

context 当前请求的 FacesContext
value 要测试成员关系的转换值。
ThrowsNullPointerException: 如果 contextnull
英文文档:

validateValue

protected void validateValue(FacesContext context,
                             Object value)

In addition to the standard validation behavior inherited from UIInput, ensure that any specified values are equal to one of the available options. Before comparing each option, coerce the option value type to the type of this component's value following the Expression Language coercion rules. If the specified value is not equal to any of the options, enqueue an error message and set the valid property to false.

Overrides:
validateValue in class UIInput
Parameters:
context - The FacesContext for the current request
value - The converted value to test for membership.
Throws:
NullPointerException - if context is null


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!