7.8 View Config
A ViewConfig controls how a bean will be rendered and interact with users,
including properties, layout, render style, access control, partial behavior,
pagination and bookmarkable links. A ViewConfig can be created dynamically at
runtime, or expressed in XML in FormDesigns and embedded objects in a page.
<object xmlns="http://www.cmobilecom.com/af/objects" type="objectType">
<viewConfig>
<attributeName>attributeValue</attributeName>
</viewConfig>
</object>
ViewConfig Base Type
ViewConfig is the base class of the ViewConfig hierarchy. It is
the superclass of PersistenceDataViewConfig and MenuViewConfig.
ViewConfig
/ \
PersistenceDataViewConfig MenuViewConfig
/ \
EntityViewConfig EntityListViewConfig
Properties:
- viewType:
- ENTITY: for EntityViewConfig of an EntityBackingBean in creating, view
or edit mode.
- ENTITY_LIST_WIDE: for EntityListViewConfig of an EntityListBackingBean
in view or edit mode.
- QUERY: for EntityViewConfig of an EntityBackingBean in query mode.
- MENU: for MenuViewConfig of a MenuBean or MenuNodeFactory.
- accessControlContext: grant or deny certain permissions from users.
- accessControl: module access control. An AccessControlAccessor consists of one
or more module access controls. It is chained to the root
AccessControlAccessor of current DataAccessUnit, and will
override existing access controls if any. The root
AccessControlAccessor is the federation of all module access controls defined
in the XML document ac.xml.
- panelVisible: whether to render a panel around backing bean.
- panelView: panel options if bean is shown in a panel.
- accordionView: accordion options if bean is shown in an accordion. For example,
accordion tree menu.
- title: bean panel title.
- localized: boolean. If false, resource bundles will be used to translate
the title for current user locale.
- message: bean message to show at the specified location.
- location: TOP, BELOW_HEADER_MENU, ABOVE_FOOTER_MENU, BOTTOM.
- localized: boolean. If false, resource bundles will be used to translate
the message for current user locale.
Supported expressions in message: JSF EL expressions, #{current_user}, #{current_date}.
- styleClass: bean style classes
- param: define a parameter with name/value.
- redirect: define request redirect after an action is completed.
For example, API:
EntityViewConfig viewConfig = new EntityViewConfig(ViewType.ENTITY);
viewConfig.setPanelVisible(true);
viewConfig.setAccessControlAccessor(acAccessor);
XML:
<viewConfig>
<viewType>ENTITY</viewType>
<panelVisible>true</panelVisible>
<panelView>
<toggleable>true</toggleable>
<collapsed>true</collapsed>
</panelView>
<accordionView>
<multiple>true</theme>
</accordionView>
<message location="BOTTOM" localized="true">message on the bottom</message>
<accessControlContext>
<permissionsGranted>permission1,permission2</permissionsGranted>
<permissionsDenied>permission1,permission2</permissionsDenied>
</accessControlContext>
<accessControl module="HR">
<entityType name="EC">
<entity accessType="CREATE" accessControl="USER" />
<entity accessType="DELETE" accessControl="NOBODY" />
<entity accessType="EDIT" accessControl="OWNER" />
</entityType>
<action name="ApproveExpenseClaims" accessControl="SUSER{ApproveEC}" />
</accessControl>
<param name="paramName" value="paramValue"/>
<redirect action="cmd.commandName" toURL="/path/page1.xpg">
<add name="param1" value="value1" />
</redirect>
</viewConfig>
The default viewType for EntityBackingBean is ENTITY, and for EntityListBackingBean
is ENTITY_LIST_WIDE.
PanelView:
- toggleable: whether panel is toggleable. default is true.
- closable: whether panel is closable. default is true.
- collapsed: whether panel is collapsed initially. default is false.
- toggleOrientation: vertical or horizontal. default is vertical.
AccordionView:
- multiple: true or false. If true, multiple tabs can be opened at the same time.
For accessControl XML syntax, see Access Control.
Parameters:
- number.currency.symbol: (boolean) whether to include currency symbol
in showing a monetary amount. default is true.
A module can define any parameters.
Persistence Data ViewConfig
PersistenceDataViewConfig is the superclass of EntityViewConfig and EntityListViewConfig.
- layoutType: how to layout properties.
- FLOW: flowing from left to right.
- TABLE: tabular with property name and value columns.
- LAYOUT_CODE: by layout code with embedded properties.
- TAB_VIEW: tab view with one tab for each property.
- LIST_VIEW: one row for each property, valid for mobile only.
- GRID: grid view.
- GRID_NAME_VALUE: 2-column grid view for name/value pairs.
- COLUMN_VIEW: column view.
- ROW_ENTITY_VIEW: render each entity of EntityListBackingBean using EntityBackingBean.
- layoutColumns: number of layout columns for grid/column view. default is 1.
- layoutDirection: layout direction (VERTICAL or HORIZONTAL) for grid/column view.
default is HORIZONTAL.
- menuNodesSupported: a list of menu nodes supported that applies to both
header and footer menus. For menu node id(s), starts with id., and for commands,
starts with cmd.(default). For example, id.Help, cmd.Create. If a menu node has command,
use its command instead of its id.
Its default value is null, meaning that all menu nodes are supported. If it is not null,
only those menu nodes will be supported.
- menuNodesDenied: a list of menu nodes denied that applies to both header
and footer menus. Denied menu nodes will be hidden even if they are explicitly supported.
For menu node id(s), starts with id., and for commands, starts with cmd.(default).
For example, id.Help, cmd.Create. If a menu node has command, use its command instead of its id.
Its default value is null, meaning that none of menu nodes are denied. But by default
some menu nodes are denied by system, including CreateAndContinue, CreateAndReturn and
CancelCreate. To enable any of those menu nodes, remove them from the denied list in building
viewConfig or add them into the menuNodesSupported list.
- showHeaderMenu: (boolean) whether to show header menu. default is true.
- showFooterMenu: (boolean) whether to show footer menu. default is true.
- propertiesToShow: the properties to show. default is all properties.
- propertiesToHide: the properties to hide. default is empty.
- themeEnabled: (boolean) whether to use the table theme. default is true.
- accessibleWithoutParentBean: for ChildEntity type, whether entities are accessible
without parent bean. default is true for VIEW, and false for other access types.
- hasCreatePermission: (boolean) whether the user has Create permission. default is by access control.
- hasViewPermission: (boolean) whether the user has View permission. default is by access control.
- hasDeletePermission: (boolean) whether the user has Delete permission. default is by access control.
- hasEditPermission: (boolean) whether the user has Edit permission. default is by access control.
- property: property descriptor that is used to override its defaults
- propertyGrouping: a list of property groups. see PropertyGroup javadoc for detail.
- mediaParams: the parameters for showing one or a list of media. see javadoc for
parameter definitions.
- supported parameters: alwaysVisible, autoFocus, execOnReturn, returnAsTab,
autoCompleteToggle, inputDialogToggle, uiAutoComplete. see javadoc for detail.
To set default values for all properties, use _default as property name.
For example, all properties are required,
<property name="_default">
<requiredType>REQUIRED</requiredType>
</property>
To configure property select items:
<property name="choice">
<renderStyle>
<selectItems>
<selectItem value="1">select 1</selectItem>
<selectItem value="2">select 2</selectItem>
<selectItem value="3">select 3</selectItem>
</selectItems>
</renderStyle>
</property>
Example: Property grouping
<viewConfig>
<propertyGrouping>
<group name="productGroup" visibleName="Product" nameLocalized="false" position="0"
layout="LAYOUT_CODE"><![CDATA[#{product}<br/>#{unitPrice}/#{unitOfMeasure}]]></group>
<group name="productGroup" visibleName="Product" nameLocalized="false" position="0"
showMemberNames="true" memberSeparator=","
layout="FLOW">product,unitPrice,unitOfMeasure</group>
</propertyGrouping>
</viewConfig>
The first property group uses layout code(HTML) embedding property expressions, and the group
is inserted at position 0. The second property group uses FLOW layout to group the specified
properties, and then inserted a position 0.
Example: ChildEntity accessible without parent bean
<viewConfig>
<accessibleWithoutParentBean>
<create>true</create>
<view>true</view>
<edit>false</edit>
<delete>false</delete>
</accessibleWithoutParentBean>
</viewConfig>
For a ChildEntity or a list of ChildEntity(s) without its parent bean,
hasViewPermission, hasCreatePermission, hasEditPermission and hasDeletePermission
are valid only if the ChildEntity or the list of ChildEntity(s) is acceesible.
Example: clicking photos to add product to shopping cart
<viewConfig>
<viewType>ENTITY_LIST_WIDE</viewType>
<property name="photos">
<actionOnClick>AddToShoppingCart</actionOnClick>
</property>
</viewConfig>
If the menu node does not exist, override the following method to handle the action in its
EntityBackingBean.
@Override
public PageNavigation clickPropertyValue(PersistenceDataBackingBean<T> backingBean, T entity,
EntityProperty<T> property, ContainerRenderRegions containerRenderRegions) throws SystemException {
String propertyName = property.getNamePath();
PersistenceDataViewConfig viewConfig = backingBean.getViewConfig();
PropertyDescriptor propertyDescriptor = viewConfig.getPropertyDescriptor(propertyName, false, false);
String command = propertyDescriptor!=null? propertyDescriptor.getActionOnClick() : null;
if ("AddToShoppingCart".equals(command)) {
// handle action
return null;
}
return super.clickPropertyValue(backingBean, entity, property, containerRenderRegions);
}
Example: search when product hierarchy is changed
<viewConfig>
<viewType>QUERY</viewType>
<property name="hierarchy">
<actionOnChange>Search</actionOnChange>
</property>
</viewConfig>
If the menu node does not exist, override the following method to handle valueChange partial behavior
event in its EntityBackingBean.
@Override
public PageNavigation handlePartialBehaviorEvent(PartialBehaviorEvent event,
PersistenceDataBackingBean<T> backingBean,
T entity, EntityProperty<T> property) throws SystemException {
if (event.getPartialBehavior().isValueChange()) {
String propertyName = property.getNamePath();
PersistenceDataViewConfig viewConfig = backingBean.getViewConfig();
PropertyDescriptor propertyDescriptor = viewConfig.getPropertyDescriptor(propertyName, false, false);
String command = propertyDescriptor!=null? propertyDescriptor.getActionOnChange() : null;
if ("Search".equals(command)) {
// handle action
return null;
}
}
return super.handlePartialBehaviorEvent(event, backingBean, entity, property);
}
Entity ViewConfig
EntityViewConfig is the ViewConfig of an EntityBackingBean in create, view, edit or query mode.
- formDesign: use an existing Form Design or create a new Form Design
with layout code embedding property expressions and optional style sheet.
see Form Design.
- quickQueryProperties: a list of property names that will be grouped under Quick
search tab for query view.
- showSearchOptions: (boolean) whether to show search options including group by properties,
order by properties, and query results page size. default is true.
For example, an EntityViewConfig for user registration
<viewConfig>
<viewType>ENTITY</viewType>
<propertiesToShow>name,address,contact,phone,email,user.username,user.password</propertiesToShow>
<property name="name">
<visibleName>CompanyName</visibleName>
</property>
<property name="_default">
<requiredType>REQUIRED</requiredType>
</property>
<viewConfig name="address">
<viewType>ENTITY</viewType>
<themeEnabled>false</themeEnabled>
<propertiesToShow>country,state,city</propertiesToShow>
<property name="_default">
<requiredType>REQUIRED</requiredType>
</property>
</viewConfig>
</viewConfig>
The address property is a form bean property and its ViewConfig is embedded.
<viewConfig>
<viewConfig name="address">
</viewConfig>
</viewConfig>
The following example is showing name and type for a query bean.
<viewConfig>
<viewType>QUERY</viewType>
<propertiesToShow>name,type</propertiesToShow>
</viewConfig>
Entity List ViewConfig
EntityListViewConfig is the ViewConfig of an EntityListBackingBean in view or edit mode.
- showRowCommands: (boolean) whether to show row commands. default is true.
- pageable: (boolean) whether to support pagination. default is true.
- pageSize: rows per page. If null and pageable is false, one page only.
- pagePadding: (boolean) whether to add blank rows if page is not full. It is meaningful
only if pageSize is not null. default is false.
- calculateStatistics: (boolean) whether to calculate statistics row. default is true.
- showStatistics: (boolean) whether to show statistics row at the bottom. default is true.
- statisticsRowLabel: the label for statistics row. default is Total.
- listItemLayoutCode: for LIST_VIEW, the list item(entity) layout code with embedded
property expressions #{property}.
- pageParam: page number parameter name in URL. If not specified, partial behavior is
used for pagination.
- columnHeadersRenderable: (boolean) whether to show column headers. default is true.
- columnHeaders: structured column headers. default is using property names.
- initialEntityCount: for entity list formBean, initial number of entities to create. default is 1.
- entityCountToAdd: for entity list formBean, the number of entities to add for adding rows command.
default is 1.
- askEntityCountToAdd: (boolean) for entity list formBean, whether to pop up a dialog
asking the number of entities to add for adding rows command. default is false.
- navigatableToEntity: (boolean) whether user can navigate to entity views from an entity list view.
default is true.
- embeddedStatistics: define statistics entities to be embedded between entity rows.
Insert a statistics row if any of the diff property values is different between two consecutive rows.
For example, an EntityListViewConfig for employees:
<viewConfig>
<viewType>ENTITY_LIST_WIDE</viewType>
<propertiesToShow>nid,name,type,hiredDate</propertiesToShow>
<pageSize>20</pageSize>
<pageParam>page</pageParam>
</viewConfig>
Embed statistics rows
<viewConfig>
<viewType>ENTITY_LIST_WIDE</viewType>
<embeddedStatistics>
<diffProperties>property1, property2, ...</diffProperties>
</embeddedStatistics>
</viewConfig>
MenuViewConfig is the ViewConfig of a MenuBean or MenuNodeFactory.
- menuStyle: menu style such as MENU_BAR, TREE, TIERED_MENU, or ACCORDION_TREE.
- rootVisible: (boolean) whether the root menu node is visible, default is false.
- iconOnly: (boolean) whether to show icons only (no labels) for menu nodes, default is false.
- commandStyleNumber: command style number, COMMAND_BUTTON or COMMAND_LINK. If not specified,
using the style number specified when creating menu nodes.
- menuNodesToShow: menu nodes to show. For menu node id(s), starts with id., and for commands,
starts with cmd.(default).
For example, id.Help,cmd.Create. If a menu node has command, use its command instead of its id.
- menuNodesToHide: menu nodes to hide. For menu node id(s), starts with id., and for commands,
starts with cmd.(default).
For example, id.Help,cmd.Create. If a menu node has command, use its command instead of its id.
- menuNode: menu node descriptor. If the menu is built from hierarchy entities,
the entity variable is the hierarchy entity object mapped to the menu node.
- key: hierarchy.root(hierarchy root node), hierarchy.entity (hierarchy entity), cmd.[command], or
id.[menuNode Id].
For example, cmd.Create, id.Help. If a menu node has command, use its command instead of its id.
The key for default menu node descriptor is _default.
- name: menu node name, supporting expressions such as #{entity.name}.
localized attribute: whether the name is localized, default is false.
- icon: icon name
- renderStyle:
- styleNumber: 16 for OUTPUT_LINK, 20 for COMMAND_LINK. See RenderStyle javadoc.
- target: target for outputLink, e.g., _blank
- outputLink: hyperlink supporting expressions, e.g.,
http://domain/foo.xpg?id=#{entity.hierarchyId}
- captchaRequired: (boolean) whether to verify captcha before executing the command.
- partialBehaviorSupport: partial behavior definitions. See Partial
Behavior for detail.
- treeView:
- expandedDepth: initially expand menu nodes whose depth is less than or equals to the depth.
For example, menu bar:
<viewConfig>
<viewType>MENU</viewType>
<menuStyle>MENU_BAR</menuStyle>
<iconOnly>false</iconOnly>
<commandStyleNumber>19</commandStyleNumber>
<menuNodesToShow>cmd.Help,cmd.OpenQueryForm,cmd.Create</menuNodesToShow>
</viewConfig>
Example: tree menu with nodes expanded up to depth 3.
<viewConfig>
<viewType>MENU</viewType>
<menuStyle>TREE</menuStyle>
<treeView>
<expandedDepth>3</expandedDepth>
</treeView>
</viewConfig>
For example, a MenuViewConfig for forum hierarchy entities:
<viewConfig>
<viewType>MENU</viewType>
<menuStyle>TREE</menuStyle>
<menuNode key="hierarchy.entity">
<name localized="true">#{entity.name}</name>
<renderStyle>
<styleNumber>16</styleNumber>
</renderStyle>
<outputLink>/forum.xpg?forumId=#{entity.hierarchyId}</outputLink>
</menuNode>
<menuNode key="hierarchy.root">
<name>Forums</name>
<renderStyle>
<styleNumber>16</styleNumber>
</renderStyle>
<outputLink>/all-forums.xpg</outputLink>
</menuNode>
</viewConfig>
Style number 16 is OUTPUT_LINK, and style number 19 is COMMAND_BUTTON. For a complete list of
style numbers, see Property Annotations or RenderStyle
javadoc.
Nested ViewConfig
A ViewConfig can have nested ViewConfig(s). The following nested viewConfig names are supported
for each enclosing ViewConfig type:
- EntityViewConfig: headerMenu, footerMenu, a formBean property name,
queryResults, report and reportTable.
- EntityListViewConfig: headerMenu, footerMenu, paginatorMenu, rowCommandMenu,
navigateToEntity, createEntity.
navigateToEntity is the name of the EntityViewConfig for viewing or editing an entity, and
createEntity is the name of the EntityViewConfig for creating an entity.
- MenuViewConfig: menu node command and inputData. The format of a nested
viewConfig name for a menuNode is <menuNodeIdentifier>:<selector>, where
menuNodeIdentifier is cmd.<command name> or id.<menu node id>, and the selector
can be command or inputData. The command selector indicates that the nested viewConfig
is used for the command handler to show a bean, and The inputData selector indicates
that the nested viewConfig is used as the viewConfig of the inputData bean of the menu node.
Example: a ViewConfig for a ReportQueryFormBean:
<viewConfig>
<viewType>QUERY</viewType>
<viewConfig name="report" >
<viewType>ENTITY</viewType>
<viewConfig name="reportTable" >
<viewType>ENTITY_LIST_WIDE</viewType>
<pageable>false</pageable>
</viewConfig>
</viewConfig>
</viewConfig>
"report" is the name of the ReportBean viewConfig of a ReportQueryFormBean, and
"reportTable" is the name of the report table viewConfig of a ReportBean. A ReportBean
contains charts and report table.
Example: place an order with a list of order items. Command link "Show Shipping Cost"
has inputData(shippingMethod, weight) to show shipping costs for various destinations.
<viewConfig>
<viewType>ENTITY</viewType>
<viewConfig name="orderItems" >
<viewType>ENTITY_LIST_NARROW</viewType>
<propertiesToShow>product,unitPrice,quantity,total</propertiesToShow>
<pageable>false</pageable>
</viewConfig>
<showHeaderMenu>false</showHeaderMenu>
<viewConfig name="footerMenu" >
<viewType>MENU</viewType>
<menuStyle>MENU_BAR</menuStyle>
<menuNodesToShow>cmd.Create,cmd.ShowShippingCost</menuNodesToShow>
<menuNode key="cmd.Create">
<name>PlaceOrder</name>
<captchaRequired>true</captchaRequired>
</menuNode>
<viewConfig name="cmd.ShowShippingCost:command" >
<viewType>ENTITY_LIST_WIDE</viewType>
<propertiesToShow>destination,cost</propertiesToShow>
</viewConfig>
<viewConfig name="cmd.ShowShippingCost:inputData" >
<viewType>ENTITY</viewType>
<propertiesToShow>shippingMethod,weight</propertiesToShow>
</viewConfig>
</viewConfig>
</viewConfig>
Example: a user list view with row command "ShowUserData". Nested ViewConfig(s):
rowCommandMenu, cmd.ShowUserData:command, navigateToEntity and createEntity.
<viewConfig>
<viewType>ENTITY_LIST_WIDE</viewType>
<viewConfig name="rowCommandMenu" >
<viewType>MENU</viewType>
<menuStyle>MENU_BAR</menuStyle>
<viewConfig name="cmd.ShowUserData:command" >
<!-- viewConfig for showing user data -->
</viewConfig>
</viewConfig>
<viewConfig name="navigateToEntity" >
<!-- viewConfig for showing or editing an entity -->
</viewConfig>
<viewConfig name="createEntity" >
<!-- viewConfig for creating an entity -->
</viewConfig>
</viewConfig>
To get a nested ViewConfig of a menu node, its action handler can call MenuNode.getNestedViewConfig(...).
For example,
public PageNavigation clickMenuNode(MenuNode menuNode) {
// get menu node command viewConfig
EntityViewConfig viewConfig = menuNode.getNestedViewConfig(true, EntityViewConfig.class);
...
}
see MenuNode javadoc.
Partial Behavior Support
The partialBehaviorSupport element of a MenuNode or Property defines a list of partial behaviors.
<partialBehaviorSupport>
<partialBehavior event="eventName">
<renderRegions>regionNumber1,regionNumber2,...</renderRegions>
<openDialog>true|false</openDialog>
</partialBehavior>
</partialBehaviorSupport>
- event: event name such as action, change.
- renderRegions: a list of render regions to show action result beans.
The first region is used to show the beans, and the other regions will be cleared.
If not defined, the default query result regions of the containerBean will be used.
The containerBean is current containerBean or a new DialogBean(if openDialog is true).
- openDialog: (boolean) whether to open a dialog to show the result beans. Default is false.
For example, the following ViewConfig of a query EntityBackingBean defines that
the Search command will show query results in region 8 and clear region 9.
<viewConfig>
<viewConfig name="footerMenu" >
<viewType>MENU</viewType>
<menuStyle>MENU_BAR</menuStyle>
<menuNode key="cmd.Search">
<partialBehaviorSupport>
<partialBehavior event="action">
<renderRegions>8,9</renderRegions>
<openDialog>false</openDialog>
</partialBehavior>
</partialBehaviorSupport>
</menuNode>
</viewConfig>
</viewConfig>