KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > faces > internal > PageFlowActionListener


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow.faces.internal;
19
20 import org.apache.beehive.netui.pageflow.internal.InternalUtils;
21 import org.apache.struts.action.ActionForm;
22
23 import javax.faces.event.ActionListener;
24 import javax.faces.event.ActionEvent;
25 import javax.faces.event.AbortProcessingException;
26 import javax.faces.context.FacesContext;
27 import javax.faces.el.ValueBinding;
28 import javax.servlet.ServletRequest JavaDoc;
29
30 /**
31  * Internal class used in JSF/Page Flow integration. This exists to pass form beans from JSF pages to Page Flow
32  * actions, and to abort event processing if {@link PageFlowNavigationHandler} forwarded to an action.
33  *
34  * @see org.apache.beehive.netui.pageflow.faces.PageFlowApplicationFactory
35  */

36 public class PageFlowActionListener
37         implements ActionListener
38 {
39     private ActionListener _delegate;
40     
41     public PageFlowActionListener( ActionListener delegate )
42     {
43         _delegate = delegate;
44     }
45     
46     public void processAction( ActionEvent event ) throws AbortProcessingException
47     {
48         Object JavaDoc submitFormBean = event.getComponent().getAttributes().get( "submitFormBean" );
49         FacesContext context = FacesContext.getCurrentInstance();
50         
51         if ( submitFormBean != null )
52         {
53             ValueBinding binding = context.getApplication().createValueBinding( "#{" + submitFormBean + '}' );
54             Object JavaDoc beanInstance = binding.getValue( context );
55             Object JavaDoc request = context.getExternalContext().getRequest();
56             assert request instanceof ServletRequest JavaDoc : request.getClass().getName();
57             ActionForm wrappedFormBean = InternalUtils.wrapFormBean( beanInstance );
58             InternalUtils.setForwardedFormBean( ( ServletRequest JavaDoc ) request, wrappedFormBean );
59         }
60         
61         _delegate.processAction( event );
62         
63         Object JavaDoc request = context.getExternalContext().getRequest();
64         assert request instanceof ServletRequest JavaDoc : request.getClass().getName();
65         ServletRequest JavaDoc servletRequest = ( ServletRequest JavaDoc ) request;
66         
67         String JavaDoc actionURI = ( String JavaDoc ) servletRequest.getAttribute( PageFlowNavigationHandler.ALREADY_FORWARDED_ATTR );
68         
69         if ( actionURI != null )
70         {
71             throw new AbortProcessingException( "PageFlowNavigationHandler forwarded to: " + actionURI );
72         }
73     }
74 }
75
Popular Tags