Hello Jochen,

since you are able to read German, here is a presentation I gave on
Struts AND Faces ([1]).
The Struts-Faces-Integration-Lib is not really the way to go. I think
it is nice to *learn* JSF, when having a struts app in hand, but not
really a production ready tool. Keep them separate. Use JSF for new
stuff. Stay with struts for the "old" stuff.

When you are in a situation where you have to refactor some struts
code (not just changing the title of a page), move that and all the
related stuff to JSF. For instance, when you do a refactoring on a
search result. Move that and the search to JSF.

You can link from Struts zu Faces by using:

<forward name="success" path="/jsfAlleUser.faces" />

Vice versa is also possible.
When mixing the content of a page, I think it would be more straight
forward to have the view containing only one framework. Struts or JSF.
Running with both is fine, but don't mix the pages (my opinion).

There was a JavaOne talk from David Geary. When it came to the
question of "mixing" Struts and JSF he answered, that he never would
like to ride two elephants at the same time :)

If your struts actions need access to your jsf backing beans (for what
ever reason), you can perhaps use this RequestProcessor (code
attached).

When doing the templating, go w/ Facelets instead of Tiles.

[1] http://www.slideshare.net/mwessendorf/

/*
* Copyright 2006, 2007 Matthias Wessendorf
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.wessendorf.struts;

import java.io.IOException;

import javax.faces.FactoryFinder;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextFactory;
import javax.faces.lifecycle.Lifecycle;
import javax.faces.lifecycle.LifecycleFactory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionServlet;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.tiles.TilesRequestProcessor;

public class LegacyTilesRequestProcessor extends TilesRequestProcessor
{

 public static final String LIFECYCLE_ID_ATTR = "javax.faces.LIFECYCLE_ID";
 private FacesContextFactory facesContextFactory;
 private Lifecycle lifecycle;



 @Override
 public void init(ActionServlet arg0, ModuleConfig arg1) throws
ServletException
 {
   super.init(arg0, arg1);
   facesContextFactory =
(FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);

   LifecycleFactory lifecycleFactory =
(LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
   lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
 }

 @Override
 public void destroy()
 {
   facesContextFactory = null;
   lifecycle = null;
   super.destroy();
 }

 @Override
 public void process(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException
 {

   FacesContext facesContext
   = facesContextFactory.getFacesContext(this.servlet.getServletContext(),
                                          request,
                                          response,
                                          lifecycle);

   try
   {
     super.process(request, response);
   }
   catch(Exception e)
   {
     if (e instanceof IOException)
     {
         throw (IOException)e;
     }
     else if (e instanceof ServletException)
     {
         throw (ServletException)e;
     }
     else if (e.getMessage() != null)
     {
         throw new ServletException(e.getMessage(), e);
     }
     else
     {
         throw new ServletException(e);
     }
   }
   finally
   {
     facesContext.release();
   }

 }

 private String getLifecycleId()
 {
     String lifecycleId =
this.servlet.getServletContext().getInitParameter(LIFECYCLE_ID_ATTR);
     return lifecycleId != null ? lifecycleId :
LifecycleFactory.DEFAULT_LIFECYCLE;
 }
}

Reply via email to