org.primefaces.context.RequestContext Maven / Gradle / Ivy
/*
* Copyright 2009-2013 PrimeTek.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.primefaces.context;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.faces.application.FacesMessage;
import org.primefaces.component.api.AutoUpdatable;
import org.primefaces.util.AjaxRequestBuilder;
import org.primefaces.util.CSVBuilder;
import org.primefaces.util.StringEncrypter;
import org.primefaces.util.WidgetBuilder;
/**
* A RequestContext is a helper class consisting of several utilities.
* RequestContext is thread-safe and scope is same as FacesContext.
* Current instance can be retrieved as;
*
* RequestContext.getCurrentInstance();
*
*/
public abstract class RequestContext {
private static final ThreadLocal INSTANCE = new ThreadLocal();
public static RequestContext getCurrentInstance() {
return INSTANCE.get();
}
public static void setCurrentInstance(final RequestContext context) {
if (context == null) {
INSTANCE.remove();
} else {
INSTANCE.set(context);
}
}
/**
* @return true if request is an ajax request, otherwise return false.
*/
public abstract boolean isAjaxRequest();
/**
* Add a parameter for ajax oncomplete client side callbacks. Value would be serialized to json.
* @param name name of the parameter.
* @param object value of the parameter.
*/
public abstract void addCallbackParam(String name, Object value);
/**
* @return all callback parameters added in the current request.
*/
public abstract Map getCallbackParams();
/**
* @return all scripts added in the current request.
*/
public abstract List getScriptsToExecute();
/**
* Execute a javascript after current ajax request is completed.
* @param script Javascript statement to execute.
*/
public abstract void execute(String script);
/**
* Scroll to a component after ajax request is completed.
* @param clientId Client side identifier of the component.
*/
public abstract void scrollTo(String clientId);
/**
* Update a component with ajax.
* @param name Client side identifier of the component.
*/
public abstract void update(String name);
/**
* Update components with ajax.
* @param collection Client side identifiers of the components.
*/
public abstract void update(Collection collection);
/**
* Reset an editableValueHolder.
* @param expressions A string with one or multiple search expression to resolve the components.
*/
public abstract void reset(String expressions);
/**
* Reset a collection of editableValueHolders.
* @param expressions A list with with one or multiple search expression to resolve the components.
*/
public abstract void reset(Collection expressions);
/**
* @return Shared WidgetBuilder instance of the current request
*/
public abstract WidgetBuilder getWidgetBuilder();
/**
* @return Shared AjaxRequestBuilder instance of the current request
*/
public abstract AjaxRequestBuilder getAjaxRequestBuilder();
/**
* @return Shared Client Side Validation builder instance of the current request
*/
public abstract CSVBuilder getCSVBuilder();
/**
* @return Attributes map in RequestContext scope
*/
public abstract Map