Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 34

Thread: JSF and WebFlow

  1. #11
    Join Date
    Sep 2004
    Posts
    346

    Default In terms of experts...

    I suggest:

    http://opensource.atlassian.com/conf...splay/JSF/Home

    I think first of all there are ideas here specifically regarding bean implementing actionlistener.

    Based on that article do you guys have any ideas on integration?

    I think the most simple place to integrate would be in classes like JstlView

    i.e:
    JSFView, JSFJstlView, JSFTilesView and JSFJstlTilesView.

    that then you could apply as the view resolver view class.


    The challenge here I think is keeping the faces component tree in sync as you go through the flow and somehow hooking into web flow xml to resolve JSF actions rather than JSF built in navigation.

    Basically as I understand it when going to a page the component tree would be created by FacesServlet in web.xml. I think that should be instead created by the view and stored in the session somehow delegating to the JSF classes that do it.

    But I am no expert.... I think contacting the people on that page should get the integration off the ground.


    Any ideas based on the article?

  2. #12
    Join Date
    Sep 2004
    Posts
    346

    Default Of course it would be great if this works with portlets too.

    Of course it would be great if this works with portlets too. :-)

  3. #13
    Join Date
    Sep 2004
    Posts
    346

    Default FacesContext

    Another very useful snippet of information. It appears to simulate FacesContext setup:

    http://www.thoughtsabout.net/blog/archives/000033.html

  4. #14
    Join Date
    Sep 2004
    Posts
    346

  5. #15
    Join Date
    Sep 2004
    Posts
    346

    Default JSF Portlet integration problems....

    I am running into a problem implementing JsfPortletView

    Line here is failing with class cast.

    Code:
    facesContext = contextFactory.getFacesContext(portletContext, request, response, lifecycle);
    I think this is occurring because
    contextFactory is a portlet context factory because of jsf-portlet integration library.

    request and response are not portlet compatible and hence class cast.

    So either we've got to figure out a way to continue to use servlet context factory here or somehow convert servlet request and response into portlet request and response.

    That's my 2cents... Any ideas?


    Here is the code so far..

    Code:
    /*
    
    * Created on Apr 22, 2005
    
    *
    
    * TODO To change the template for this generated file go to
    
    * Window - Preferences - Java - Code Style - Code Templates
    
    */
    
    package org.springframework.web.servlet.view;
    
    import java.util.Map;
    
    import javax.faces.FactoryFinder;
    
    import javax.faces.component.UIViewRoot;
    
    import javax.faces.context.FacesContext;
    
    import javax.faces.context.FacesContextFactory;
    
    import javax.faces.lifecycle.Lifecycle;
    
    import javax.faces.lifecycle.LifecycleFactory;
    
    import javax.portlet.PortletContext;
    
    import javax.servlet.RequestDispatcher;
    
    import javax.servlet.ServletException;
    
    import javax.servlet.http.HttpServletRequest;
    
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.web.portlet.context.PortletApplicationContext;
    
     
    
     
    
    /**
    
    * @author jztb88
    
    *
    
    * TODO To change the template for this generated type comment go to
    
    * Window - Preferences - Java - Code Style - Code Templates
    
    */
    
    public class JsfPortletView extends InternalResourceView {
    
    /**
    
    * Render the internal resource given the specified model.
    
    * This includes setting the model as request attributes.
    
    */
    
    protected void renderMergedOutputModel(
    
    Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    
    // Expose the model object as request attributes.
    
    exposeModelAsRequestAttributes(model, request);
    
    // Expose helpers as request attributes, if any.
    
    exposeHelpers(request);
    
    FacesContext facesContext = getFacesContext(request, response);
    
    // you could just render the page here but since we are still in filter, it might be
    
    // a better idea to forward to the actual page
    
    // facesContext.getApplication().getViewHandler().renderView(facesContext, facesContext.getViewRoot() );
    
    // Forward to the resource (typically a JSP).
    
    // Note: The JSP is supposed to determine the content type itself.
    
    RequestDispatcher rd = request.getRequestDispatcher(facesContext.getViewRoot().getViewId() );
    
    if (rd == null) {
    
    throw new ServletException(
    
    "Could not get RequestDispatcher for [" + getUrl() + "]: check that this file exists within your WAR");
    
    }
    
    // If already included or response already committed, perform include, else forward.
    
    if (useInclude(request, response)) {
    
    rd.include(request, response);
    
    if (logger.isDebugEnabled()) {
    
    logger.debug("Included resource [" + getUrl() + "] in InternalResourceView '" + getBeanName() + "'");
    
    }
    
    }
    
    else {
    
    rd.forward(request, response);
    
    if (logger.isDebugEnabled()) {
    
    logger.debug("Forwarded to resource [" + getUrl() + "] in InternalResourceView '" + getBeanName() + "'");
    
    }
    
    }
    
    }
    
    // You need an inner class to be able to call FacesContext.setCurrentInstance
    
    // since it's a protected method
    
    private abstract static class InnerFacesContext extends FacesContext 
    
    {
    
    protected static void setFacesContextAsCurrentInstance(FacesContext facesContext) {
    
    FacesContext.setCurrentInstance(facesContext);
    
    }
    
    }
    
    private FacesContext getFacesContext(HttpServletRequest request, HttpServletResponse response) throws Exception {
    
    // Try to get it first 
    
    FacesContext facesContext = FacesContext.getCurrentInstance();
    
    if (facesContext != null) return facesContext;
    
    FacesContextFactory contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    
    LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); 
    
    Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    
    PortletContext portletContext = ((PortletApplicationContext) getApplicationContext()).getPortletContext();
    
    // Doesn't set this instance as the current instance of FacesContext.getCurrentInstance 
    
    facesContext = contextFactory.getFacesContext(portletContext, request, response, lifecycle);
    
    // Set using our inner class
    
    InnerFacesContext.setFacesContextAsCurrentInstance(facesContext);
    
    
    // Determine the path for the request dispatcher.
    
    String dispatcherPath = prepareForRendering(request, response);
    
    // set a new viewRoot, otherwise context.getViewRoot returns null
    
    UIViewRoot view = facesContext.getApplication().getViewHandler().createView(facesContext, dispatcherPath);
    
    facesContext.setViewRoot(view);
    
    return facesContext;
    
    }
    
    
    }

  6. #16
    Join Date
    Sep 2004
    Posts
    346

    Default Seems it works without integration library

    I removed jsf integration library and went with Servlet context all the way and it works.... At least I was able to do.

    Code:
    <%@ taglib uri="http&#58;//java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http&#58;//java.sun.com/jsf/core" prefix="f" %>            
    <f&#58;loadBundle basename="ApplicationResources" var="Message"/>
    
    <f&#58;view>
    <h&#58;outputText value="#&#123;Message&#91;'contactus.title'&#93;&#125;"/>
    </f&#58;view>
    I'll have to test more and I am looking for input as to if facescontext and servletcontext are behaving properly. I would think that it should be saving facescontext in portletcontext not servletcontext????

    Code:
    /*
     * Created on Apr 22, 2005
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    package org.springframework.web.servlet.view;
    
    import java.util.Map;
    
    import javax.faces.FactoryFinder;
    import javax.faces.component.UIViewRoot;
    import javax.faces.context.FacesContext;
    import javax.faces.context.FacesContextFactory;
    import javax.faces.lifecycle.Lifecycle;
    import javax.faces.lifecycle.LifecycleFactory;
    
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    
    
    /**
     * @author jztb88
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    public class JsfPortletView extends InternalResourceView &#123;
    
    	/**
    	 * Render the internal resource given the specified model.
    	 * This includes setting the model as request attributes.
    	 */
    	protected void renderMergedOutputModel&#40;
    			Map model, HttpServletRequest request, HttpServletResponse response&#41; throws Exception &#123;
    
    		// Expose the model object as request attributes.
    		exposeModelAsRequestAttributes&#40;model, request&#41;;
    
    		// Expose helpers as request attributes, if any.
    		exposeHelpers&#40;request&#41;;
    
    		FacesContext facesContext = getFacesContext&#40;request, response&#41;;
    
    		// you could just render the page here but since we are still in filter, it might be
    		// a better idea to forward to the actual page
    		// facesContext.getApplication&#40;&#41;.getViewHandler&#40;&#41;.renderView&#40;facesContext, facesContext.getViewRoot&#40;&#41; &#41;;
    
    		// Forward to the resource &#40;typically a JSP&#41;.
    		// Note&#58; The JSP is supposed to determine the content type itself.
    		RequestDispatcher rd = request.getRequestDispatcher&#40;facesContext.getViewRoot&#40;&#41;.getViewId&#40;&#41; &#41;;
    
    		if &#40;rd == null&#41; &#123;
    			throw new ServletException&#40;
    					"Could not get RequestDispatcher for &#91;" + getUrl&#40;&#41; + "&#93;&#58; check that this file exists within your WAR"&#41;;
    		&#125;
    
    		// If already included or response already committed, perform include, else forward.
    		if &#40;useInclude&#40;request, response&#41;&#41; &#123;
    			rd.include&#40;request, response&#41;;
    			if &#40;logger.isDebugEnabled&#40;&#41;&#41; &#123;
    				logger.debug&#40;"Included resource &#91;" + getUrl&#40;&#41; + "&#93; in InternalResourceView '" + getBeanName&#40;&#41; + "'"&#41;;
    			&#125;
    		&#125;
    		else &#123;
    			rd.forward&#40;request, response&#41;;
    			if &#40;logger.isDebugEnabled&#40;&#41;&#41; &#123;
    				logger.debug&#40;"Forwarded to resource &#91;" + getUrl&#40;&#41; + "&#93; in InternalResourceView '" + getBeanName&#40;&#41; + "'"&#41;;
    			&#125;
    		&#125;
    	&#125;
        //	 You need an inner class to be able to call FacesContext.setCurrentInstance
        //	 since it's a protected method
    	private abstract static class InnerFacesContext extends FacesContext 
    	&#123;
    	  protected static void setFacesContextAsCurrentInstance&#40;FacesContext facesContext&#41; &#123;
    	    FacesContext.setCurrentInstance&#40;facesContext&#41;;
    	  &#125;
    	&#125;
    
    	private FacesContext getFacesContext&#40;HttpServletRequest request, HttpServletResponse response&#41; throws Exception &#123;
    		  // Try to get it first 
    		  FacesContext facesContext = FacesContext.getCurrentInstance&#40;&#41;;
    		  if &#40;facesContext != null&#41; return facesContext;
    
    		  FacesContextFactory contextFactory = &#40;FacesContextFactory&#41;FactoryFinder.getFactory&#40;FactoryFinder.FACES_CONTEXT_FACTORY&#41;;
    		  LifecycleFactory lifecycleFactory = &#40;LifecycleFactory&#41;FactoryFinder.getFactory&#40;FactoryFinder.LIFECYCLE_FACTORY&#41;; 
    		  Lifecycle lifecycle = lifecycleFactory.getLifecycle&#40;LifecycleFactory.DEFAULT_LIFECYCLE&#41;;
    
    		  //PortletContext portletContext = &#40;&#40;PortletApplicationContext&#41; getApplicationContext&#40;&#41;&#41;.getPortletContext&#40;&#41;;
    		  // Doesn't set this instance as the current instance of FacesContext.getCurrentInstance 
    		  facesContext = contextFactory.getFacesContext&#40;request.getSession&#40;&#41;.getServletContext&#40;&#41;, request, response, lifecycle&#41;;
    
    		  // Set using our inner class
    		  InnerFacesContext.setFacesContextAsCurrentInstance&#40;facesContext&#41;;
    		  
    		  // Determine the path for the request dispatcher.
    	      String dispatcherPath = prepareForRendering&#40;request, response&#41;;
    
    		  // set a new viewRoot, otherwise context.getViewRoot returns null
    		  UIViewRoot view = facesContext.getApplication&#40;&#41;.getViewHandler&#40;&#41;.createView&#40;facesContext, dispatcherPath&#41;;
    		  facesContext.setViewRoot&#40;view&#41;;
    
    		  return facesContext;
    		&#125;
    
    	
    
    &#125;

  7. #17
    Join Date
    Sep 2004
    Posts
    346

    Default Of course now I don't need a portlet specific jsf view...

    Of course now I don't need a portlet specific jsf view...

  8. #18
    Join Date
    Sep 2004
    Posts
    346

    Default Ok I tried a more more complex example... Here is result

    I tried hello world application from here:

    http://www.exadel.com/tutorial/jsf/j...kickstart.html

    It displayed correctly but looking at soure it seems it set the form action to be the jsp page rather than <portlet:actionURL/>

    looking for input here. I don't know if integration library would have handled this or if there is a way to do this in the bridge... Let me know.

  9. #19
    Join Date
    Sep 2004
    Location
    Valencia, ES
    Posts
    92

    Default

    Hi,

    Apache MyFaces (http://myfaces.apache.org/) is a Open Source Implementation of the JavaServer Faces Framework. It has support for Portlet JSR-168.

    I believe that an interesting way to support JSF could be to integrate MyFaces in Spring MVC.
    Enrique Ruiz
    DiSiD - http://www.disid.com

  10. #20
    Join Date
    Sep 2004
    Posts
    346

    Default As you said MyFaces is just an implementation

    As you said MyFaces is just an implementation. I don't see why it would be any easier than integrating Sun's JSF. The last thing I was trying to understand is about flowId. It seems that a component tree is saved in context for each view in JSF application. In the standard way this view is associated with the name of a jsp. I think with webflow it would be instead some combination of flowId and viewId. That way if you ever navigate to the same flow-view combination JSF can locate the view component tree. Does that sound right? I wish a JSF expert would join this thread...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •