--
PedroRio - 30 Dec 2010
BridgeHandler - Handler for a collection attribute
The
bridgeHandler class is a handler for collection attributes. It allows to iterate through the collection, add new elements to the collection, remove elements and re-order the elements inside the collection (
elements in XEO's collections are ordered). Bellow is the list of methods that allow interaction with a collection attribute
Definition
Methods in these category allow to query the Object Model definition for the given collection attribute
Method name |
Description |
Parameters |
Return type |
Notes |
getName |
Retrieves the name of the collection attribute (as declared in the Object Model) |
- |
String |
|
getDefAttribute |
Retrieves the handler for the Object Model definition of the collection attribute |
- |
boDefAttribute |
|
_
Iteration
Iteration methods allow to iterate through elements of the collection as well as interacting with the content of the collection. As explained before, the collection attribute contains an ordered list of elements and can be iterated from the first to the last element (collection attributes are not paged, like
boObjectList instances).
Method name |
Description |
Parameters |
Return type |
Notes |
beforeFirst |
Resets the iterator to the beginning of the collection (before the first position of the collection, so that a call to next() will return the first element) |
- |
void |
Issuing a beforeFirst() command on the iterator allows to issue a next() command afterwards and retrieve the first element |
first |
Positions the iterator in the first position of the collection |
- |
void |
|
last |
Positions the iterator in the last position of the collection |
- |
void |
|
next |
Advances the iterator to the next position of the collection |
- |
boolean |
If no more elements are available in the iterator this method returns false |
getObject |
Retrieves the boObject instance in the current position of the iterator |
- |
boObject |
Throws runtime exception1 |
isEmpty |
Checks whether the collection is empty or not |
- |
boolean |
|
truncate |
Removes all elements from the collection (final size is zero) |
- |
void |
|
moveTo |
Moves the iterator the desired position (passed as parameter) |
int line |
boolean |
Returns whether or not the iterator was moved to the desired position |
moveRowTo |
Moves the current element to a specified position |
int position |
void |
This method will trigger the onBeforeChangeOrder and onAfterChangeOrder events in any collection attribute that defines them. |
addNewObject |
Creates a new boObject instance adds it to the bridge and returns a reference to it. |
String objectName |
boObject |
|
getEboContext |
Retrieves an EboContext instance |
- |
EboContext |
|
getParent |
Retrieves the boObject instance which own the collection attribute |
- |
boObject |
|
_
Behavior
Collection attributes, like non-collection attributes, have associated behavior which can be invoked/queried through the API. The following methods are available:
Method name |
Description |
Parameters |
Return type |
Notes |
required |
Whether the attribute is required or not (executes user code if it's defined) |
- |
boolean |
|
disableWhen |
Whether the attribute is disabled or not (executes user code if it's defined) |
- |
boolean |
|
|
|
|
|
|
valid()-
Não funciona
hiddenWhen() -
Não funciona
defaultValue() -
Não funciona
formula() -
Não funciona
_
Sample Code : Iterating through a collection attribute and updating the objects
_
boObject obj = ... //loadObject;
//Retrieve the bridge
bridgeHandler collectionHandler = obj.getBridge("collectionAttributeName");
boBridgeIterator it = collectionHandler.iterator();
//Iterate through all elements
while (it.next()){
try {
//Retrieve the current object
boObject current = it.currentRow().getObject();
//Change a value and update
current.getAttribute("foo").setValueString("bar");
current.update();
} catch (boRuntimeException e) {
//Deal with the exception
}
}
_