|
Components
A view is composed of components, namely the table, row and column. The attributes of each component represent the features that are valid across multiple renderers. If you remember, each view defines their own components. For the purpose of this article I will also talk about the Html components and their attributes as they are used more often. For the other views see the javadocs to find out the various component specific attributes and how to use them. TableThe common attributes of all tables, regardless of the view, are caption, row, and tableRenderer. caption and captionKeyThe caption is used to give the table a name. Almost all views will display the caption above the table.
table.setCaption("Presidents");
<jmesa:table caption="Presidents"> If you are using the Messages then use the alternate caption method.
table.setCaptionKey("table.presidents");
<jmesa:table captionKey="table.presidents"> rowThe row defines the Row used for the table. Each table has one Row associated with it that represents all the rows in a table.
table.setRow(row);
<jmesa:row> Can set global filterable and sortable attributes on the row. Also have the ability to override the row settings on a column by column basis.
row.setFilterable(true); row.setSortable(true);
<jmesa:row filterable="true" sortable="true"> tableRendererThe tableRenderer defines the TableRenderer used for the table. See the TableRenderer in the Renderers article for more information.
table.setTableRenderer(tableRenderer);
<jmesa:table tableRenderer="com.mycompany.renderer.MyTableRenderer"> HtmlTableThe HtmlTable also has a theme attribute used to give a different display for different tables. Technically this means that the div that surrounds the table will have its class attribute modified. This technique makes it very easy to define many different displays just by declaring different CSS styles. All you have to do is prepend each selector in the CSS with the theme. For instance the default theme is called jmesa. theme
table.setTheme("jmesa"); // the default
<jmesa:table theme="jmesa"> If you open up the jmesa.css file you will see .jmesa prepended before each selector. .jmesa caption {
caption-side: top;
color: #444444;
font-weight: bold;
font-size: 1em;
text-align: left;
padding-left: 5px;
}
RowThe common attributes of all rows, regardless of the view, are columns and rowRenderer. columnsThe columns defines the Columns used for the table.
row.addColumn(column);
<jmesa:column> rowRendererThe rowRenderer defines the RowRenderer used for the row. See the RowRenderer in the Renderers article for more information.
row.setRowRenderer(rowRenderer);
<jmesa:row rowRenderer="com.mycompany.renderer.MyRowRenderer"> HtmlRowAn HtmlRow has the following attributes: highlighter, onclick, onmouseover, and onmouseout. highlighterThe highlighter is used to give the visual appearance of a row being highlighted as your mouse flows over the row. The default value is true, meaning the row will be highlighted.
row.setHighlighter(true); // the default
<jmesa:row highlighter="true"> onclickThe onclick method on the row looks like this:
public String onclick(RowEvent event); The RowEvent is a callback interface:
public interface RowEvent {
public String execute(Object item, int rowcount);
}This allows custom onclick callback events for each row:
HtmlRow row = table.getRow();
row.setOnclick(new RowEvent() {
public String execute(Object Item, int rowcount) {
// do something custom for each click on the row
// which contains data from the item.
}
};)
<jmesa:htmlRow onclick="org.jmesaweb.controller.TagRowEvent"> public class TagRowEvent implements RowEvent {
public String execute(Object item, int rowcount) {
Object bean = ItemUtils.getItemValue(item, "bean");
Object id = ItemUtils.getItemValue(bean, "id");
return "document.location='http://www.whitehouse.gov/history/presidents?id=" + id + "'";
}
}The onmouseover and onmouseout work the same way. Note: When working with the row events you do not have to inject the WebContext or CoreContext specifically into your classes if you define the proper support interfaces. See the support interfaces page for more details on that. ColumnThe common attributes of all columns, regardless of the view, are property, title, cellRenderer, and headerRenderer. propertyThe property corresponds to the item attribute, where an item is one object in the Collection of Items or Collection of Maps. The property is optional, so if the column does not map to an item attribute then it should be null.
column.setProperty("firstName");
<jmesa:column property="firstName"> title and titleKeyThe title is used to give the header a descriptive name. If you do not define a title then the column will convert the camelcase property name to a real word. If you do not want anything to show up in the header then just add a single whitespace for the title.
column.setTitle("First Name"); // Note: if left blank would still show as "First Name"
<jmesa:column title="First Name"> If you are using the Messages then use the alternate title method.
column.setTitleKey("column.firstName")
<jmesa:column titleKey="column.firstName"> cellRendererThe cellRenderer defines the CellRenderer used for the column. See the CellRenderer in the Renderers article for more information.
column.setCellRenderer(cellRenderer);
<jmesa:column cellRenderer="com.mycompany.renderer.MyCellRenderer"> headerRendererThe headerRenderer defines the HeaderRenderer used for the column. See the HeaderRenderer in the Renderers article for more information.
column.setHeaderRenderer(headerRenderer);
<jmesa:column headerRenderer="com.mycompany.renderer.MyHeaderRenderer"> HtmlColumnThe HtmlColumn also has the following attributes: filterable, sortable, filterRenderer, width, and sortOrder. filterable / sortableJMesa has filtering and sorting built right in. The only thing you need to decide is whether or not to use it. The attributes you will use are filterable and sortable. Both are booleans and the default value is true. If you choose not to use the sorting or filtering, then set the attributes to false.
column.setFilterable(true); // the default column.setSortable(true); // the default
<jmesa:column filterable="true" sortable="true"> filterRendererThe filterRenderer defines the FilterRenderer used for the column. See the FilterRenderer in the Renderers article for more information.
column.setFilterRenderer(filterRenderer);
<jmesa:column filterRenderer="com.mycompany.renderer.MyFilterRenderer"> widthThe width defines the width used for the column.
column.setWidth("10px");
<jmesa:column width="10px"> sortOrderThe sort order restricts the sorting to only the types defined. Typically you would use this to exclude the 'none' Order so that the user can only sort ascending and decending once invoked. Note: Initially this does not change the look of the column, or effect the sorting, when the table is first displayed. For instance, if you only want to sort asc and then desc then when the table is initially displayed you need to make sure you set the Limit to be ordered. The reason is, by design, the limit does not look at the view for any information. The syntax to set the limit would be: limit.getSortSet().addSort();. If you do not do this then the effect will be that the once the column is sorted then it will just flip between asc and desc, which is still a really nice effect and is what I would mostly do.
HtmlColumn htmlColumn = (HtmlColumn)firstName; htmlColumn.setSortOrder(Order.ASC, Order.DESC);
<jmesa:htmlColumn sortOrder="asc,desc"> The legal Column sortOrder values are 'asc', 'desc', and 'none'. |