use of org.apache.myfaces.tobago.internal.component.AbstractUIEvent in project myfaces-tobago by apache.
the class TobagoClientBehaviorRenderer method decode.
@Override
public void decode(final FacesContext facesContext, final UIComponent component, final ClientBehavior clientBehavior) {
if (clientBehavior instanceof AjaxBehavior) {
AjaxBehavior ajaxBehavior = (AjaxBehavior) clientBehavior;
if (!component.isRendered() || ajaxBehavior.isDisabled()) {
return;
}
dispatchBehaviorEvent(component, ajaxBehavior);
} else if (clientBehavior instanceof EventBehavior) {
final EventBehavior eventBehavior = (EventBehavior) clientBehavior;
final AbstractUIEvent abstractUIEvent = RenderUtils.getAbstractUIEvent(component, eventBehavior);
if (!component.isRendered() || abstractUIEvent == null || !abstractUIEvent.isRendered() || abstractUIEvent.isDisabled()) {
return;
}
for (List<ClientBehavior> children : abstractUIEvent.getClientBehaviors().values()) {
for (ClientBehavior child : children) {
decode(facesContext, component, child);
}
}
dispatchBehaviorEvent(component, eventBehavior);
}
}
use of org.apache.myfaces.tobago.internal.component.AbstractUIEvent in project myfaces-tobago by apache.
the class RendererBase method getBehaviorCommands.
protected CommandMap getBehaviorCommands(final FacesContext facesContext, final ClientBehaviorHolder clientBehaviorHolder) {
CommandMap commandMap = null;
for (final Map.Entry<String, List<ClientBehavior>> entry : clientBehaviorHolder.getClientBehaviors().entrySet()) {
final String eventName = entry.getKey();
final ClientBehaviorContext clientBehaviorContext = getClientBehaviorContext(facesContext, clientBehaviorHolder, eventName);
for (final ClientBehavior clientBehavior : entry.getValue()) {
if (clientBehavior instanceof EventBehavior) {
final EventBehavior eventBehavior = (EventBehavior) clientBehavior;
final AbstractUIEvent abstractUIEvent = RenderUtils.getAbstractUIEvent((UIComponent) clientBehaviorHolder, eventBehavior);
if (abstractUIEvent != null && abstractUIEvent.isRendered() && !abstractUIEvent.isDisabled()) {
for (List<ClientBehavior> children : abstractUIEvent.getClientBehaviors().values()) {
for (ClientBehavior child : children) {
final CommandMap childMap = getCommandMap(facesContext, clientBehaviorContext, child);
commandMap = CommandMap.merge(commandMap, childMap);
}
}
}
}
final CommandMap map = getCommandMap(facesContext, clientBehaviorContext, clientBehavior);
commandMap = CommandMap.merge(commandMap, map);
}
}
// if there is no explicit behavior (with f:ajax or tc:event), use the command properties as default.
if ((commandMap == null || commandMap.isEmpty()) && clientBehaviorHolder instanceof AbstractUICommand) {
if (commandMap == null) {
commandMap = new CommandMap();
}
final AbstractUICommand holder = (AbstractUICommand) clientBehaviorHolder;
commandMap.addCommand(ClientBehaviors.click, new Command(holder.getClientId(facesContext), holder.getFieldId(facesContext), holder.isTransition(), holder.getTarget(), null, null, ComponentUtils.getConfirmation(holder), null, TobagoClientBehaviorRenderer.createCollapsible(facesContext, holder), holder.isOmit()));
}
return commandMap;
}
use of org.apache.myfaces.tobago.internal.component.AbstractUIEvent in project myfaces-tobago by apache.
the class RenderUtils method getBehaviorCommands.
/**
* @deprecated since 5.0.0
*/
@Deprecated
public static CommandMap getBehaviorCommands(final FacesContext facesContext, final ClientBehaviorHolder clientBehaviorHolder) {
CommandMap commandMap = null;
for (final Map.Entry<String, List<ClientBehavior>> entry : clientBehaviorHolder.getClientBehaviors().entrySet()) {
final String eventName = entry.getKey();
final ClientBehaviorContext clientBehaviorContext = getClientBehaviorContext(facesContext, clientBehaviorHolder, eventName);
for (final ClientBehavior clientBehavior : entry.getValue()) {
if (clientBehavior instanceof EventBehavior) {
final EventBehavior eventBehavior = (EventBehavior) clientBehavior;
final AbstractUIEvent abstractUIEvent = getAbstractUIEvent((UIComponent) clientBehaviorHolder, eventBehavior);
if (abstractUIEvent != null && abstractUIEvent.isRendered() && !abstractUIEvent.isDisabled()) {
for (List<ClientBehavior> children : abstractUIEvent.getClientBehaviors().values()) {
for (ClientBehavior child : children) {
final CommandMap childMap = getCommandMap(facesContext, clientBehaviorContext, child);
commandMap = CommandMap.merge(commandMap, childMap);
}
}
}
}
final CommandMap map = getCommandMap(facesContext, clientBehaviorContext, clientBehavior);
commandMap = CommandMap.merge(commandMap, map);
}
}
// if there is no explicit behavior (with f:ajax or tc:event), use the command properties as default.
if ((commandMap == null || commandMap.isEmpty()) && clientBehaviorHolder instanceof AbstractUICommand) {
if (commandMap == null) {
commandMap = new CommandMap();
}
final AbstractUICommand holder = (AbstractUICommand) clientBehaviorHolder;
commandMap.addCommand(ClientBehaviors.click, new Command(holder.getClientId(facesContext), holder.getFieldId(facesContext), holder.isTransition(), holder.getTarget(), null, null, ComponentUtils.getConfirmation(holder), null, TobagoClientBehaviorRenderer.createCollapsible(facesContext, holder), holder.isOmit()));
}
return commandMap;
}
use of org.apache.myfaces.tobago.internal.component.AbstractUIEvent in project myfaces-tobago by apache.
the class TabGroupRenderer method processEvent.
@Override
public void processEvent(final ComponentSystemEvent event) {
final AbstractUITabGroup tabGroup = (AbstractUITabGroup) event.getComponent();
for (final UIComponent child : tabGroup.getChildren()) {
if (child instanceof AbstractUITab) {
final AbstractUITab tab = (AbstractUITab) child;
final FacesContext facesContext = FacesContext.getCurrentInstance();
final ClientBehaviors click = ClientBehaviors.click;
switch(tabGroup.getSwitchType()) {
case none:
break;
case client:
// todo: implement a client behavior which can call local scripts (respect CSP)
break;
case reloadTab:
final AjaxBehavior ajaxBehavior = new AjaxBehavior();
final Collection<String> ids = Collections.singleton(UINamingContainer.getSeparatorChar(facesContext) + tabGroup.getClientId(facesContext));
ajaxBehavior.setExecute(ids);
ajaxBehavior.setRender(ids);
tab.addClientBehavior(click.name(), ajaxBehavior);
break;
case reloadPage:
final AbstractUIEvent component = (AbstractUIEvent) ComponentUtils.createComponent(facesContext, Tags.event.componentType(), RendererTypes.Event, "_click");
component.setEvent(click);
tab.getChildren().add(component);
final EventBehavior eventBehavior = new EventBehavior();
eventBehavior.setFor(component.getId());
tab.addClientBehavior(click.name(), eventBehavior);
break;
default:
LOG.error("Unknown switch type: '{}'", tabGroup.getSwitchType());
}
}
}
}
use of org.apache.myfaces.tobago.internal.component.AbstractUIEvent in project myfaces-tobago by apache.
the class TobagoClientBehaviorRenderer method getScript.
/**
* In standard JSF this method returns a JavaScript string. Because of CSP, Tobago doesn't render JavaScript
* into the HTML content. It transports the return value a bit hacky by {@link CommandMap#storeCommandMap}.
*
* @return "dummy" string or null, if nothing to do.
*/
@Override
public String getScript(final ClientBehaviorContext behaviorContext, final ClientBehavior behavior) {
final FacesContext facesContext = behaviorContext.getFacesContext();
final UIComponent uiComponent = behaviorContext.getComponent();
final ClientBehaviors eventName = ClientBehaviors.valueOf(behaviorContext.getEventName());
// // TBD: is this nice? May be implemented with a JSF behavior?
Collapse collapse = createCollapsible(facesContext, uiComponent);
String executeIds = null;
String renderIds = null;
Boolean transition = null;
String target = null;
String clientId = null;
String fieldId = null;
boolean omit = false;
final String confirmation = ComponentUtils.getConfirmation(uiComponent);
if (behavior instanceof AjaxBehavior) {
final AjaxBehavior ajaxBehavior = (AjaxBehavior) behavior;
if (ajaxBehavior.isDisabled()) {
return null;
}
final Collection<String> execute = ajaxBehavior.getExecute();
final Collection<String> render = ajaxBehavior.getRender();
clientId = uiComponent.getClientId(facesContext);
if (uiComponent instanceof SupportFieldId) {
fieldId = ((SupportFieldId) uiComponent).getFieldId(facesContext);
}
executeIds = ComponentUtils.evaluateClientIds(facesContext, uiComponent, execute.toArray(new String[0]));
if (executeIds != null) {
executeIds = executeIds + " " + clientId;
} else {
executeIds = clientId;
}
if (uiComponent instanceof AbstractUICommand) {
// <f:ajax> inside of a command
final AbstractUICommand command = (AbstractUICommand) uiComponent;
transition = command.isTransition();
target = command.getTarget();
omit = command.isOmit() || StringUtils.isNotBlank(RenderUtils.generateUrl(facesContext, command));
}
renderIds = ComponentUtils.evaluateClientIds(facesContext, uiComponent, render.toArray(new String[0]));
} else if (behavior instanceof EventBehavior) {
// <tc:event>
final EventBehavior eventBehavior = (EventBehavior) behavior;
final AbstractUIEvent event = RenderUtils.getAbstractUIEvent(uiComponent, eventBehavior);
if (event != null) {
if (!event.isRendered() || event.isDisabled()) {
return null;
} else {
transition = event.isTransition();
target = event.getTarget();
clientId = event.getClientId(facesContext);
if (collapse == null) {
collapse = createCollapsible(facesContext, event);
}
omit = event.isOmit() || StringUtils.isNotBlank(RenderUtils.generateUrl(facesContext, event));
}
}
} else {
LOG.warn("Unknown behavior '{}'!", behavior.getClass().getName());
}
final Command command = new Command(clientId, fieldId, transition, target, executeIds, renderIds, confirmation, null, collapse, omit);
final CommandMap map = new CommandMap();
map.addCommand(eventName, command);
CommandMap.storeCommandMap(facesContext, map);
// XXX the return value is a string, but we should use a CommandMap
return "dummy";
}
Aggregations