|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.click.util.ContainerUtils
public class ContainerUtils
Provides Container access and copy utilities.
Constructor Summary | |
---|---|
ContainerUtils()
|
Method Summary | |
---|---|
static void |
copyContainerToObject(Container container,
Object object)
Populate the given object attributes from the Containers field values. |
static void |
copyContainerToObject(Container container,
Object object,
List fieldList)
Populate the given object attributes from the Containers field values. |
static void |
copyObjectToContainer(Object object,
Container container)
Populate the given Container field values from the object attributes. |
static void |
copyObjectToContainer(Object object,
Container container,
List fieldList)
Populate the given Container field values from the object attributes. |
static Control |
findControlByName(Container container,
String name)
Find and return the first control with a matching name in the specified container. |
static Form |
findForm(Control control)
Find and return the specified controls parent Form or null if no Form is present. |
static List |
getButtons(Container container)
Return the list of Buttons for the given Container, recursively including any Fields contained in child containers. |
static List |
getErrorFields(Container container)
Return a list of container fields which are not valid, not hidden and not disabled. |
static Map |
getFieldMap(Container container)
Return a map of all Fields for the given Container, recursively including any Fields contained in child containers. |
static List |
getFields(Container container)
Return the list of Fields for the given Container, recursively including any Fields contained in child containers. |
static List |
getFieldsAndLabels(Container container)
Return the list of Fields for the given Container, recursively including any Fields contained in child containers. |
static List |
getHiddenFields(Container container)
Return the list of hidden Fields for the given Container, recursively including any Fields contained in child containers. |
static List |
getInputFields(Container container)
Return the list of input Fields (TextField, Select, Radio, Checkbox etc). |
static Control |
insert(Container container,
Control control,
int index,
Map controlMap)
Add the given control to the container at the specified index, and return the added instance. |
static boolean |
remove(Container container,
Control control,
Map controlMap)
Remove the given control from the container, returning true if the control was found in the container and removed, or false if the control was not found. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ContainerUtils()
Method Detail |
---|
public static void copyContainerToObject(Container container, Object object, List fieldList)
Field.getValueObject()
. If an object
attribute is a primitive, the Object returned from
Field.getValueObject()
will be converted
into the specific primitive e.g. Integer will become int and Boolean will
become boolean.
The fieldList specifies which fields to copy to the object. This allows
one to include or exclude certain Container fields before populating the
object.
The following example shows how to exclude disabled fields from
populating a customer object:
public void onInit() { List formFields = new ArrayList(); for(Iterator it = form.getFieldList().iterator(); it.hasNext(); ) { Field field = (Field) formFields.next(); // Exclude disabled fields if (!field.isDisabled()) { formFields.add(field); } } Customer customer = new Customer(); ContainerUtils.copyContainerToObject(form, customer, formFields); }The specified Object can either be a POJO (plain old java object) or a
Map
. If a POJO is specified, its attributes are
populated from matching container fields. If a map is specified, its
key/value pairs are populated from matching container fields.
container
- the fieldList Containerobject
- the object to populate with field valuesfieldList
- the list of fields to obtain values from
IllegalArgumentException
- if container, object or fieldList is
nullpublic static void copyContainerToObject(Container container, Object object)
container
- the Container to obtain field values fromobject
- the object to populate with field valuescopyContainerToObject(org.apache.click.control.Container, java.lang.Object, java.util.List)
public static void copyObjectToContainer(Object object, Container container, List fieldList)
Field.setValueObject(java.lang.Object)
. If
an object attribute is a primitive it is first converted to its proper
wrapper class e.g. int will become Integer and boolean will become
Boolean.
The fieldList specifies which fields to populate from the object. This
allows one to exclude or include specific fields.
The specified Object can either be a POJO (plain old java object) or
a Map
. If a POJO is specified, its attributes are
copied to matching container fields. If a map is specified, its key/value
pairs are copied to matching container fields.
object
- the object to obtain attribute values fromcontainer
- the Container to populatefieldList
- the list of fields to populate from the object
attributespublic static void copyObjectToContainer(Object object, Container container)
object
- the object to obtain attribute values fromcontainer
- the Container to populatecopyObjectToContainer(java.lang.Object, org.apache.click.control.Container, java.util.List)
public static Control findControlByName(Container container, String name)
container
- the container that is searched for a control with a
matching namename
- the name of the control to find
public static Form findForm(Control control)
control
- the control to check for Form
public static List getButtons(Container container)
container
- the container to obtain the buttons from
public static List getErrorFields(Container container)
container
- the container to obtain the invalid fields from
public static Map getFieldMap(Container container)
container
- the container to obtain the fields from
public static List getFields(Container container)
container
- the container to obtain the fields from
public static List getFieldsAndLabels(Container container)
container
- the container to obtain the fields from
public static List getHiddenFields(Container container)
container
- the container to obtain the fields from
public static List getInputFields(Container container)
container
- the container to obtain the fields from
public static Control insert(Container container, Control control, int index, Map controlMap)
Container
interface but cannot for one
reason or another extend from AbstractContainer
.
For example if the Container already extends from an existing Control
such as a Field, it won't be possible to extend
AbstractContainer as well. In such scenarios instead of
reimplementing insert
,
one can delegate to this method.
For example, a custom Container that extends Field and
implements Container could implement the insert method
as follows:
public class MyContainer extends Field implements Container { public Control insert(Control control, int index) { return ContainerUtils.insert(this, control, index, getControlMap()); } ... }
container
- the container to insert the given control intocontrol
- the control to add to the containerindex
- the index at which the control is to be insertedcontrolMap
- the container's map of controls keyed on control name
IllegalArgumentException
- if the control is null or if the control
and container is the same instance or the container already contains
a control with the same name or if a Field name is not defined
IndexOutOfBoundsException
- if index is out of range
(index < 0 || index > container.getControls().size())public static boolean remove(Container container, Control control, Map controlMap)
Container
interface but cannot for one
reason or another extend from AbstractContainer
.
For example if the Container already extends from an existing Control
such as a Field, it won't be possible to extend
AbstractContainer as well. In such scenarios instead of
reimplementing remove
,
one can delegate to this method.
For example, a custom Container that extends Field and
implements Container could implement the remove method
as follows:
public class MyContainer extends Field implements Container { public boolean remove (Control control) { return ContainerUtils.remove(this, control, getControlMap()); } ... }
container
- the container to remove the given control fromcontrol
- the control to remove from the containercontrolMap
- the container's map of controls keyed on control name
IllegalArgumentException
- if the control is null
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |