Xoetrope
HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
XUI 4.0

XPojoIterator


XPojoIterator is a special model node that handles an iteration over POJO arrays and collections. The iterator by default is assigned to each array/collection and placed under the "iterator" subpath. For example: if pojo/allUsers path points to a XPojoModel node encapsulating either an array or collection then the associated iterator is located at the pojo/allUsers/iterator path.

The iterator exposes four methods:
- first() - moves the iteration to the first element of the underlying collection/array.
- last() - moves the iteration to the last element of the underlying collection/array.
- next() - moves the iteration to the next element of the underlying collection/array.
- prev() - moves the iteration to the previous element of the underlying collection/array.

Each of the methods above can be invoked be evaluating the ...iterator/[method_name] path, e. g. pojo/allUsers/iterator/next(), pojo/allUsers/iterator/prev(), etc.

Properties of the iteration's current element (POJO) are available under ...iterator/[property_name] paths, e.g. pojo/allUsers/iterator/firstname points to a POJO model node wrapping the current user's firstname. Combining this with a facility to bind action events to POJO methods allows to create "UI iterators" over arrays and collection with no user code needed. A simple example of that could be as follows:

<XPage>

  <Components>
    <Label name="firstnameLabel"/>
    <Label name="secondnameLabel"/>
    <Button name="nextUserButton" text="next user"/>
    <Button name="prevUserButton" text="previous user"/>
  </Components>
 
  <Events>
    <Event method="pojo/allUsers/iterator/next()" target="nextUserButton" type="ActionHandler"/>
    <Event method="pojo/allUsers/iterator/prev()" target="prevUserButton" type="ActionHandler"/>
  </Events>
 
  <Data>
    <Bind target="firstnameLabel" source="pojo/allUsers/iterator/firstname"/>
    <Bind target="secondnameLabel" source="pojo/allUsers/iterator/lastname"/>
  <Data>
 
</XPage>

There are no comments on this page. [Add comment]

Page was generated in 0.5838 seconds