Search in sources :

Example 1 with AjaxBehaviorEvent

use of javax.faces.event.AjaxBehaviorEvent in project liferay-faces-alloy by liferay.

the class Accordion method queueEvent.

@Override
public void queueEvent(FacesEvent facesEvent) {
    // behavior event, then
    if (facesEvent instanceof AjaxBehaviorEvent) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
        String eventName = requestParameterMap.get("javax.faces.behavior.event");
        // If the AjaxBehaviorEvent indicates a tab being collapsed/expanded, then
        if (TabCollapseEvent.TAB_COLLAPSE.equals(eventName) || TabExpandEvent.TAB_EXPAND.equals(eventName)) {
            // Determine the client-side state of the selected tab index.
            String clientId = getClientId(facesContext);
            int index;
            if (TabCollapseEvent.TAB_COLLAPSE.equals(eventName)) {
                index = IntegerHelper.toInteger(requestParameterMap.get(clientId + "collapsedTabIndex"));
            } else {
                index = IntegerHelper.toInteger(requestParameterMap.get(clientId + "selectedIndex"));
            }
            // If iterating over a data model, then determine the row data and tab associated with the data model
            // iteration.
            Object rowData = null;
            Tab tab = null;
            String var = getVar();
            if (var != null) {
                setRowIndex(index);
                rowData = getRowData();
                tab = TabUtil.getFirstChildTab(this);
                setRowIndex(-1);
            } else // Otherwise, determine the tab associated with the client-side state of the selected tab index.
            {
                List<Tab> childTabs = TabUtil.getChildTabs(this);
                if (childTabs.size() >= (index + 1)) {
                    tab = childTabs.get(index);
                }
            }
            // Queue a tab collapse/expand event rather than the specified faces event.
            AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) facesEvent;
            Behavior behavior = behaviorEvent.getBehavior();
            if (TabCollapseEvent.TAB_COLLAPSE.equals(eventName)) {
                facesEvent = new TabCollapseEvent(this, behavior, tab, rowData);
            } else {
                facesEvent = new TabExpandEvent(this, behavior, tab, rowData);
            }
        }
    }
    super.queueEvent(facesEvent);
}
Also used : FacesContext(javax.faces.context.FacesContext) TabCollapseEvent(com.liferay.faces.alloy.component.tab.TabCollapseEvent) Tab(com.liferay.faces.alloy.component.tab.Tab) ExternalContext(javax.faces.context.ExternalContext) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) Behavior(javax.faces.component.behavior.Behavior) TabExpandEvent(com.liferay.faces.alloy.component.tab.TabExpandEvent)

Example 2 with AjaxBehaviorEvent

use of javax.faces.event.AjaxBehaviorEvent in project primefaces by primefaces.

the class AjaxBehaviorRenderer method decode.

@Override
public void decode(FacesContext context, UIComponent component, ClientBehavior behavior) {
    AjaxBehavior ajaxBehavior = (AjaxBehavior) behavior;
    if (!ajaxBehavior.isDisabled()) {
        AjaxBehaviorEvent event = new AjaxBehaviorEvent(component, behavior);
        PhaseId phaseId = isImmediate(component, ajaxBehavior) ? PhaseId.APPLY_REQUEST_VALUES : PhaseId.INVOKE_APPLICATION;
        event.setPhaseId(phaseId);
        component.queueEvent(event);
    }
}
Also used : PhaseId(javax.faces.event.PhaseId) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent)

Example 3 with AjaxBehaviorEvent

use of javax.faces.event.AjaxBehaviorEvent in project primefaces by primefaces.

the class AccordionPanel method queueEvent.

