Hi Pedro,
I will show you my solution, but first I must make a consideration.
The use of @PostConstruct annotation will work only in a full J2EE
Application server (e.g. JBoss or WebSphere), not in a Servlet
container (like Tomcat or Jetty).
Indeed I did not test this, but this annotation is part of EJB-Session
specification and therefore available only with a full EJB container
(Please note that EJB-Persistence annotations, instead, can be used
without any container, even in a bare Java application).

My solution is this:
- create a servlet that you can invoke by any non-JSF page
- fill it with the following code

        private abstract static class InnerFacesContext extends FacesContext {
                protected static void setFacesContextAsCurrentInstance(
                                FacesContext facesContext) {
                        FacesContext.setCurrentInstance(facesContext);
                }
        }

        protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                        throws ServletException, IOException {
                ServletContext servletContext = this.getServletContext();
                FacesContext ctx = getFacesContext(req, resp);
                Application app = ctx.getApplication();
                //get an instance of your backing-bean form
                MyForm form = (MyForm) app.createValueBinding(
                                "#{myForm}").getValue(ctx);
                //Invoke the action!!!
                form.edit();
                NavigationHandler navigationHandler = ctx.getApplication()
                                .getNavigationHandler();
                navigationHandler.handleNavigation(ctx, "#{anyaction}", "edit");
//the second parameter may be anything
                ctx.renderResponse();
                req.getRequestDispatcher("myForm.html").forward(req, resp);
        }

        private FacesContext getFacesContext(ServletRequest request,
                        ServletResponse response) {
                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);

                facesContext = 
contextFactory.getFacesContext(this.getServletContext(),
                                request, response, lifecycle);
                
InnerFacesContext.setFacesContextAsCurrentInstance(facesContext);
                UIViewRoot view = facesContext.getApplication().getViewHandler()
                                .createView(facesContext, "/myForm.html");
                facesContext.setViewRoot(view);
                return facesContext;
        }


- in faces-config.xml, remove        <redirect/> in the navigation-case

Please let me know if it works for you.
It seems to me that the servlet code is somewhat redundant, but now I
cannot do trials to simplify it.
Still this approach do not work if the page contains a <t:popup>, I
had to remove it from my page.
It has to do with the fact that using a servlet that forwards to a JSF
page removes from the page header the necessary javascript for the
popup.
If someone has a solution please tell me.

Vincenzo Caselli
gtalk: [EMAIL PROTECTED]



On Tue, Jul 8, 2008 at 5:21 AM, pedro_burglin <[EMAIL PROTECTED]> wrote:
>
> Quick update: I tried the JSFPageParser and configuration steps to make
> sitemesh decorators JSF-aware as described here
> (http://forums.opensymphony.com/thread.jspa?threadID=36939&messageID=72427#72427)
> but with no luck. I still got a blank screen with no errors when I tried to
> use JSF tags in the default.jsp even after following these steps...
>
> I am still looking for a workaround to this issue, any help greatly
> appreciated.
> Pedro Burglin
>
>
> pedro_burglin wrote:
>>
>> Hi All,
>>
>> Does anyone know how to call a JSF action from AppFuse's non-JSF
>> default.jsp?
>>
>> I implemented a shopping cart component UI in default.jsp so it would be
>> presented in most screens of the application. In this UI component I added
>> a link (and later replaced with a form and a button with similar results)
>> to the Checkout screen. Everything was working fine until I had to
>> implement logic to determine if the Checkout link in this UI component
>> would direct the user to the Checkout screen or to another screen based on
>> logic implemented in an Action class.
>>
>> The problem is that I can't find how to make the Checkout button (or link)
>> in default.jsp to use the JSF action and the navigation rules defined in
>> faces-config.xml. It always send the user to the Checkout screen without
>> calling any logic in the Checkout managed bean.
>>
>> I have another screen with a button to the Checkout screen. This screen
>> uses JSF to contact the managed bean and navigation rules and it works
>> fine. My problem is just with default.jsp.
>>
>> Digging for entries about similar issue I found this link:
>> http://www.nabble.com/Editing-default.jsp-td9267623s2369.html#a9267623
>> I believe the discussed solution does not work (yet?) and I was really
>> looking for a simpler solution, like how to use html/javascript in
>> default.jsp to use JSF's managed bean and navigation rules, if possible...
>>
>> Any help really appreciated,
>> Pedro Burglin
>>
>
> --
> View this message in context: 
> http://www.nabble.com/call-to-JSF-action-from-default.jsp-tp18325804s2369p18331105.html
> Sent from the AppFuse - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to