OK, I think I'm getting much closer. MailComponent.encode() has the process
down, but from within a UIComponent, which renders differently. However, the
info from Monkey shows how to render from outside a UIComponent, and
org.jboss.seam.ui.facelet.FaceletsRenderer showed how to create a
ResponseWriter (the one from FacesContext is null). Here is what I have so far:
try {
| FacesContext facesContext = FacesContext.getCurrentInstance();
| ViewHandler viewHandler =
facesContext.getApplication().getViewHandler();
| UIViewRoot viewRoot = viewHandler.restoreView(facesContext,
"/myDir/myPage.xhtml");
| if(viewRoot == null) {
| log.info("restoreView returned null, calling createView");
| viewRoot = viewHandler.createView(facesContext,
"/myDir/myPage.xhtml");
| }
| StringWriter stringWriter = new StringWriter();
| ResponseWriter originalResponseWriter =
facesContext.getResponseWriter();
| if(originalResponseWriter == null) {
| log.info("responseWriter is null, creating new one");
|
facesContext.setResponseWriter(facesContext.getRenderKit().createResponseWriter(stringWriter,
null, null));
| } else {
| ResponseWriter cachingResponseWriter =
originalResponseWriter.cloneWithWriter(stringWriter);
| facesContext.setResponseWriter(cachingResponseWriter);
| }
| viewHandler.renderView(facesContext, viewRoot);
| if(originalResponseWriter != null)
| facesContext.setResponseWriter(originalResponseWriter);
| String output = stringWriter.getBuffer().toString();
| log.info("Rendered data: {0}", output);
| } catch (Throwable t) {
| log.error("Error rendering: {0}", t, t.getMessage());
| }
Here is the output I got:
restoreView returned null, calling createView
| responseWriter is null, creating new one
| Rendered data:
The call to restoreView() returns null, so I call createView(). I suspect that
this may be my problem. I'm getting nothing rendered because I am creating a
new view, not restoring my existing one. The viewId I'm using is
"/myDir/myPage.xhtml", like I would refer to it in in pages.xml. Is this
incorrect? If so, what should I use for viewId?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4127949#4127949
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4127949
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user