[jboss-user] [JBoss Seam] - Re: Seam + Portlets + JSF + Facelets problem: Exception in P

jarkko@jab.fi do-not-reply at jboss.com
Fri Sep 22 10:04:16 EDT 2006


Combining SeamFaceletViewHandler and com.sun.facelets.FaceletPortletViewHandler allowed me to take a next step forward in making JSF+myfaces+portlets+seam together:

/*
  |  * JBoss, Home of Professional Open Source
  |  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  |  * by the @authors tag. See the copyright.txt in the distribution for a
  |  * full listing of individual contributors.
  |  *
  |  * This is free software; you can redistribute it and/or modify it
  |  * under the terms of the GNU Lesser General Public License as
  |  * published by the Free Software Foundation; either version 2.1 of
  |  * the License, or (at your option) any later version.
  |  *
  |  * This software is distributed in the hope that it will be useful,
  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  |  * Lesser General Public License for more details.
  |  *
  |  * You should have received a copy of the GNU Lesser General Public
  |  * License along with this software; if not, write to the Free
  |  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  |  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  |  */
  | 
  | package org.jboss.seam.ui.facelet;
  | 
  | import java.io.IOException;
  | import java.io.Writer;
  | 
  | import javax.faces.FacesException;
  | import javax.faces.application.ViewHandler;
  | import javax.faces.context.ExternalContext;
  | import javax.faces.context.FacesContext;
  | import javax.faces.context.ResponseWriter;
  | import javax.faces.render.RenderKit;
  | import javax.portlet.RenderRequest;
  | import javax.portlet.RenderResponse;
  | 
  | /**
  |  * This class just extends the SeamFaceletViewHandler to support Portlet usage of Facelets.
  |  * 
  |  * 
  |  * Merge of SeamFaceletViewHandler and com.sun.facelets.FaceletPortletViewHandler
  |  * 
  |  * @author Jarkko Lietolahti
  |  */
  | public class SeamPortletFaceletViewHandler extends SeamFaceletViewHandler {
  | 
  | 	public SeamPortletFaceletViewHandler(ViewHandler parent) {
  | 		super(parent);
  | 	}
  | 
  | 	protected ResponseWriter createResponseWriter(FacesContext context)
  | 			throws IOException, FacesException {
  | 		
  | 		ExternalContext extContext = context.getExternalContext();
  | 		RenderKit renderKit = context.getRenderKit();
  | 
  | 		RenderRequest request = (RenderRequest) extContext.getRequest();
  | 		RenderResponse response = (RenderResponse) extContext.getResponse();
  | 
  | 		String contenttype = request.getResponseContentType();
  | 		if (contenttype == null) {
  | 			contenttype = "text/html";
  | 		}
  | 
  | 		String encoding = response.getCharacterEncoding();
  | 		if (encoding == null) {
  | 			encoding = "ISO-8859-1";
  | 		}
  | 		
  | 		ResponseWriter writer = renderKit.createResponseWriter(  
  | 				NullWriter. Instance, contenttype, encoding);
  | 
  | 		contenttype = writer.getContentType();
  | 
  | 		// apply them to the response
  | 		response.setContentType(contenttype);
  | 
  | 		// Now, clone with the real writer
  | 		writer = writer.cloneWithWriter(response.getWriter());
  | 
  | 		return writer;
  | 	}
  | 	
  | 	   protected static class NullWriter extends Writer {
  | 
  | 	        static final NullWriter Instance = new NullWriter();
  | 
  | 	        public void write(char[] buffer) {
  | 	        }
  | 
  | 	        public void write(char[] buffer, int off, int len) {
  | 	        }
  | 
  | 	        public void write(String str) {
  | 	        }
  | 
  | 	        public void write(int c) {
  | 	        }
  | 
  | 	        public void write(String str, int off, int len) {
  | 	        }
  | 
  | 	        public void close() {
  | 	        }
  | 
  | 	        public void flush() {
  | 	        }
  | 	    }
  | 
  | 
  | }

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3973568#3973568

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3973568



More information about the jboss-user mailing list