Search in sources :

Example 1 with AbstractUITabGroup

use of org.apache.myfaces.tobago.internal.component.AbstractUITabGroup 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());
            }
        }
    }
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ClientBehaviors(org.apache.myfaces.tobago.component.ClientBehaviors) UIComponent(jakarta.faces.component.UIComponent) EventBehavior(org.apache.myfaces.tobago.internal.behavior.EventBehavior) AbstractUIEvent(org.apache.myfaces.tobago.internal.component.AbstractUIEvent) AbstractUITabGroup(org.apache.myfaces.tobago.internal.component.AbstractUITabGroup) AbstractUITab(org.apache.myfaces.tobago.internal.component.AbstractUITab) AjaxBehavior(jakarta.faces.component.behavior.AjaxBehavior)

Aggregations

UIComponent (jakarta.faces.component.UIComponent)1 AjaxBehavior (jakarta.faces.component.behavior.AjaxBehavior)1 FacesContext (jakarta.faces.context.FacesContext)1 ClientBehaviors (org.apache.myfaces.tobago.component.ClientBehaviors)1 EventBehavior (org.apache.myfaces.tobago.internal.behavior.EventBehavior)1 AbstractUIEvent (org.apache.myfaces.tobago.internal.component.AbstractUIEvent)1 AbstractUITab (org.apache.myfaces.tobago.internal.component.AbstractUITab)1 AbstractUITabGroup (org.apache.myfaces.tobago.internal.component.AbstractUITabGroup)1