Search in sources :

Example 1 with AjaxRequestBuilder

use of org.primefaces.util.AjaxRequestBuilder in project primefaces by primefaces.

the class AjaxBehaviorRenderer method getScript.

@Override
public String getScript(ClientBehaviorContext behaviorContext, ClientBehavior behavior) {
    AjaxBehavior ajaxBehavior = (AjaxBehavior) behavior;
    if (ajaxBehavior.isDisabled()) {
        return null;
    }
    UIComponent component = behaviorContext.getComponent();
    ClientBehaviorRenderingMode renderingMode = ClientBehaviorRenderingMode.OBSTRUSIVE;
    Collection<ClientBehaviorContext.Parameter> behaviorParameters = behaviorContext.getParameters();
    if (behaviorParameters != null && !behaviorParameters.isEmpty()) {
        // perf optimzation
        if (behaviorParameters instanceof ArrayList) {
            for (int i = 0; i < behaviorParameters.size(); i++) {
                ClientBehaviorContext.Parameter behaviorParameter = ((ArrayList<ClientBehaviorContext.Parameter>) behaviorParameters).get(i);
                if (behaviorParameter.getValue() instanceof ClientBehaviorRenderingMode) {
                    renderingMode = (ClientBehaviorRenderingMode) behaviorParameter.getValue();
                    break;
                }
            }
        } else {
            for (ClientBehaviorContext.Parameter behaviorParameter : behaviorParameters) {
                if (behaviorParameter.getValue() instanceof ClientBehaviorRenderingMode) {
                    renderingMode = (ClientBehaviorRenderingMode) behaviorParameter.getValue();
                    break;
                }
            }
        }
    }
    String source = behaviorContext.getSourceId();
    String process = ajaxBehavior.getProcess();
    if (process == null) {
        process = "@this";
    }
    AjaxRequestBuilder builder = PrimeRequestContext.getCurrentInstance().getAjaxRequestBuilder();
    String request = builder.init().source(source).event(behaviorContext.getEventName()).form(ajaxBehavior, component).process(component, process, ajaxBehavior.isIgnoreComponentNotFound()).update(component, ajaxBehavior.getUpdate(), ajaxBehavior.isIgnoreComponentNotFound()).async(ajaxBehavior.isAsync()).global(ajaxBehavior.isGlobal()).delay(ajaxBehavior.getDelay()).timeout(ajaxBehavior.getTimeout()).partialSubmit(ajaxBehavior.isPartialSubmit(), ajaxBehavior.isPartialSubmitSet(), ajaxBehavior.getPartialSubmitFilter()).resetValues(ajaxBehavior.isResetValues(), ajaxBehavior.isResetValuesSet()).ignoreAutoUpdate(ajaxBehavior.isIgnoreAutoUpdate()).skipChildren(ajaxBehavior.isSkipChildren()).onstart(ajaxBehavior.getOnstart()).onerror(ajaxBehavior.getOnerror()).onsuccess(ajaxBehavior.getOnsuccess()).oncomplete(ajaxBehavior.getOncomplete()).params(component).buildBehavior(renderingMode);
    return request;
}
Also used : ClientBehaviorRenderingMode(org.primefaces.component.api.ClientBehaviorRenderingMode) UIComponent(javax.faces.component.UIComponent) ArrayList(java.util.ArrayList) AjaxRequestBuilder(org.primefaces.util.AjaxRequestBuilder) ClientBehaviorContext(javax.faces.component.behavior.ClientBehaviorContext)

Aggregations

ArrayList (java.util.ArrayList)1 UIComponent (javax.faces.component.UIComponent)1 ClientBehaviorContext (javax.faces.component.behavior.ClientBehaviorContext)1 ClientBehaviorRenderingMode (org.primefaces.component.api.ClientBehaviorRenderingMode)1 AjaxRequestBuilder (org.primefaces.util.AjaxRequestBuilder)1