Search in sources :

Example 1 with ClientBehavior

use of javax.faces.component.behavior.ClientBehavior in project liferay-faces-alloy by liferay.

the class DataTableRenderer method getColumnClientBehaviorScript.

protected String getColumnClientBehaviorScript(FacesContext facesContext, DataTable dataTable, Column column, String clientId) {
    String clientBehaviorScript = null;
    Map<String, List<ClientBehavior>> clientBehaviorMap = column.getClientBehaviors();
    String defaultEventName = column.getDefaultEventName();
    List<ClientBehavior> clientBehaviorsForEvent = clientBehaviorMap.get(defaultEventName);
    if (clientBehaviorsForEvent != null) {
        for (ClientBehavior clientBehavior : clientBehaviorsForEvent) {
            List<ClientBehaviorContext.Parameter> parameters = new ArrayList<ClientBehaviorContext.Parameter>();
            String sortColumnClientIdParamName = clientId.concat("_sortColumnClientId");
            String sortColumnClientId = column.getClientId(facesContext);
            parameters.add(new ClientBehaviorContext.Parameter(sortColumnClientIdParamName, sortColumnClientId));
            String eventMetaKeyParamName = clientId.concat("_eventMetaKey");
            parameters.add(new ClientBehaviorContext.Parameter(eventMetaKeyParamName, "event.metaKey"));
            ClientBehaviorContext clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, dataTable, defaultEventName, clientId, parameters);
            clientBehaviorScript = clientBehavior.getScript(clientBehaviorContext);
        }
    }
    if (clientBehaviorScript != null) {
        clientBehaviorScript = clientBehaviorScript.replaceFirst("'event.metaKey'", "event.metaKey");
    }
    return clientBehaviorScript;
}
Also used : ArrayList(java.util.ArrayList) UIParameter(javax.faces.component.UIParameter) ArrayList(java.util.ArrayList) List(java.util.List) ClientBehavior(javax.faces.component.behavior.ClientBehavior) ClientBehaviorContext(javax.faces.component.behavior.ClientBehaviorContext)

Example 2 with ClientBehavior

use of javax.faces.component.behavior.ClientBehavior in project liferay-faces-alloy by liferay.

the class AccordionRenderer method encodeJavaScriptCustom.

@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    // Encode a script that will handle the client-side state of the selected tab index, as well as submitting
    // Ajax requests to support server-side events.
    Accordion accordion = (Accordion) uiComponent;
    // var accordionClientVarName = Liferay.component('{clientKey}');
    String clientVarName = getClientVarName(facesContext, accordion);
    String clientKey = accordion.getClientKey();
    if (clientKey == null) {
        clientKey = clientVarName;
    }
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
    // Expand the selected tab.
    Integer selectedIndex = accordion.getSelectedIndex();
    if ((selectedIndex != null) && (selectedIndex > -1)) {
        DataEncoderBase dataEncoder = new DataEncoderTabJavaScriptImpl(selectedIndex, clientVarName);
        dataEncoder.encodeColumns(facesContext, accordion);
    }
    // LFAI.initAccordion(multiple, accordionClientVarName, '{clientId}selectedIndex', '{clientId}',
    // [tabExpandClientBehaviorScriptFunction1, tabExpandClientBehaviorScriptFunction2,
    // tabExpandClientBehaviorScriptFunction3], '{clientId}collapsedTabIndex',
    // [tabCollapseClientBehaviorScriptFunction1, tabCollapseClientBehaviorScriptFunction2,
    // tabCollapseClientBehaviorScriptFunction3]);
    boolean multiple = accordion.isMultiple();
    String clientId = accordion.getClientId(facesContext);
    StringBuilder tabExpandedClientBehaviors = new StringBuilder();
    tabExpandedClientBehaviors.append("[");
    StringBuilder tabCollapsedClientBehaviors = new StringBuilder();
    tabCollapsedClientBehaviors.append("[");
    boolean firstTabExpandedClientBehavior = true;
    boolean firstTabCollapsedClientBehavior = true;
    Map<String, List<ClientBehavior>> clientBehaviorMap = accordion.getClientBehaviors();
    Collection<String> eventNames = accordion.getEventNames();
    for (String eventName : eventNames) {
        List<ClientBehavior> clientBehaviorsForEvent = clientBehaviorMap.get(eventName);
        if (clientBehaviorsForEvent != null) {
            for (ClientBehavior clientBehavior : clientBehaviorsForEvent) {
                ClientBehaviorContext clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, accordion, eventName, clientId, null);
                // an Ajax request.
                if (TabExpandEvent.TAB_EXPAND.equals(eventName)) {
                    if (!firstTabExpandedClientBehavior) {
                        tabExpandedClientBehaviors.append(",");
                    }
                    // J-
                    // function(event) {
                    // jsf.ajax.request(this, event, {'javax.faces.behavior.event': 'tabSelect'})
                    // };
                    // J+
                    tabExpandedClientBehaviors.append("function(event){");
                    tabExpandedClientBehaviors.append(clientBehavior.getScript(clientBehaviorContext));
                    tabExpandedClientBehaviors.append("}");
                    firstTabExpandedClientBehavior = false;
                } else // an Ajax request.
                if (TabCollapseEvent.TAB_COLLAPSE.equals(eventName)) {
                    if (!firstTabCollapsedClientBehavior) {
                        tabCollapsedClientBehaviors.append(",");
                    }
                    // J-
                    // function(event) {
                    // jsf.ajax.request(this, event, {'javax.faces.behavior.event': 'tabSelect'})
                    // };
                    // J+
                    tabCollapsedClientBehaviors.append("function(event){");
                    tabCollapsedClientBehaviors.append(clientBehavior.getScript(clientBehaviorContext));
                    tabCollapsedClientBehaviors.append("}");
                    firstTabCollapsedClientBehavior = false;
                }
            }
        }
    }
    tabExpandedClientBehaviors.append("]");
    tabCollapsedClientBehaviors.append("]");
    encodeFunctionCall(responseWriter, "LFAI.initAccordion", multiple, new JavaScriptFragment(clientVarName), clientId + "selectedIndex", clientId, new JavaScriptFragment(tabExpandedClientBehaviors.toString()), clientId + "collapsedTabIndex", new JavaScriptFragment(tabCollapsedClientBehaviors.toString()));
}
Also used : ClientBehaviorContext(javax.faces.component.behavior.ClientBehaviorContext) Accordion(com.liferay.faces.alloy.component.accordion.Accordion) ResponseWriter(javax.faces.context.ResponseWriter) JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) DataEncoderBase(com.liferay.faces.alloy.component.data.internal.DataEncoderBase) List(java.util.List) ClientBehavior(javax.faces.component.behavior.ClientBehavior)

