Partial Behavior

Partially executing and/or rendering a page is called partial behavior. For example, Submit a form to create an entity and display the created entity back without processing the whole page.

The following components can be execute or render targets called VisitTarget:

VisitTargetComponents
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 ajax render targets automatically, for example: For examples,

To partially execute/refresh a property of an EntityBackingBean:


	EntityBackingBean entityBackingBean = ...;
	EntityProperty property = entityBackingBean.getEntityProperty("name");
	VisitTarget visitTarget = new VisitEntityProperty(property, entityBackingBean.getEntity());
To partially execute/refresh 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);
To partially execute/refresh 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);
To partially execute/refresh a BackingBean:(entity, entityList, menu)

	VisitTarget visitTarget = backingBean.asVisitTarget();
To partially execute/refresh a MenuNode:

	// menuNode including subtree
	VisitTarget visitTarget = new VisitMenuNode(menuNode, true);
	// menuNode itself
	VisitTarget visitTarget = new VisitMenuNode(menuNode, false);	
To refresh the whole page in ajax mode:

	PartialViewUtil.setRenderAll(true);

Partial Behavior

A partial behavior describes an event, its execute targets and render targets. Execute targets are required, and default is the component itself. Render targets can be null since render targets can added dynamically by action 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 PartialBehaviors 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. Action handler needs to add render targets to refresh partial page when handling commands.

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


	MenuNode menuNode = new MenuNode(menuBean, commandName, RenderStyle.COMMAND_BUTTON);
	PartialBehavior actionBehavior = PartialBehavior.newInstance(PartialBehavior.EVENT_ACTION, 
		new VisitBackingBean(entityBackingBean));
	menuNode.getPartialBehaviorSupport(true).addActionBehavior(actionBehavior);
	menuBean.add(menuNode);
To disable parital behavior, 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));

Property Partial Behavior Annotation

The most often used partial behavior event for entity properties is value chnage 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.

Menu Node Action Handler

To handle MenuNode action(regardless of partial behavior), its action handler needs to implement


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

For the footer/header menu nodes of a PersistenceDataBackingBean(EntityBackingBean or EntityListBackingBean), their action handler is the PersistenceDataBackingBean.

Row Command Action Handler

For an EntityListBackingBean, to handle its row command menu node actions (regardless of partial behavior), its EntityBackingBean needs to implement

	@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")) {
  			...
  		}
  	
	}

Property Menu Action Handler

To handle MenuNode action(regardless of partial behavior) of an EntityProperty, its EntityBackingBean needs to implement


	@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;
	}

Property Partial Behavior Handler

To handle EntityProperty partial behavior event, its EntityBackingBean needs to override

	@Override
	public PageNavigation handlePartialBehaviorEvent(PartialBehaviorEvent event, 
  		PersistenceDataBackingBean<T> backingBean,
  		T entity, EntityProperty<T> property) throws SystemException {
  		
  		if (property.getName().equals("aPropertyName")) {
  			...
  		}
  		
  		return super.handlePartialBehaviorEvent(event, backingBean, entity, property); 
  	}

MenuNode InputData Property

A menu node can have an input data bean that is an EntityBackingBean as the command argument. The input data bean may have EntityProperties 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( //partially execute: menuNode
			type, value, selectPartialBehaviorSupport, selectRenderStyle, true);
	selectEP.setSelectPropertyQueryElements(...);
To handle such partial behaviors, the menu node action handler needs to implement

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