Cmobilecom AF 5.19 Developer Guide

8 Partial Behavior

Executing and/or rendering a part of view is called partial behavior. It is equivalent to ajax for web. A partial behavior request involves event, execute targets, event handler and render targets.

Execute and Render Targets

An execute target is a part of view from which to get data for event handler, and a render target is a part of view that will be updated after request is completed. For example,

Components As Visit Targets

Both execute and render targets are called Visit Targets. If a visit target is used for execute, it is an execute target. Similarly, if a visit target is used for render, it is a render target.

The following components can be Visit Targets (execute or render):

VisitTarget Components
VisitContainerBean ContainerBean: root ContainerBean or DialogBean.
VisitRegion Region: a region of ContainerBean page content.
VisitBackingBean BackingBean: EntityBackingBean, EntityListBackingBean, or MenuBean.
VisitMenuNode MenuNode: a menu node itself or including its subtree.
VisitEntityProperty EntityProperty: a property of EntityBackingBean, or a property at a certain row of EntityListBackingBean.
VisitEntityListRow Entity list row: a regular or expansion row of EntityListBackingBean.
VisitUIComponent UI component: @this - JSF component itself, @form - form component.
Some actions will add render targets automatically, for example:

Create Visit Targets

Visit targets can be explicitly created. For example,

Create a VisitTarget for a property of an EntityBackingBean:


	EntityBackingBean entityBackingBean = ...;
	EntityProperty property = entityBackingBean.getEntityProperty("name");
	VisitTarget visitTarget = new VisitEntityProperty(property, entityBackingBean.getEntity());
Create a VisitTarget for a property at a row of an EntityListBackingBean:

	EntityListBackingBean entityListBackingBean = ...;
	EntityProperty property = entityListBackingBean.getEntityProperty("name");
	T entity = entityListBackingBean.getPageEntityList().get(2);
	VisitTarget visitTarget = new VisitEntityProperty(property, entity);
Create a VisitTarget for a row of an EntityListBackingBean:

	EntityListBackingBean entityListBackingBean = ...;
	// regular row
	VisitTarget visitTarget = new VisitEntityListRow(entityListBackingBean, 2, true, false);
	// expansion row
	VisitTarget visitTarget = new VisitEntityListRow(entityListBackingBean, 2, true, true);
	// statistics row
	VisitTarget visitTarget = VisitEntityListRow.statisticsRow(entityListBackingBean);
	// current row
	VisitTarget visitTarget = VisitEntityListRow.currentRow(entityListBackingBean);
Create a VisitTarget for a BackingBean:(entity, entityList, menu)

	VisitTarget visitTarget = backingBean.asVisitTarget();
Create a VisitTarget for a MenuNode:

	// menuNode including subtree
	VisitTarget visitTarget = new VisitMenuNode(menuNode, true);
	// menuNode itself
	VisitTarget visitTarget = new VisitMenuNode(menuNode, false);	
A VisitTarget can be used as an execute or render target for creating PartialBehavior instances. For example,

	VisitTarget beanVisitTarget = backingBean.asVisitTarget();
	PartialBehavior partialBehavior = new PartialBehavior(event, beanVisitTarget,
			Arrays.asList(beanVisitTarget), null);
	// add partialBehavior to a Partial Behavior holder(MenuNode or EntityProperty)
A VisitTarget can be added to current PartialViewContext as a render target. For example,

	VisitTarget beanVisitTarget = backingBean.asVisitTarget();
	PartialViewUtil.addRenderTarget(beanVisitTarget);
Add entire view as a render target:

	PartialViewUtil.setRenderAll(true);

Partial Behavior Holder

A partial behavior describes an event, its execute targets and render targets. Execute targets are required, and default is the associated view component itself. Render targets can be null since render targets can be dynamically added by event handler by calling PartialViewUtil.addRenderTarget(VisitTarget). For example,

	PartialViewUtil.addRenderTarget(backingBean.asVisitTarget());
	PartialViewUtil.addRenderTarget(new VisitEntityListRow(entityListBackingBean, 3, true, false));
MenuNode and EntityProperty are ClientBehaviorHolders supporting partial behaviors. Get the PartialBehaviorSupport instance and add PartialBehavior(s) to it.
 
	PartialBehaviorSupport partialBehaviorSupport = menuNode.getPartialBehaviorSupport(true);
	PartialBehaviorSupport partialBehaviorSupport = entityProperty.getPartialBehaviorSupport(true);
By default, a command MenuNode is enabled for partial behavior and its execute target is its CommandLink or CommandButton itself. Its action handler can add render targets to refresh partial view when handling commands.

The following code adds an action partial behavior to the menu node, and its execute target is an EntityBackingBean.


	MenuNode menuNode = new MenuNode(menuBean, commandName, RenderStyle.COMMAND_BUTTON);
	PartialBehavior actionBehavior = PartialBehavior.newInstance(PartialBehavior.EVENT_ACTION, 
			entityBackingBean.asVisitTarget());
	menuNode.getPartialBehaviorSupport(true).addPartialBehavior(actionBehavior);
	menuBean.add(menuNode);