Example 3 with ClientBehavior

use of javax.faces.component.behavior.ClientBehavior in project liferay-faces-alloy by liferay.

the class AutoCompleteRenderer method getModules.

@Override
public String[] getModules(FacesContext facesContext, UIComponent uiComponent) {
    String[] modules = MODULES;
    AutoComplete autoComplete = (AutoComplete) uiComponent;
    String clientFilterType = autoComplete.getClientFilterType();
    String clientCustomFilter = autoComplete.getClientCustomFilter();
    // "autocomplete-filters" module.
    if (!isServerFilteringEnabled(autoComplete) && (clientFilterType != null) && (clientFilterType.length() > 0) && (clientCustomFilter == null)) {
        modules = StringHelper.append(modules, AUTOCOMPLETE_FILTERS);
    }
    String highlighterType = autoComplete.getHighlighterType();
    if (highlighterType != null) {
        modules = StringHelper.append(modules, AUTOCOMPLETE_HIGHLIGHTERS);
    }
    Map<String, List<ClientBehavior>> clientBehaviorMap = autoComplete.getClientBehaviors();
    List<ClientBehavior> valueChangeClientBehaviors = clientBehaviorMap.get(VALUE_CHANGE);
    if ((valueChangeClientBehaviors != null) && !valueChangeClientBehaviors.isEmpty()) {
        modules = StringHelper.append(modules, NODE_EVENT_SIMULATE);
    }
    return modules;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AutoComplete(com.liferay.faces.alloy.component.autocomplete.AutoComplete) ClientBehavior(javax.faces.component.behavior.ClientBehavior)

Example 4 with ClientBehavior

use of javax.faces.component.behavior.ClientBehavior in project liferay-faces-alloy by liferay.

the class ProgressBarRenderer method encodeHiddenAttributes.

@Override
protected void encodeHiddenAttributes(FacesContext facesContext, ResponseWriter responseWriter, ProgressBar progressBar, boolean first) throws IOException {
    // render: true
    encodeWidgetRender(responseWriter, first);
    first = false;
    // contentBox
    String clientId = progressBar.getClientId(facesContext);
    String contentBoxClientId = clientId.concat(CONTENT_BOX_SUFFIX);
    encodeClientId(responseWriter, CONTENT_BOX, contentBoxClientId, first);
    // Begin encoding event listeners that occur on the event.
    encodeNonEscapedObject(responseWriter, "on", "", first);
    responseWriter.write("{");
    // complete
    boolean onFirst = true;
    String oncomplete = progressBar.getOncomplete();
    Map<String, List<ClientBehavior>> clientBehaviorMap = progressBar.getClientBehaviors();
    List<ClientBehavior> clientBehaviorsForComplete = clientBehaviorMap.get("progressComplete");
    if ((oncomplete != null) || ((clientBehaviorsForComplete != null) && !clientBehaviorsForComplete.isEmpty())) {
        // J-
        // function(event) {
        // oncomplete();
        // jsf.ajax.request(...);
        // jsf.ajax.request(...);
        // ...
        // jsf.ajax.request(...);
        // }
        // J+
        StringBuilder onCompleteBuilder = new StringBuilder();
        onCompleteBuilder.append("function(event){");
        if (oncomplete != null) {
            onCompleteBuilder.append(oncomplete);
        }
        if ((clientBehaviorsForComplete != null) && !clientBehaviorsForComplete.isEmpty()) {
            ClientBehaviorContext clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, progressBar, "progressComplete", clientId, null);
            for (ClientBehavior clientBehaviorForComplete : clientBehaviorsForComplete) {
                onCompleteBuilder.append(clientBehaviorForComplete.getScript(clientBehaviorContext));
                onCompleteBuilder.append(";");
            }
        }
        onCompleteBuilder.append("}");
        encodeNonEscapedObject(responseWriter, COMPLETE, onCompleteBuilder.toString(), onFirst);
        onFirst = false;
    }
    // label
    String label = progressBar.getLabel();
    // J+
    if ((label != null) && label.contains(TOKEN)) {
        String escapedLabel = RendererUtil.escapeJavaScript(label);
        encodeNonEscapedObject(responseWriter, VALUE_CHANGE, "function(event){this.set('label','".concat(escapedLabel).concat("'.replace(LFAI.TOKEN_REGEX, event.newVal));}"), onFirst);
        onFirst = false;
    }
    // Finish encoding event listeners that occur on the event.
    responseWriter.write("}");
}
Also used : List(java.util.List) ClientBehavior(javax.faces.component.behavior.ClientBehavior) ClientBehaviorContext(javax.faces.component.behavior.ClientBehaviorContext)

