本文整理汇总了Java中javax.faces.context.ExternalContext类的典型用法代码示例。如果您正苦于以下问题:Java ExternalContext类的具体用法?Java ExternalContext怎么用?Java ExternalContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExternalContext类属于javax.faces.context包,在下文中一共展示了ExternalContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: redirectToServiceDetails
import javax.faces.context.ExternalContext; //导入依赖的package包/类
public String redirectToServiceDetails() {
logger.logDebug("entering redirectToServiceDetails");
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext extContext = context.getExternalContext();
String viewId = Marketplace.MARKETPLACE_ROOT + "/serviceDetails.jsf";
try {
viewId = extContext.getRequestContextPath()
+ viewId
+ ui.getSelectedServiceKeyQueryPart(String.valueOf(model
.getSelectedServiceKey()))
+ ui.getMarketplaceIdQueryPart();
String urlLink = context.getExternalContext().encodeActionURL(
viewId);
JSFUtils.redirect(extContext, urlLink);
} catch (IOException e) {
extContext.log(
getClass().getName() + ".redirectToServiceDetails()", e);
} finally {
// reset requested key;
model.setSelectedServiceKey(null);
}
return null;
}
示例2: encodeAllAsElement
import javax.faces.context.ExternalContext; //导入依赖的package包/类
@Override
protected void encodeAllAsElement(
FacesContext context,
RenderingContext rc,
UIComponent component,
FacesBean bean
) throws IOException
{
// call super...
super.encodeAllAsElement(context, rc, component, bean);
// now evaluate the EL
// We need to evaluate it here and store it on the sessionMap because
// during UploadedFileProcessor.processFile() there is no FacesContext
RequestContext requestContext = RequestContext.getCurrentInstance();
Object maxMemory = requestContext.getUploadedFileMaxMemory();
Object maxDiskSpace = requestContext.getUploadedFileMaxDiskSpace();
Object tempDir = requestContext.getUploadedFileTempDir();
ExternalContext external = context.getExternalContext();
Map<String, Object> sessionMap = external.getSessionMap();
sessionMap.put(UploadedFileProcessor.MAX_MEMORY_PARAM_NAME, maxMemory);
sessionMap.put(UploadedFileProcessor.MAX_DISK_SPACE_PARAM_NAME, maxDiskSpace);
sessionMap.put(UploadedFileProcessor.TEMP_DIR_PARAM_NAME, tempDir);
}
示例3: _parseDisplayNameParam
import javax.faces.context.ExternalContext; //导入依赖的package包/类
private static <E extends Enum> Collection<E> _parseDisplayNameParam(
ExternalContext external,
String paramName,
Class<E> enumClass,
E defaultValue
) throws InvalidConfigException
{
try
{
return Enums.parseDisplayNameEnumRequestParameter(external,
paramName,
enumClass,
defaultValue);
}
catch (EnumParseException e)
{
throw new InvalidConfigException(e.getMessage());
}
}
示例4: ParamPregenConfig
import javax.faces.context.ExternalContext; //导入依赖的package包/类
public ParamPregenConfig(FacesContext context)
throws InvalidConfigException
{
ExternalContext external = context.getExternalContext();
_containerTypes = _parseDisplayNameParam(external,
"containerType",
ContainerType.class,
ContainerType.SERVLET);
_requestTypes = _parseDisplayNameParam(external,
"requestType",
RequestType.class,
RequestType.NONSECURE);
_styleClassTypes = _parseDisplayNameParam(external,
"styleClassType",
StyleClassType.class,
StyleClassType.COMPRESSED);
_targetDirectoryPath = _getTargetDirectoryPath(context);
}
示例5: _getServletContextFromFacesContext
import javax.faces.context.ExternalContext; //导入依赖的package包/类
/**
*Returns the servlet context object from the FacesContext
*
* @param context
* @return
*/
private Object _getServletContextFromFacesContext(FacesContext context)
{
ExternalContext ec = null;
Object sc = null;
if (context != null)
{
ec = context.getExternalContext();
if (ec != null)
{
sc = ec.getContext();
}
}
return sc;
}
示例6: getSkin
import javax.faces.context.ExternalContext; //导入依赖的package包/类
/**
* given the skinId, pass back the Skin.
*
* @param context FacesContext. If not available, pass in null.
* @param skinId
* @return Skin that is in this SkinFactory and has the skinId.
* @deprecated use SkinProvider to query skins
*/
@Deprecated
@Override
public Skin getSkin(FacesContext context, String skinId)
{
context = SkinUtils.getNonNullFacesContext(context);
if (skinId == null)
{
_LOG.warning("CANNOT_GET_SKIN_WITH_NULL_SKINID");
return null;
}
ExternalContext ec = context.getExternalContext();
SkinMetadata skinMetadata = new SkinMetadata.Builder().id(skinId).build();
return SkinProvider.getCurrentInstance(ec).getSkin(ec, skinMetadata);
}
示例7: getSelectedServiceKeyQueryPart
import javax.faces.context.ExternalContext; //导入依赖的package包/类
public String getSelectedServiceKeyQueryPart(String selectedServiceKey) {
String selectedService = "";
ExternalContext extContext = getFacesContext().getExternalContext();
String charEncoding = extContext.getRequestCharacterEncoding();
try {
String name = URLEncoder.encode("selectedServiceKey", charEncoding);
String value = URLEncoder.encode(selectedServiceKey, charEncoding);
selectedService = '?' + name + '=' + value;
} catch (UnsupportedEncodingException e) {
extContext.log(getClass().getName()
+ ".getSelectedServiceQueryPart()", e);
}
return selectedService;
}
示例8: setup
import javax.faces.context.ExternalContext; //导入依赖的package包/类
@Before
public void setup() {
validator = new CaptchaValidator();
sessionMock = new HttpSessionStub(Locale.ENGLISH);
context = new FacesContextStub(Locale.ENGLISH) {
@Override
public ExternalContext getExternalContext() {
ExternalContext exContext = spy(new ExternalContextStub(
Locale.ENGLISH));
doReturn(sessionMock).when(exContext).getSession(false);
return exContext;
}
};
inputField = new HtmlInputText() {
@Override
public String getClientId(FacesContext ctx) {
return "";
}
};
}
示例9: saveState
import javax.faces.context.ExternalContext; //导入依赖的package包/类
/**
* Saves the current state to the session. Running this is only manditory if you need to preserve a request across
* the natural request boundry in a portlet environment. Executing this function outside of a portlet environment will
* not alter operation of his class.
*
* @param ec the ExternalContext to save the stateMap to.
*/
public void saveState(ExternalContext ec)
{
RequestType type = ExternalContextUtils.getRequestType(ec);
if(type.isPortlet() && !type.isResponseWritable())
{
try
{
//TODO: use reflection here but it can be replaced..
Object actionResp = ec.getResponse();
Method m = actionResp.getClass().getMethod("setRenderParameter", String.class, String.class);
String uuid = UUID.randomUUID().toString();
ec.getSessionMap().put(_STATE_MAP+"."+uuid, this);
m.invoke(actionResp, _STATE_MAP, uuid);
}
catch(Throwable t)
{
//TODO: Log exception
t.printStackTrace();
}
}
}
示例10: registerFacesDependencies
import javax.faces.context.ExternalContext; //导入依赖的package包/类
public static void registerFacesDependencies(ConfigurableListableBeanFactory beanFactory) {
beanFactory.registerResolvableDependency(FacesContext.class, new ObjectFactory<FacesContext>() {
@Override
public FacesContext getObject() {
return FacesContext.getCurrentInstance();
}
@Override
public String toString() {
return "Current JSF FacesContext";
}
});
beanFactory.registerResolvableDependency(ExternalContext.class, new ObjectFactory<ExternalContext>() {
@Override
public ExternalContext getObject() {
return FacesContext.getCurrentInstance().getExternalContext();
}
@Override
public String toString() {
return "Current JSF ExternalContext";
}
});
}
示例11: setUp
import javax.faces.context.ExternalContext; //导入依赖的package包/类
@Override
protected void setUp() throws IOException
{
MFacesContext ctx = new MFacesContext(MApplication.sharedInstance(), true);
ExternalContext externalContext = ctx.getExternalContext();
Map<String, Object> applicationMap = externalContext.getApplicationMap();
applicationMap.put(TrinidadSkinProvider.TRINDIAD_SKIN_PROVIDER_KEY,
new TrinidadSkinProvider());
applicationMap.put(ExternalSkinProvider.EXTERNAL_SKIN_PROVIDER_KEY,
new ExternalSkinProvider());
applicationMap.put(SkinProvider.SKIN_PROVIDER_INSTANCE_KEY,
new SkinProviderRegistry());
_facesContext = ctx;
_externalContext = externalContext;
_provider = SkinProvider.getCurrentInstance(_externalContext);
if (SkinFactory.getFactory() == null)
SkinFactory.setFactory(new SkinFactoryImpl());
RenderKitBootstrap.setFactories(_facesConfigInfo);
}
示例12: reloadSkins
import javax.faces.context.ExternalContext; //导入依赖的package包/类
/**
* @inheritDoc
*/
@Override
@Deprecated
public void reloadSkins(ExternalContext externalContext, SkinFactory skinFactory)
{
// ask all subordinate configurators to reload their skins
// We do not load the base skins and trinidad-skins eagerly.
// When any configurator tries to register its skins to the SKinFactory,
// it may be calling skinFactory.getSkin(...) to get hold of a base skin.
// As SkinFactory is now under SkinProvider SPI, it makes sure that internally all parents are lazy loaded.
// thus the caller will get a base Skin which he wants, but we do not load all skins eagerly.
for (final Configurator config: _services)
{
config.reloadSkins(externalContext, skinFactory);
}
}
示例13: TrinidadComponentHandler
import javax.faces.context.ExternalContext; //导入依赖的package包/类
public TrinidadComponentHandler(ComponentConfig config)
{
super(config);
if (_markInitialState == null)
{
// Can't imagine why this wouldn't always run during
// a Faces request...
FacesContext context = FacesContext.getCurrentInstance();
if (context != null)
{
ExternalContext external = context.getExternalContext();
String restoreMode = external.getInitParameter(
StateManager.PARTIAL_STATE_SAVING_PARAM_NAME);
if (Boolean.valueOf(restoreMode))
{
_markInitialState = Boolean.TRUE;
_LOG.severe("PARTIAL_STATE_SAVING_NOT_SUPPORTED");
}
else
{
_markInitialState = Boolean.FALSE;
}
}
}
}
示例14: _getPprOptimization
import javax.faces.context.ExternalContext; //导入依赖的package包/类
/**
* Returns the value of the PPR optimization parameter. We currently support "on" and "off"
* @param context
* @return
*/
private static String _getPprOptimization(FacesContext context)
{
ExternalContext external = context.getExternalContext();
Map<String, Object> applicationMap = external.getApplicationMap();
// first check if this has been overridden at the application level
String pprOptimization = (String)applicationMap.get(_PPR_OPTIMIZATION_PROP);
if (pprOptimization == null)
{
// the value hasn't been set, so check the initialization parameter
pprOptimization = external.getInitParameter(_PPR_OPTIMIZATION_PROP);
// default to "off"
if (pprOptimization == null)
pprOptimization = "off";
// cache in the application so that we don't need to fetch this again
applicationMap.put(_PPR_OPTIMIZATION_PROP, pprOptimization);
}
return pprOptimization;
}
示例15: construct
import javax.faces.context.ExternalContext; //导入依赖的package包/类
/**
* This fires during the Render Response phase, saving state.
*/
public static final String construct(Object object, ExternalContext ctx)
{
byte[] bytes = getAsByteArray(object, ctx);
if( enableCompression(ctx) )
{
bytes = compress(bytes);
}
if(isSecure(ctx))
{
bytes = encrypt(bytes, ctx);
}
bytes = encode(bytes);
try
{
return new String(bytes, ZIP_CHARSET);
}
catch (UnsupportedEncodingException e)
{
throw new FacesException(e);
}
}