To disable partial behavior for an action, a disabled partial behavior needs to be added. For example, disable partial behavior for a menu node:

	menuNode.getPartialBehaviorSupport(true).disableActionBehavior();
That is short for:
	
	menuNode.getPartialBehaviorSupport(true).addPartialBehavior(
			PartialBehavior.newInstance(PartialBehavior.EVENT_ACTION, true));
A menu node can have action event only, but a property can have action and value change events. For example, when a property value is changed, fire PartialBehavior change event, execute target is a bean.
	PartialBehaviorSupport partialBehaviorSupport = entityProperty.getPartialBehaviorSupport(true);
	partialBehaviorSupport.addValueChangeBehavior(beanVisitTarget);

Property Partial Behavior Annotation

The most often used partial behavior event for entity properties is value change event. For example,

	@Property(name="propertyName",
		...
		partialBehavior=@PartialBehaviorDef(event=PartialBehavior.EVENT_CHANGE,
			execute=VisitTarget.THIS,
			mode={ModeType.CREATE, ModeType.EDIT}),
	)
Partial behavior annotation execute value can be VisitTarget.THIS, VisitTarget.FORM, VisitTarget.BACKING_BEAN, VisitTarget.ENTITY_LIST_ROW. The mode value specifies a list of modes in which the partial behavior is enabled, default is all modes. To handle MenuNode action(regardless of partial behavior), its action handler needs to override the following method:

	@Override
	public PageNavigation clickMenuNode(MenuNode menuNode) throws SystemException {
		String command = menuNode.getCommand();
		if (command.equals(aCommandName)) { 	    	
			...
			return null;
		}

		return super.clickMenuNode(menuNode);
	}
For the footer/header menu nodes of a PersistenceDataBackingBean(EntityBackingBean or EntityListBackingBean), their action handler is the PersistenceDataBackingBean instance.

Row Command Action Handler

For an EntityListBackingBean, to handle its row command menu node actions (regardless of partial behavior), its EntityBackingBean needs to override the following method:

	@Override
	protected PageNavigation clickEntityRowCommand(EntityListBackingBean<T> entityListBackingBean,
		T entity, EntityProperty<T> property, MenuNode menuNode) throws BackingBeanException, SystemException {
		String command = menuNode.getCommand();
		if (command.equals("aCommandName")) {
			...
			return null;
		}

		return super.clickRowEntityCommand(entityListBackingBean, entity, property, menuNode);
	}

Property Menu Action Handler

To handle MenuNode action(regardless of partial behavior) of an EntityProperty, its EntityBackingBean needs to override the following method:

	@Override
	public PageNavigation clickPropertyMenuNode(PersistenceDataBackingBean<T> backingBean,
		T entity, EntityProperty<T> property, MenuNode menuNode) throws SystemException {

		String command = menuNode.getCommand();
		if (property.getName().equals("aPropertyName") &&
				command.equals("aCommandName")) {
			...
			return null;
		}
  
		return super.clickPropertyMenuNode(backingBean, entity, property, menuNode);
	}

Property Partial Behavior Handler

To handle EntityProperty partial behavior event, its EntityBackingBean needs to override the following method:

	@Override
	public PageNavigation handlePartialBehaviorEvent(PartialBehaviorEvent event, 
		PersistenceDataBackingBean<T> backingBean,
		T entity, EntityProperty<T> property) throws SystemException {

		if (property.getName().equals("aPropertyName")) {
			...
			return null;
		}

		return super.handlePartialBehaviorEvent(event, backingBean, entity, property);
	}
A menu node can have an input data bean that is an EntityBackingBean as the command argument. The input data bean may have EntityProperty(s) that support partial behaviors. For example,

	MenuNode menuNode = new MenuNode(menuBean, aCommandName, RenderStyle.COMMAND_LINK);
	RenderStyle selectRenderStyle = new RenderStyle(RenderStyle.SELECT_ONE_MENU); 
	PartialBehaviorSupport selectPartialBehaviorSupport = new PartialBehaviorSupport(
			PartialBehavior.newInstance(PartialBehavior.EVENT_CHANGE, new VisitUIComponent(VisitTarget.THIS)));
	EntityProperty selectEP = menuNode.addInputDataProperty(
			type, value, selectPartialBehaviorSupport, selectRenderStyle, true);
	selectEP.setSelectPropertyQueryElements(...);
To handle such partial behaviors, the menu node action handler needs to override the following method:

	@Override
	public <M extends PersistenceEntity> PageNavigation handlePartialBehaviorEvent(
			PartialBehaviorEvent event, MenuNode menuNode, EntityBackingBean<M> inputDataBackingBean,
			EntityProperty<M> property) throws SystemException {

	}
Query BeanUser Defined Entity PropertiesFrames / No Frames