Example 5 with ClientBehavior

use of javax.faces.component.behavior.ClientBehavior in project liferay-faces-alloy by liferay.

the class PaginatorRenderer method getClientBehaviorScript.

protected String getClientBehaviorScript(FacesContext facesContext, Paginator paginator, String clientId, String paginatorAction) {
    String clientBehaviorScript = null;
    Map<String, List<ClientBehavior>> clientBehaviorMap = paginator.getClientBehaviors();
    String defaultEventName = paginator.getDefaultEventName();
    String paginatorActionParamName = clientId.concat("_paginatorAction");
    List<ClientBehavior> clientBehaviorsForEvent = clientBehaviorMap.get(defaultEventName);
    if (clientBehaviorsForEvent != null) {
        for (ClientBehavior clientBehavior : clientBehaviorsForEvent) {
            List<ClientBehaviorContext.Parameter> parameters = new ArrayList<ClientBehaviorContext.Parameter>();
            parameters.add(new ClientBehaviorContext.Parameter(paginatorActionParamName, paginatorAction));
            ClientBehaviorContext clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, paginator, defaultEventName, clientId, parameters);
            clientBehaviorScript = clientBehavior.getScript(clientBehaviorContext);
        }
    }
    return clientBehaviorScript;
}
Also used : ArrayList(java.util.ArrayList) UIParameter(javax.faces.component.UIParameter) ArrayList(java.util.ArrayList) List(java.util.List) ClientBehavior(javax.faces.component.behavior.ClientBehavior) ClientBehaviorContext(javax.faces.component.behavior.ClientBehaviorContext)

Aggregations

ClientBehavior (javax.faces.component.behavior.ClientBehavior)20 List (java.util.List)14 ClientBehaviorContext (javax.faces.component.behavior.ClientBehaviorContext)12 JavaScriptFragment (com.liferay.faces.util.render.JavaScriptFragment)6 ResponseWriter (javax.faces.context.ResponseWriter)5 ArrayList (java.util.ArrayList)4 ClientBehaviorHolder (javax.faces.component.behavior.ClientBehaviorHolder)4 UIParameter (javax.faces.component.UIParameter)3 DataEncoderBase (com.liferay.faces.alloy.component.data.internal.DataEncoderBase)2 ProgressBar (com.liferay.faces.alloy.component.progressbar.ProgressBar)2 EscapedClientId (com.liferay.faces.alloy.render.internal.EscapedClientId)2 MixedClientBehaviorHolder (org.primefaces.component.api.MixedClientBehaviorHolder)2 Accordion (com.liferay.faces.alloy.component.accordion.Accordion)1 AutoComplete (com.liferay.faces.alloy.component.autocomplete.AutoComplete)1 InputDateTime (com.liferay.faces.alloy.component.inputdatetime.InputDateTime)1 TabView (com.liferay.faces.alloy.component.tabview.TabView)1 BrowserSniffer (com.liferay.faces.util.client.BrowserSniffer)1 BufferedScriptResponseWriter (com.liferay.faces.util.render.BufferedScriptResponseWriter)1 AjaxBehavior (javax.faces.component.behavior.AjaxBehavior)1 AjaxBehavior (org.primefaces.behavior.ajax.AjaxBehavior)1