facesContext.setResponseWriter(jsfStateWriter);
final StateManager stateManager
= facesContext.getApplication().getStateManager();
StateManager.SerializedView serializedView = stateManager.saveSerializedView(facesContext);
stateManager.writeState(facesContext, serializedView);
contentWriter.startElement(HtmlConstants.SCRIPT, null);
contentWriter.writeAttribute(HtmlAttributes.TYPE, "text/javascript", null);
contentWriter.write("Tobago.replaceJsfState(\"");
contentWriter.write(StringUtils.replace(StringUtils.replace(jsfState.toString(), "\"", "\\\""), "\n", ""));