Search in sources :

Example 1 with UnselectEvent

use of org.primefaces.event.UnselectEvent in project primefaces by primefaces.

the class Chips 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)) {
            Object selectedItemValue = ComponentUtils.getConvertedValue(context, this, params.get(getClientId(context) + "_itemSelect"));
            SelectEvent selectEvent = new SelectEvent(this, ajaxBehaviorEvent.getBehavior(), selectedItemValue);
            selectEvent.setPhaseId(ajaxBehaviorEvent.getPhaseId());
            super.queueEvent(selectEvent);
        } else if ("itemUnselect".equals(eventName)) {
            Object unselectedItemValue = ComponentUtils.getConvertedValue(context, this, params.get(getClientId(context) + "_itemUnselect"));
            UnselectEvent unselectEvent = new UnselectEvent(this, ajaxBehaviorEvent.getBehavior(), unselectedItemValue);
            unselectEvent.setPhaseId(ajaxBehaviorEvent.getPhaseId());
            super.queueEvent(unselectEvent);
        } else {
            // e.g. blur, focus, change
            super.queueEvent(event);
        }
    } else {
        // e.g. valueChange
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) UnselectEvent(org.primefaces.event.UnselectEvent) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) SelectEvent(org.primefaces.event.SelectEvent)

Example 2 with UnselectEvent

use of org.primefaces.event.UnselectEvent in project primefaces by primefaces.

the class AutoComplete 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)) {
            Object selectedItemValue = ComponentUtils.getConvertedValue(context, this, params.get(getClientId(context) + "_itemSelect"));
            SelectEvent selectEvent = new SelectEvent(this, ajaxBehaviorEvent.getBehavior(), selectedItemValue);
            selectEvent.setPhaseId(ajaxBehaviorEvent.getPhaseId());
            super.queueEvent(selectEvent);
        } else if ("itemUnselect".equals(eventName)) {
            Object unselectedItemValue = ComponentUtils.getConvertedValue(context, this, params.get(getClientId(context) + "_itemUnselect"));
            UnselectEvent unselectEvent = new UnselectEvent(this, ajaxBehaviorEvent.getBehavior(), unselectedItemValue);
            unselectEvent.setPhaseId(ajaxBehaviorEvent.getPhaseId());
            super.queueEvent(unselectEvent);
        } else if ("moreTextSelect".equals(eventName) || "emptyMessageSelect".equals(eventName) || "clear".equals(eventName)) {
            ajaxBehaviorEvent.setPhaseId(event.getPhaseId());
            super.queueEvent(ajaxBehaviorEvent);
        } else {
            // e.g. blur, focus, change
            super.queueEvent(event);
        }
    } else {
        // e.g. valueChange, autoCompleteEvent
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) UnselectEvent(org.primefaces.event.UnselectEvent) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) SelectEvent(org.primefaces.event.SelectEvent)

Example 3 with UnselectEvent

use of org.primefaces.event.UnselectEvent in project primefaces by primefaces.

the class PickList method validate.

@Override
public void validate(FacesContext context) {
    super.validate(context);
    if (isValid() && customEvents != null) {
        for (Map.Entry<String, AjaxBehaviorEvent> event : customEvents.entrySet()) {
            String eventName = event.getKey();
            AjaxBehaviorEvent behaviorEvent = event.getValue();
            Map<String, String> params = context.getExternalContext().getRequestParameterMap();
            String clientId = getClientId(context);
            DualListModel<?> list = (DualListModel<?>) getValue();
            FacesEvent wrapperEvent = null;
            if ("select".equals(eventName)) {
                String listName = params.get(clientId + "_listName");
                int itemIndex = Integer.parseInt(params.get(clientId + "_itemIndex"));
                if ("target".equals(listName)) {
                    wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), list.getTarget().get(itemIndex));
                } else {
                    wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), list.getSource().get(itemIndex));
                }
            } else if ("unselect".equals(eventName)) {
                String listName = params.get(clientId + "_listName");
                int itemIndex = Integer.parseInt(params.get(clientId + "_itemIndex"));
                if ("target".equals(listName)) {
                    wrapperEvent = new UnselectEvent(this, behaviorEvent.getBehavior(), list.getTarget().get(itemIndex));
                } else {
                    wrapperEvent = new UnselectEvent(this, behaviorEvent.getBehavior(), list.getSource().get(itemIndex));
                }
            } else if ("reorder".equals(eventName)) {
                wrapperEvent = behaviorEvent;
            }
            if (wrapperEvent == null) {
                throw new FacesException("Component " + this.getClass().getName() + " does not support event " + eventName + "!");
            }
            wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
            super.queueEvent(wrapperEvent);
        }
    }
}
Also used : DualListModel(org.primefaces.model.DualListModel) UnselectEvent(org.primefaces.event.UnselectEvent) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) FacesEvent(javax.faces.event.FacesEvent) SelectEvent(org.primefaces.event.SelectEvent) FacesException(javax.faces.FacesException)

