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