On 1/4/06, David Bowers <[EMAIL PROTECTED]> wrote: > > I'm trying to figure out a good way to start migrating from struts to JSF > (w/o Shale at this point). > > I've been thinking that it would be very handy if I could do something > like > this: > > <action > path="/something"> > <forward name="success" path="#{someBean.someAction}"/> > </action> > > Then the expression that is forwarded to would be passed to the JSF > application and rendered from there. Obviously this would be much easier > in > Struts 1.3 as the forward could be handled by a seperate command, but for > now I'm okay with extending the RequestProcessor. For those not using > Shale, something like this could make initialization of a JSF page much > easier, as this would provide a kind of implicit "prerender" > functionality. > > Has anyone done something like this and could point me to some sample > code? > Basically, take a non-faces request, get a reference to the context and > lifecycle, and then start JSF processing at the "Invoke Application" > phase. > I have my own ideas on the code it would take to do this below, but would > welcome more detailed examples if available. > > Assuming I have my lifecycle, context, and application variables defined, > should something like this work? > MethodBinding mb = application.createMethodBinding(forward.getPath(), > null); > String view = mb.invoke(context, null); //Assume this is a global outcome > context.getNavigationHandler().handleNavigation(context, null, view); > lifecycle.render(context);
Conceptually, something like this should work for rendering ... *if* you have turned the original non-faces request into a faces request first. The steps you have to follow are described in Section 2.4.1 of the spec (it's basically what FacesServlet does to turn any request into a Faces request in the first place.) Something to think about, though, is how you'll get back to a Struts action when the page you are about to render wants to submit its form. You'll need to use a JSF form component for the input components on the page to operate correctly (I'm assuming you want to use components on this page, or you wouldn't be messing with JSF at all) ... but it's going to do a Faces request, not a submit to the Struts controller servlet to look up the appropriate Action. You might be better off looking at the Struts-Faces integration library[1], which deals with this problem by providing a form tag that is both a JSF form component, *and* knows about Struts related concepts like the form bean and which action to invoke. Craig [1] http://struts.apache.org/struts-faces/ Craig