Example 4 with UnselectEvent

use of org.primefaces.event.UnselectEvent in project primefaces by primefaces.

the class OrderList method validate.

@Override
public void validate(FacesContext context) {
    super.validate(context);
    if (isValid() && customEvents != null) {
        for (Map.Entry<String, AjaxBehaviorEvent> event : customEvents.entrySet()) {
            String eventName = event.getKey();
            AjaxBehaviorEvent behaviorEvent = event.getValue();
            Map<String, String> params = context.getExternalContext().getRequestParameterMap();
            String clientId = getClientId(context);
            List<?> list = (List) getValue();
            FacesEvent wrapperEvent = null;
            if ("select".equals(eventName)) {
                int itemIndex = Integer.parseInt(params.get(clientId + "_itemIndex"));
                boolean metaKey = Boolean.parseBoolean(params.get(clientId + "_metaKey"));
                boolean ctrlKey = Boolean.parseBoolean(params.get(clientId + "_ctrlKey"));
                wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), list.get(itemIndex), metaKey, ctrlKey);
            } else if ("unselect".equals(eventName)) {
                int itemIndex = Integer.parseInt(params.get(clientId + "_itemIndex"));
                wrapperEvent = new UnselectEvent(this, behaviorEvent.getBehavior(), list.get(itemIndex));
            } else if ("reorder".equals(eventName)) {
                wrapperEvent = behaviorEvent;
            }
            if (wrapperEvent == null) {
                throw new FacesException("Component " + this.getClass().getName() + " does not support event " + eventName + "!");
            }
            wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
            super.queueEvent(wrapperEvent);
        }
    }
}
Also used : UnselectEvent(org.primefaces.event.UnselectEvent) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) FacesEvent(javax.faces.event.FacesEvent) SelectEvent(org.primefaces.event.SelectEvent) FacesException(javax.faces.FacesException)

Example 5 with UnselectEvent

use of org.primefaces.event.UnselectEvent in project primefaces by primefaces.

the class SelectCheckboxMenu 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 ("toggleSelect".equals(eventName)) {
            String clientId = getClientId(context);
            boolean checked = Boolean.parseBoolean(params.get(clientId + "_checked"));
            ToggleSelectEvent toggleSelectEvent = new ToggleSelectEvent(this, ((AjaxBehaviorEvent) event).getBehavior(), checked);
            toggleSelectEvent.setPhaseId(event.getPhaseId());
            super.queueEvent(toggleSelectEvent);
        } else if ("itemUnselect".equals(eventName)) {
            Object unselectedItemValue = ComponentUtils.getConvertedValue(context, this, params.get(getClientId(context) + "_itemUnselect"));
            UnselectEvent unselectEvent = new UnselectEvent(this, ajaxBehaviorEvent.getBehavior(), unselectedItemValue);
            unselectEvent.setPhaseId(ajaxBehaviorEvent.getPhaseId());
            super.queueEvent(unselectEvent);
        } else {
            super.queueEvent(event);
        }
    } else {
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) UnselectEvent(org.primefaces.event.UnselectEvent) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) ToggleSelectEvent(org.primefaces.event.ToggleSelectEvent)

Aggregations

AjaxBehaviorEvent (javax.faces.event.AjaxBehaviorEvent)5 UnselectEvent (org.primefaces.event.UnselectEvent)5 SelectEvent (org.primefaces.event.SelectEvent)4 FacesContext (javax.faces.context.FacesContext)3 FacesException (javax.faces.FacesException)2 FacesEvent (javax.faces.event.FacesEvent)2 ToggleSelectEvent (org.primefaces.event.ToggleSelectEvent)1 DualListModel (org.primefaces.model.DualListModel)1