@Override
public void queueEvent(FacesEvent event) {
    FacesContext context = getFacesContext();
    if (ComponentUtils.isRequestSource(this, context) && event instanceof AjaxBehaviorEvent) {
        Map<String, String> params = context.getExternalContext().getRequestParameterMap();
        String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
        String clientId = getClientId(context);
        boolean repeating = isRepeating();
        AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
        if ("tabChange".equals(eventName)) {
            String tabClientId = params.get(clientId + "_newTab");
            TabChangeEvent changeEvent = new TabChangeEvent(this, behaviorEvent.getBehavior(), findTab(tabClientId));
            if (repeating) {
                int index = Integer.parseInt(params.get(clientId + "_tabindex"));
                setIndex(index);
                changeEvent.setData(getIndexData());
                changeEvent.setTab(getDynamicTab());
            }
            changeEvent.setPhaseId(behaviorEvent.getPhaseId());
            super.queueEvent(changeEvent);
            if (repeating) {
                setIndex(-1);
            }
        } else if ("tabClose".equals(eventName)) {
            String tabClientId = params.get(clientId + "_tabId");
            TabCloseEvent closeEvent = new TabCloseEvent(this, behaviorEvent.getBehavior(), findTab(tabClientId));
            if (repeating) {
                int index = Integer.parseInt(params.get(clientId + "_tabindex"));
                setIndex(index);
                closeEvent.setData(getIndexData());
                closeEvent.setTab(getDynamicTab());
            }
            closeEvent.setPhaseId(behaviorEvent.getPhaseId());
            super.queueEvent(closeEvent);
            if (repeating) {
                setIndex(-1);
            }
        }
    } else {
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) TabCloseEvent(org.primefaces.event.TabCloseEvent) TabChangeEvent(org.primefaces.event.TabChangeEvent)

Example 4 with AjaxBehaviorEvent

use of javax.faces.event.AjaxBehaviorEvent in project primefaces by primefaces.

the class DialogReturnAware method queueDialogReturnEvent.

default void queueDialogReturnEvent(FacesEvent event, FacesContext context, UIComponent source, Consumer<FacesEvent> queueEvent) {
    Map<String, String> params = context.getExternalContext().getRequestParameterMap();
    AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
    Map<String, Object> session = context.getExternalContext().getSessionMap();
    String dcid = params.get(source.getClientId(context) + "_pfdlgcid");
    Object selectedValue = session.get(dcid);
    session.remove(dcid);
    queueEvent.accept(new SelectEvent(source, behaviorEvent.getBehavior(), selectedValue));
}
Also used : AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) SelectEvent(org.primefaces.event.SelectEvent)

Example 5 with AjaxBehaviorEvent

use of javax.faces.event.AjaxBehaviorEvent in project primefaces by primefaces.

the class InputTextarea method queueEvent.

@Override
public void queueEvent(FacesEvent event) {
    FacesContext context = getFacesContext();
    Map<String, String> params = context.getExternalContext().getRequestParameterMap();
    String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
    if (eventName != null && event instanceof AjaxBehaviorEvent) {
        AjaxBehaviorEvent ajaxBehaviorEvent = (AjaxBehaviorEvent) event;
        if ("itemSelect".equals(eventName)) {
            String selectedItemValue = params.get(getClientId(context) + "_itemSelect");
            SelectEvent selectEvent = new SelectEvent(this, ajaxBehaviorEvent.getBehavior(), selectedItemValue);
            selectEvent.setPhaseId(ajaxBehaviorEvent.getPhaseId());
            super.queueEvent(selectEvent);
        } else {
            // e.g. blur, focus, change
            super.queueEvent(event);
        }
    } else {
        // e.g. valueChange, autoCompleteEvent
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) SelectEvent(org.primefaces.event.SelectEvent)

Aggregations

AjaxBehaviorEvent (javax.faces.event.AjaxBehaviorEvent)56 FacesContext (javax.faces.context.FacesContext)39 SelectEvent (org.primefaces.event.SelectEvent)13 BehaviorEvent (javax.faces.event.BehaviorEvent)9 FacesEvent (javax.faces.event.FacesEvent)9 ItemSelectEvent (org.primefaces.event.ItemSelectEvent)9 FacesException (javax.faces.FacesException)7 UnselectEvent (org.primefaces.event.UnselectEvent)5 Behavior (javax.faces.component.behavior.Behavior)4 ExternalContext (javax.faces.context.ExternalContext)4 PageEvent (org.primefaces.event.data.PageEvent)4 ToggleEvent (org.primefaces.event.ToggleEvent)3 Visibility (org.primefaces.model.Visibility)3 Tab (com.liferay.faces.alloy.component.tab.Tab)2 ZoneId (java.time.ZoneId)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Renderer (javax.faces.render.Renderer)2 CloseEvent (org.primefaces.event.CloseEvent)2 DateViewChangeEvent (org.primefaces.event.DateViewChangeEvent)2