|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.faces.component Class UISelectMany
java.lang.Object javax.faces.component.UIComponent javax.faces.component.UIComponentBase javax.faces.component.UIOutput javax.faces.component.UIInput 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()
上执行以下逻辑:
- 基本类型数组(如
int[]
)。查找为此基本类型注册的按类转换的javax.faces.convert.Converter
。 - 对象数组(如
Integer[]
或String[]
)。查找为底层元素类型注册的按类转换的javax.faces.convert.Converter
。 java.util.List
。假定该元素类型为java.lang.String
,因此不需要转换。
使用下面的算法获取 javax.faces.convert.Converter
:
如果组件有连接的 javax.faces.convert.Converter
,则使用它。
如果没有,则查找 value
的 ValueExpression
(如果有)。ValueExpression
必须指向以下各项:
如果由于任何原因无法找到 Converter
,则假定类型为 String 数组。
使用选定的 javax.faces.convert.Converter
(如果有)将请求中的值数组或列表中的每个元素转换为正确的类型。如果组件的 value
有 ValueBinding
,则创建所需类型的数组来存放转换的值。如果组件的 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()
:
- An array of primitives (such as
int[]
). Look up the registered by-classConverter
for this primitive type. - An array of objects (such as
Integer[]
orString[]
). Look up the registered by-classConverter
for the underlying element type. - A
java.util.List
. Assume that the element type isjava.lang.String
, so no conversion is required.
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:
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 |
COMPONENT_FAMILY
The standard component family for this component. |
static String |
COMPONENT_TYPE
The standard component type for this component. |
static String |
INVALID_MESSAGE_ID
The message identifier of the FacesMessage to be created if
a value not matching the available options is specified. |
Fields inherited from class javax.faces.component.UIInput |
---|
CONVERSION_MESSAGE_ID, REQUIRED_MESSAGE_ID, UPDATE_MESSAGE_ID |
Fields inherited from class javax.faces.component.UIComponent |
---|
bindings |
Constructor Summary | |
---|---|
UISelectMany()
Create a new UISelectMany instance with default property
values. |
Method Summary | |
---|---|
protected boolean |
compareValues(Object previous,
Object value)
Return true if the new value is different from the
previous value. |
String |
getFamily()
Return the identifier of the component family to which this component belongs. |
Object[] |
getSelectedValues()
Return the currently selected values, or null if there
are no currently selected values. |
ValueBinding |
getValueBinding(String name)
Deprecated. this has been replaced by getValueExpression(java.lang.String) . |
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. |
void |
setSelectedValues(Object[] selectedValues)
Set the currently selected values, or null to indicate
that there are no currently selected values. |
void |
setValueBinding(String name,
ValueBinding binding)
Deprecated. This has been replaced by setValueExpression(java.lang.String, javax.el.ValueExpression) . |
void |
setValueExpression(String name,
ValueExpression binding)
Store any ValueExpression specified for
selectedValues under value instead;
otherwise, perform the default superclass processing for this method. |
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. |
Methods inherited from class javax.faces.component.UIOutput |
---|
getConverter, getLocalValue, getValue, setConverter |
Methods inherited from class javax.faces.component.UIComponentBase |
---|
addFacesListener, broadcast, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientId, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, getRendersChildren, invokeOnComponent, isRendered, isTransient, processRestoreState, processSaveState, queueEvent, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setRendererType, setTransient |
Methods inherited from class javax.faces.component.UIComponent |
---|
encodeAll, getContainerClientId |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface javax.faces.component.ValueHolder |
---|
getConverter, getLocalValue, getValue, setConverter |
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 appropriateRenderer
for this component instance.
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 forgetValue()
.
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 forsetValue()
.- Parameters:
selectedValues
- The new selected values (if any)
public ValueBinding
getValueBinding(String name)
如果请求 selectedValues
的 ValueBinding
,则返回任何为 value
设置的 ValueBinding
;否则,执行此方法的默认超类处理。
此方法依赖于超类将 ValueExpression
提供给 ValueBinding
包装。
name |
要为其获取 ValueBinding 的属性的名称 |
Throws | NullPointerException:
如果 name 为 null |
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 forvalue
if aValueBinding
forselectedValues
is requested; otherwise, perform the default superclass processing for this method.This method relies on the superclass to provide the
ValueExpression
toValueBinding
wrapping.- Overrides:
getValueBinding
in classUIComponentBase
- Parameters:
name
- Name of the attribute or property for which to retrieve aValueBinding
- Throws:
NullPointerException
- ifname
isnull
public void
setValueBinding(String name, ValueBinding binding)
存储 value
下为 selectedValues
指定的任何 ValueBinding
;否则,执行此方法的默认超类处理。
此方法依赖于超类来包装 ValueExpression
中的参数 ValueBinding
。
name |
要为其设置 ValueBinding 的属性的名称 |
binding |
要设置的 ValueBinding ,或为 null 以移除任何当前设置的 ValueBinding |
Throws | NullPointerException:
如果 name 为 null |
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 forselectedValues
undervalue
instead; otherwise, perform the default superclass processing for this method.This method relies on the superclass to wrap the argument
ValueBinding
in aValueExpression
.- Overrides:
setValueBinding
in classUIComponentBase
- Parameters:
name
- Name of the attribute or property for which to set aValueBinding
binding
- TheValueBinding
to set, ornull
to remove any currently setValueBinding
- Throws:
NullPointerException
- ifname
isnull
public ValueExpression
getValueExpression(String name)
如果请求 selectedValues
的 ValueExpression
,则返回任何为 value
设置的 ValueExpression
;否则,执行此方法的默认超类处理。
name |
要为其获取 ValueExpression 的属性的名称 |
Throws | NullPointerException:
如果 name 为 null |
since | 1.2 |
getValueExpression
public ValueExpression getValueExpression(String name)
Return any
ValueExpression
set forvalue
if aValueExpression
forselectedValues
is requested; otherwise, perform the default superclass processing for this method.- Overrides:
getValueExpression
in classUIComponent
- Parameters:
name
- Name of the attribute or property for which to retrieve aValueExpression
- Throws:
NullPointerException
- ifname
isnull
- Since:
- 1.2
public void
setValueExpression(String name, ValueExpression binding)
存储 value
下为 selectedValues
指定的任何 ValueExpression
;否则,执行此方法的默认超类处理。
name |
要为其设置 ValueExpression 的属性的名称 |
binding |
要设置的 ValueExpression ,或为 null 以移除任何当前设置的 ValueExpression |
Throws | NullPointerException:
如果 name 为 null |
since | 1.2 |
setValueExpression
public void setValueExpression(String name, ValueExpression binding)
Store any
ValueExpression
specified forselectedValues
undervalue
instead; otherwise, perform the default superclass processing for this method.- Overrides:
setValueExpression
in classUIComponent
- Parameters:
name
- Name of the attribute or property for which to set aValueExpression
binding
- TheValueExpression
to set, ornull
to remove any currently setValueExpression
- Throws:
NullPointerException
- ifname
isnull
- 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 classUIInput
- Parameters:
previous
- old value of this componentvalue
- new value of this component
protected void
validateValue(FacesContext context, Object value)
除继承自 UIInput
的标准验证行为外,还确保任何指定的值等于可用选项之一。在比较每个选项前,将根据 Expression 语言强制匹配规则强制匹配选项值类型与此组件值的类型。如果指定的值不等于任何选项,则将错误消息加入队列并将 valid
属性设置为 false
。
context |
当前请求的 FacesContext |
value | 要测试成员关系的转换值。 |
Throws | NullPointerException:
如果 context 为 null |
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 thevalid
property tofalse
.- Overrides:
validateValue
in classUIInput
- Parameters:
context
- TheFacesContext
for the current requestvalue
- The converted value to test for membership.- Throws:
NullPointerException
- ifcontext
isnull
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!