本文整理匯總了Java中javax.faces.context.ExternalContext.getResponse方法的典型用法代碼示例。如果您正苦於以下問題:Java ExternalContext.getResponse方法的具體用法?Java ExternalContext.getResponse怎麽用?Java ExternalContext.getResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.faces.context.ExternalContext
的用法示例。
在下文中一共展示了ExternalContext.getResponse方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleError
import javax.faces.context.ExternalContext; //導入方法依賴的package包/類
/**
* Handle a server-side error by reporting it back to the client.
*/
public static void handleError(ExternalContext ec,
Throwable t) throws IOException
{
String error = _getErrorString();
_LOG.severe(error, t);
ServletResponse response = (ServletResponse)ec.getResponse();
PrintWriter writer = response.getWriter();
XmlResponseWriter rw = new XmlResponseWriter(writer, "UTF-8");
rw.startDocument();
rw.startElement("partial-response", null);
rw.startElement("error", null);
rw.startElement("error-name", null);
rw.writeText(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null);
rw.endElement("error-name");
String errorMessage = _getErrorMessage(error);
// Default exception message contains the type of the exception.
// Do not send this info to client in Production mode
ApplicationFactory factory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
if (application.getProjectStage() != ProjectStage.Production)
{
errorMessage = _getExceptionString(t) + errorMessage;
}
rw.startElement("error-message", null);
rw.writeText(errorMessage, null);
rw.endElement("error-message");
rw.endElement("error");
rw.endElement("partial-response");
rw.endDocument();
rw.close();
}
示例2: 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();
}
}
}
示例3: renderNoopResponse
import javax.faces.context.ExternalContext; //導入方法依賴的package包/類
/**
* This method writes a <noop/> to the response.
*
* @param context the FacesContext
* @throws IOException
*/
public static void renderNoopResponse(FacesContext context)
throws IOException
{
ExternalContext external = context.getExternalContext();
Writer writer = ExternalContextUtils.getResponseWriter(external);
Object response = external.getResponse();
if (response instanceof HttpServletResponse)
{
HttpServletResponse httpResponse = (HttpServletResponse) response;
// Prevent caching
httpResponse.setHeader("Cache-Control", "no-cache");
httpResponse.setHeader("Pragma", "no-cache");
httpResponse.setHeader("Expires", "-1");
}
XmlResponseWriter xrw = new XmlResponseWriter(writer, "utf-8");
xrw.startDocument();
xrw.startElement("partial-response", null);
xrw.startElement("noop", null);
xrw.endElement("noop");
xrw.endElement("partial-response");
xrw.endDocument();
xrw.close();
}
示例4: UploadActionRequestWrapper
import javax.faces.context.ExternalContext; //導入方法依賴的package包/類
public UploadActionRequestWrapper(
ExternalContext ec,
Map<String, String[]> params)
{
super((ActionRequest)ec.getRequest());
_response = (ActionResponse)ec.getResponse();
_manager = new UploadRequestManager(ec, params);
}
示例5: XmlHttpResourceResponse
import javax.faces.context.ExternalContext; //導入方法依賴的package包/類
public XmlHttpResourceResponse(ExternalContext ec)
{
super((ResourceResponse) ec.getResponse());
_contentType = "text/xml;charset=utf-8";
// must set contentType here since
// setContentType is ignored when inside an included page (bug 5591124)
super.setContentType(_contentType);
}
示例6: XmlHttpServletResponse
import javax.faces.context.ExternalContext; //導入方法依賴的package包/類
XmlHttpServletResponse(ExternalContext ec)
{
super((HttpServletResponse)ec.getResponse());
_contentType = "text/xml;charset=utf-8";
// must set contentType here since
// setContentType is ignored when inside an included page (bug 5591124)
this.setContentType(_contentType);
}
示例7: _handleDialogReturn
import javax.faces.context.ExternalContext; //導入方法依賴的package包/類
private void _handleDialogReturn(ExternalContext ec)
throws IOException
{
Map<String, Object> reqMap = ec.getRequestMap();
if(Boolean.TRUE.equals(reqMap.get(DialogServiceImpl.DIALOG_RETURN)))
{
/**
* We use pageflow scope so that if something fails on the redirect, we
* have a chance of getting cleaned up early. This will not always happen
* so the object may stick around for a while.
*/
Map<String, Object> sessionMap = ec.getSessionMap();
String uid = UUID.randomUUID().toString();
LaunchData data = new LaunchData((UIViewRoot)reqMap.get(RequestContextImpl.LAUNCH_VIEW), (Map<String, String[]>) reqMap.get(RequestContextImpl.LAUNCH_PARAMETERS));
sessionMap.put(_getKey(uid), data);
//Construct URL
//TODO: sobryan I believe some of this can be added to the RequestContextUtils to allow
// this url to be constructed for both portlet and servlet environments. We'll want to research.
HttpServletRequest req = (HttpServletRequest) ec.getRequest();
StringBuffer url = req.getRequestURL().append("?");
String queryStr = req.getQueryString();
if((queryStr != null) && (queryStr.trim().length() >0))
{
url.append(queryStr)
.append("&");
}
url.append(_LAUNCH_KEY)
.append("=")
.append(uid);
//Extensions to Trinidad may have alternatve means of handling PPR. This
//flag allows those extensions to for the <redirect> AJAX message to be returned.
if (RequestContext.getCurrentInstance().isPartialRequest(_PSEUDO_FACES_CONTEXT.get()) ||
Boolean.TRUE.equals(RequestStateMap.getInstance(ec).get(_FORCE_PPR_DIALOG_RETURN)))
{
//Special handling for XmlHttpRequest. Would be cool to handle this much cleaner.
HttpServletResponse resp = (HttpServletResponse) ec.getResponse();
XmlHttpConfigurator.sendXmlRedirect(resp.getWriter(), url.toString());
}
else
{
ec.redirect(url.toString());
}
}
}
示例8: UploadActionInvocationHandler
import javax.faces.context.ExternalContext; //導入方法依賴的package包/類
public UploadActionInvocationHandler(ExternalContext ec, Map<String, String[]> params)
{
_request = ec.getRequest();
_response = ec.getResponse();
_manager = new UploadRequestManager(ec, params);
}
示例9: UploadResourceRequest
import javax.faces.context.ExternalContext; //導入方法依賴的package包/類
public UploadResourceRequest(ExternalContext ec, Map<String, String[]> params)
{
super((ResourceRequest) ec.getRequest());
_response = (ActionResponse) ec.getResponse();
_manager = new UploadRequestManager(ec, params);
}
示例10: DispatchResourceResponse
import javax.faces.context.ExternalContext; //導入方法依賴的package包/類
public DispatchResourceResponse(ExternalContext ec)
{
super((ResourceResponse)ec.getResponse());
_request = (ResourceRequest)ec.getRequest();
}
示例11: DispatchServletResponse
import javax.faces.context.ExternalContext; //導入方法依賴的package包/類
public DispatchServletResponse(ExternalContext ec)
{
super((HttpServletResponse)ec.getResponse());
_request = (HttpServletRequest)ec.getRequest();
}
示例12: DispatchRenderResponse
import javax.faces.context.ExternalContext; //導入方法依賴的package包/類
public DispatchRenderResponse(ExternalContext ec)
{
super((RenderResponse)ec.getResponse());
_request = (RenderRequest)ec.getRequest();
}