[jboss-user] [JBoss Seam] - Re: JBoss 4.0.5.GA: java.lang.NullPointerException: serialF

jarkko@jab.fi do-not-reply at jboss.com
Mon Oct 23 18:01:11 EDT 2006


I managed to get things going by adding the following methods to my own MyFacesGenericPortlet.java. I'm more convinced that the portlet portition of myfaces is a little bit off sync compared to "normal" MyFaces usage.

I thought i saw


  | package fi.jab.jsf;
  | 
  | import java.io.IOException;
  | 
  | import javax.faces.context.ExternalContext;
  | import javax.faces.context.FacesContext;
  | import javax.portlet.PortletException;
  | import javax.portlet.RenderRequest;
  | import javax.portlet.RenderResponse;
  | 
  | import org.apache.commons.logging.Log;
  | import org.apache.commons.logging.LogFactory;
  | import org.apache.myfaces.config.FacesConfigurator;
  | import org.apache.myfaces.context.FacesContextWrapper;
  | import org.apache.myfaces.context.ReleaseableExternalContext;
  | import org.apache.myfaces.context.portlet.PortletExternalContextImpl;
  | import org.apache.myfaces.context.servlet.ServletFacesContextImpl;
  | import org.apache.myfaces.shared_impl.util.ClassUtils;
  | import org.apache.myfaces.shared_impl.util.StateUtils;
  | import org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory;
  | import org.apache.myfaces.shared_impl.util.serial.SerialFactory;
  | import org.apache.myfaces.shared_impl.webapp.webxml.WebXml;
  | 
  | /**
  |  * java.lang.IllegalStateException: Can not call encodeNamespace() during a portlet ActionRequest
  |  * http://issues.apache.org/jira/browse/MYFACES-1359?page=all
  |  * This seems to be fixed in 1.1.4.
  |  * 
  |  * http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/MyFacesGenericPortlet.java?revision=417505&view=markup
  |  * 
  |  * @author jarkko
  |  * 
  |  */
  | 
  | public class MyFacesGenericPortlet extends
  | 		org.apache.myfaces.portlet.MyFacesGenericPortlet {
  | 
  | 	private static final Log log = LogFactory
  | 			.getLog(MyFacesGenericPortlet.class);
  | 
  | 	@Override
  | 	protected void nonFacesRequest(RenderRequest request,
  | 			RenderResponse response) throws PortletException {
  | 
  | 		super.nonFacesRequest(request, response);
  | 	}
  | 
  | 	@Override
  | 	protected void nonFacesRequest(RenderRequest request,
  | 			RenderResponse response, String view) throws PortletException {
  | 
  | 		super.nonFacesRequest(request, response, view);
  | 	}
  | 
  | 	@Override
  | 	// http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/portlet/MyFacesGenericPortlet.java?revision=417505&view=markup
  | 	protected void facesRender(RenderRequest request, RenderResponse response)
  | 			throws PortletException, IOException {
  | 
  | 		if (log.isTraceEnabled())
  | 			log.trace("called facesRender");
  | 
  | 		setContentType(request, response);
  | 
  | 		String viewId = request.getParameter(VIEW_ID);
  | 		if ((viewId == null) || sessionTimedOut(request)) {
  | 			setPortletRequestFlag(request);
  | 			nonFacesRequest(request, response);
  | 			return;
  | 		}
  | 
  | 		setPortletRequestFlag(request);
  | 
  | 		try {
  | 			ServletFacesContextImpl facesContext = (ServletFacesContextImpl) request
  | 					.getPortletSession().getAttribute(CURRENT_FACES_CONTEXT);
  | 
  | 			// depending on the Portal implementation, facesContext could be
  | 			// null after a redeploy
  | 			if (facesContext == null) {
  | 				setPortletRequestFlag(request);
  | 				nonFacesRequest(request, response);
  | 				return;
  | 			}
  | 
  | 			// TODO: not sure if this can happen. Also double check this against
  | 			// spec section 2.1.3
  | 			if (facesContext.getResponseComplete())
  | 				return;
  | 
  | 			ReleaseableExternalContext ctx = makeExternalContext(request,
  | 					response);
  | 
  | 			facesContext.setExternalContext(ctx);
  | 
  | 			lifecycle.render(facesContext);
  | 		} catch (Throwable e) {
  | 			handleExceptionFromLifecycle(e);
  | 		}
  | 
  | 	}
  | 
  | 	@Override
  | 	protected void initMyFaces() {
  | 
  | 		try {
  | 			Boolean b = (Boolean) portletContext.getAttribute(FACES_INIT_DONE);
  | 
  | 			if (b == null || b.booleanValue() == false) {
  | 				log.trace("Initializing MyFaces");
  | 
  | 				// Load the configuration
  | 				ExternalContext externalContext = new PortletExternalContextImpl(
  | 						portletContext, null, null);
  | 
  | 				// And configure everything
  | 				new FacesConfigurator(externalContext).configure();
  | 
  | 				// parse web.xml - not sure if this is needed for portlet
  | 				WebXml.init(externalContext);
  | 
  | 				// What is this supposed to do??
  | 				// if (portletContext.getInitParameter(StateUtils.INIT_SECRET) != null) {
  | 				// // Yes, but how?
  | 				// // StateUtils.initSecret( externalContext );
  | 				// }
  | 
  | 				handleSerialFactory(externalContext);
  | 
  | 				portletContext.setAttribute(FACES_INIT_DONE, Boolean.TRUE);
  | 			} else {
  | 				// FIXME do we want to show this?
  | 				log.info("MyFaces already initialized");
  | 			}
  | 		} catch (Exception ex) {
  | 			log.error("Error initializing MyFacesGenericPortlet", ex);
  | 		}
  | 		log.info("Portlet " + getPortletName() + " initialized");
  | 	}
  | 
  | 	public static void handleSerialFactory(ExternalContext externalContext) {
  | 
  | 		String serialProvider = externalContext
  | 				.getInitParameter(StateUtils.SERIAL_FACTORY);
  | 		SerialFactory serialFactory = null;
  | 
  | 		if (serialProvider == null) {
  | 			serialFactory = new DefaultSerialFactory();
  | 		} else {
  | 			try {
  | 				serialFactory = (SerialFactory) ClassUtils
  | 						.newInstance(serialProvider);
  | 
  | 			} catch (ClassCastException e) {
  | 				log.error("Make sure '" + serialProvider
  | 						+ "' implements the correct interface", e);
  | 			} catch (Exception e) {
  | 				log.error(e);
  | 			} finally {
  | 				if (serialFactory == null) {
  | 					serialFactory = new DefaultSerialFactory();
  | 					log.error("Using default serialization provider");
  | 				}
  | 			}
  | 
  | 		}
  | 
  | 		log.info("Serialization provider : " + serialFactory.getClass());
  | 		externalContext.getApplicationMap().put(StateUtils.SERIAL_FACTORY,
  | 				serialFactory);
  | 
  | 	}
  | 
  | }
  | 
  | 

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

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



More information about the jboss-user mailing list