// message displayed, so we need to return something.
//if (renderIds == null || renderIds.isEmpty()) {
// return;
//}
PartialResponseWriter writer = getPartialResponseWriter();
ResponseWriter oldWriter = _facesContext.getResponseWriter();
boolean inDocument = false;
//response type = text/xml
//no caching and no timeout if possible!
ExternalContext externalContext = _facesContext.getExternalContext();
externalContext.setResponseContentType("text/xml");
externalContext.addResponseHeader("Pragma", "no-cache");
externalContext.addResponseHeader("Cache-control", "no-cache");
//under normal circumstances pragma should be enough, IE needs
//a special treatment!
//http://support.microsoft.com/kb/234067
externalContext.addResponseHeader("Expires", "-1");
try
{
writer.startDocument();
inDocument = true;
_facesContext.setResponseWriter(writer);
//Only apply partial visit if we have ids to traverse
if (renderIds != null && !renderIds.isEmpty())
{
Set<VisitHint> hints = new HashSet<VisitHint>();
// unrendered have to be skipped, transient definitely must be added to our list!
hints.add(VisitHint.SKIP_UNRENDERED);
// render=@all, so output the body.
if (renderIds.contains ("javax.faces.ViewRoot"))
{
java.util.Iterator<UIComponent> iter = viewRoot.getFacetsAndChildren();
writer.startUpdate ("javax.faces.ViewRoot");
while (iter.hasNext())
{
UIComponent comp = iter.next();
if (comp instanceof javax.faces.component.html.HtmlBody)
{
comp.encodeAll (_facesContext);
}
}
writer.endUpdate();
}
else
{
VisitContext visitCtx = VisitContext.createVisitContext(_facesContext, renderIds, hints);
viewRoot.visitTree(visitCtx, new PhaseAwareVisitCallback(_facesContext, phaseId));
}
}
// invoke encodeAll() on every UIViewParameter in the view to
// enable every UIViewParameter to save its value in the state
// just like UIViewRoot.encodeEnd() does on a normal request
// (see MYFACES-2645 for details)
Collection<UIViewParameter> viewParams = ViewMetadata.getViewParameters(viewRoot);
if (!viewParams.isEmpty())
{
for (UIViewParameter param : viewParams)
{
param.encodeAll(_facesContext);
}
}
//Retrieve the state and apply it if it is not null.
String viewState = _facesContext.getApplication().getStateManager().getViewState(_facesContext);
if (viewState != null)
{
writer.startUpdate(PartialResponseWriter.VIEW_STATE_MARKER);
writer.write(viewState);
writer.endUpdate();
}
} catch (IOException ex) {
Logger log = Logger.getLogger(PartialViewContextImpl.class.getName());
if (log.isLoggable(Level.SEVERE)) {
log.log(Level.SEVERE, "" , ex);
}
} finally {
try {
if (inDocument) {
writer.endDocument();
}
writer.flush();
} catch (IOException ex) {
Logger log = Logger.getLogger(PartialViewContextImpl.class.getName());
if (log.isLoggable(Level.SEVERE)) {
log.log(Level.SEVERE, "" , ex);
}