Java Code Examples for javax.faces.context.FacesContext.setResponseWriter()

The following are Jave code examples for showing how to use setResponseWriter() of the javax.faces.context.FacesContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: myfaces-trinidad   File: SkinPregenerationService.java   Source Code and License Vote up 6 votes
private static ResponseWriter _getResponseWriter(FacesContext context)
  throws IOException
{
  ExternalContext external  = context.getExternalContext();
  String contentType = "text/html";
  String encoding = "UTF-8";

  external.setResponseContentType(contentType);
  external.setResponseCharacterEncoding(encoding);
  
  ResponseWriter rw = context.getRenderKit().createResponseWriter(
    external.getResponseOutputWriter(),
    contentType,
    encoding);
  
  context.setResponseWriter(rw);
  
  return rw;
}
 
Example 2
Project: myfaces-trinidad   File: PartialViewContextImpl.java   Source Code and License Vote up 5 votes
private void _renderAll(FacesContext context, UIComponent viewRoot)
{
  ResponseWriter origResponseWriter = context.getResponseWriter();

  // Use JSF-supplied PartialResponseWriter, since we are rendering the full page
  PartialResponseWriter rw = new PartialResponseWriter(origResponseWriter);

  context.setResponseWriter(rw);

  try
  {
    rw.startDocument();

    rw.startUpdate(PartialResponseWriter.RENDER_ALL_MARKER);
    _renderChildren(context, viewRoot);
    rw.endUpdate();

    //write out JSF state
    rw.startUpdate(StateUtils.getViewStateId(FacesContext.getCurrentInstance()));
    String state = context.getApplication().getStateManager().getViewState(context);
    rw.write(state);
    rw.endUpdate();

    rw.endDocument();
  }
  catch(IOException e)
  {
    throw new FacesException(e);
  }
  finally
  {
    context.setResponseWriter(origResponseWriter);
  }
}
 
Example 3
Project: myfaces-trinidad   File: RepeatIdResponseWriter.java   Source Code and License Vote up 5 votes
static public ResponseWriter install(FacesContext context)
{
  ResponseWriter oldRW = context.getResponseWriter();
  
  ResponseWriter newRW = new RepeatIdResponseWriter(oldRW);
  context.setResponseWriter(newRW);
  
  return oldRW;
}
 
Example 4
Project: myfaces-trinidad   File: GatherContent.java   Source Code and License Vote up 5 votes
@Override
public void encodeBegin(FacesContext context)
{
  _savedWriter = context.getResponseWriter();
  
  ResponseWriter wrappedWriter = _savedWriter.cloneWithWriter(_writer);
  
  if (!_lenient)
    wrappedWriter = new CheckUIComponent(wrappedWriter);
      
  context.setResponseWriter(wrappedWriter);
}
 
Example 5
Project: myfaces-trinidad   File: GatherContent.java   Source Code and License Vote up 5 votes
@Override
public void encodeEnd(FacesContext context)
{
  // check that we have balanced elements in the CheckUIComponent
  if (!_lenient)
  {
    ResponseWriter wrappedWriter = context.getResponseWriter();
    
    if (wrappedWriter instanceof CheckUIComponent)
    {
      int finishingDepth = ((CheckUIComponent)wrappedWriter).getDepth();
      
      if (finishingDepth != 0)
      {
        AssertionFailedError failure = new AssertionFailedError("Elements not completely popped during rendering");
        
        _result.addError(_test, failure);          
      }
    }
  }
  
  context.setResponseWriter(_savedWriter);
  _savedWriter = null;
  
  RenderingContext arc = RenderingContext.getCurrentInstance();

  // Our hidden label utility code makes sure it never writes out
  // the same label twice consecutively - but between batches of
  // gathered content, that's a bad thing
  HiddenLabelUtils.rememberLabel(arc, "forgetTheLabel");
}
 
Example 6
Project: myfaces-trinidad   File: GenericEntry.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
static private void service(FacesContext context, String name)
  throws IOException
{
  if (_processReturnDialog(context,name))
  {
    return;
  }

  HttpServletResponse response =
    (HttpServletResponse) context.getExternalContext().getResponse();

  if (!_isValidEntry(name))
  {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST);
    return;
  }

  // Only use "text/html" for now, even if the browser thinks
  // it supports "text/html".
  String contentType = "text/html";
  String encoding = JspUtils.getEncoding(context, "UTF-8");

  if (encoding == null)
    response.setContentType(contentType);
  else
    response.setContentType(contentType +
                            "; charset=" + encoding);

  // =-=AEW Getting the Writer straight off of the ServletResponse
  // means losing buffered and unsynchronized goodness
  ResponseWriter responseWriter = context.getRenderKit().createResponseWriter(
    response.getWriter(),
    contentType,
    encoding);
  context.setResponseWriter(responseWriter);

  Map<String, String> requestParams = 
    context.getExternalContext().getRequestParameterMap();
  
  String localeName = requestParams.get("loc");
  if (localeName != null)
  {
    Locale locale =
      LocaleUtils.getLocaleForIANAString(localeName);
    // Push the locale into JSF land
    context.getViewRoot().setLocale(locale);
  }

  _service(context, name);
}
 
Example 7
Project: myfaces-trinidad   File: RepeatIdResponseWriter.java   Source Code and License Vote up 4 votes
static public void remove(FacesContext context, ResponseWriter oldRW)
{
  context.setResponseWriter(oldRW);
}