--
PedroRio - 13 Jan 2011
XEO Web Components - Library
While
modelling the first Object Model for the XEO Library, you used XEO Studio's Scaffolding function to generate the Author viewers (list/edit/lookup) and also it addedd an automatic entry to our Main viewer (Main.xvw). From the previous chapter
you created a new Main viewer (Main_Library.xvw) and added and entry to that viewer; in this chapter you'all an entry to the list viewer of the Author Object Model, understand the component structure of a List/Edit and Lookup Viewer and add an icon to an Object Model.
Adding an icon to an Object Model
One thing that's visually very pleasant to users are icons. XEO Object Models can have an associated 16x16 gif icon that will be displayed in certain situation automatically (or can be manually displayed as well, as will be showed next).Start by
downloading the following icon 
. In the default web application of the XEO Library application you'll find a folder named "Resources" (it should be empty), the Resources folder is where XEO will search for icon's associated with XEO Object Models. Inside that folder, one folder per Object Model can be created to store the Model's icon, for this example create a LIB_Author folder and copy the downloaded file to that folder (be sure that it's named ico16.gif).
For now this will be all, you'll later in this chapter where the icon will be shown automatically and in the next section how to display it manually.
Adding an entry for the author list viewer
Open the previously created Main_Library.xvw viewer and replace the xvw:menu component for the
MyViewer viewer with the following:
<xvw:menu text='Authors'
value="{viewerName:'LIB_Author/list.xvw', boql:select LIB_Author}"
target='Tab' serverAction="#{viewBean.listObject}" icon='resources/LIB_Author/ico16.gif' />
Let's explain the xvw:menu component a bit. The xvw:menu component is a generic component for creating buttons with an action, it can be used in tree panels, as well as in toolbars to create button. It has a
text property which is the label displayed, a
target property which allows to choose where the action of the menu will be presented (in a main viewer it's usually as a tab), the
icon property which will render an icon next to the menu's label, a
serverAction property which is the action to be invoked from the
XEOMainBean (or any custom bean extending that bean). For a list viewer that method will most probably be the "listObject" method, as that method is prepared to open the list viewer and receive parameters through the
value property of the menu component. In this example we're passing a
JSON object with two attributes, the name of the viewer (LIB_Author/list.xvw) and the BOQL (XEOQL) expression to select the desired instances. The
value property can also have more attributes which will be explained when needed.
The previous instructions have all the required steps to add a Main viewer entry to display a list viewer (the icon is optional, naturally), and you'll replicate them when adding the remaing list viewer entries.
Launch the project and login as usual and then click on the "Authors" entry in the main menu, the result should be the like the one depicted in figure XWCLib.1 .Notice how the tab title and the button with "New" have the authors icon right beside the label, this is one of the things XEO makes automatically (if it finds the ico16.gix file in the resources directory (in a folder with the XEO Model's name).
Figure XWCLib.1 - Main viewer with entry for the Authors List Viewer (and List viewer open)
Understanding a List Viewer
Next let's examine the list viewer, to better understand its structure. Open the list viewer for LIB_Author (under webapps/default/viewers/LIB_Author), the code generated by the scaffolding tool is the following:
<xvw:root
xmlns:xvw="http://www.netgest.net/xeo/xvw"
xmlns:xeo="http://www.netgest.net/xeo/xeo"
>
<xvw:viewer beanClass="netgest.bo.xwc.xeo.beans.XEOBaseList" beanId="viewBean">
<xeo:formList>
<xeo:list>
<xvw:columns>
<xvw:columnAttribute width="100" dataField="name"/>
</xvw:columns>
</xeo:list>
</xeo:formList>
</xvw:viewer>
</xvw:root>
Just like explained in the previous chapter we have the
xvw:root and
xvw:viewer components, the last one with a
beanClass property with a value netgest.bo.xwc.xeo.beans.XEOBaseList which is the XEO framework's bean associated with List Viewers. The
xeo:formList component is a form that extends the
xvw:form component an is designed to deal with lists of object model instances (hence the
xeo prefix as explained in the previous chapter). A xeo:formList component also includes a default toolbar with the "New" button, to open an edit viewer allowing to create a new instance. As you can imagine, there are
xeo:formEdit and
xeo:formLookupList components for the corresponding viewers.
The
xeo:list component is a extension of the more generic
xvw:gridPanel, a component to display paginated lists of items, with the ability to show multiple columns and order the results by column, as well as searching through the results, grouping results by a certain column and exporting results to an Excel spreadsheet or a PDF file (the list component has a navigational bar at the bottom with the buttons to export the contents to PDF/Excel as well as navigating through the pages of results). A list viewer is essentially a
xeo:list component, which can be configured with a set of columns; in order to configure the columns, you'll need to add a
xvw:columns component as a child of a
xeo:list component. To add a new column to a list, you use the
xvw:columnAttribute component. The only required property of the component is the dataField. The dataField property tells the list component from where to select the values to display in that column and in a list component the value for the dataField property is the name of an attribute of the object model. In this example the only column attribute uses as a dataField the
name attribute of the Author Object Model.
Using and Understanding the Edit Viewer
Since the list viewer includes a "New" button, to create a new instance, you can create a new instance of Author. Press the "New" button and a new tab with a form having a set of buttons in a toolbar and a section with fields to edit the attributes of an author (in this case, just the name, which is a required attribute), as depicted in figure XWC.Lib2. An edit viewer provides a default toolbar with the following entries: Save, Save and Close, Delete, Validate and Show Properties (see the menus depicted from right to left in figure XWCLib.2)
XWCLib.2 - Edit viewer for the Author
Fill the name attribute with "John Doe" and press the "Save and close" button (second from the left in the toolbar) which will show a message that your data was sucessfully saved and will close the current tab.
Notice that the list of authors does not show any author, despite creation of the first author. A list viewer tries to be conversative when loading data to increase the performance of the application, thus, to see the newly created instance click the "Reload" button in the navigational bar (left of the Excel button in the bottom of the list viewer). If you do that, the "John Doe" instance will appear in the list.
If you open the edit.xvw viewer for the LIB_Author Object Model you'll see the following XML definition:
<xvw:root xmlns:xvw="http://www.netgest.net/xeo/xvw" xmlns:xeo="http://www.netgest.net/xeo/xeo">
<xvw:viewer beanClass="netgest.bo.xwc.xeo.beans.XEOEditBean" beanId="viewBean">
<xeo:formEdit>
<xvw:panel>
<xvw:section label='Geral'>
<xvw:rows>
<xvw:row>
<xvw:cell>
<xvw:attribute objectAttribute="name"/>
</xvw:cell>
</xvw:row>
</xvw:rows>
</xvw:section>
</xvw:panel>
</xeo:formEdit>
</xvw:viewer>
</xvw:root>
As with the list viewer, the
xvw:root and
xvw:viewer components are present, but in this case the bean to connect to the viewer is the
XEOEditBean (netgest.bo.xwc.xeo.beans.XEOEditBean). As before, there's a special type of form component (the xeo:formEdit) component which has a default toolbar component with the common operations for an object model instance (save, save and close, destroy, validate, etc...), depicted in figure XWCLib.2.
AAA
aaa
aaa