View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.custom.conversation;
20  
21  import javax.faces.component.StateHolder;
22  import javax.faces.context.FacesContext;
23  import javax.faces.event.AbortProcessingException;
24  import javax.faces.event.ActionEvent;
25  import javax.faces.event.ActionListener;
26  
27  /**
28   * base class to handle actions events
29   * @author imario@apache.org 
30   */
31  public abstract class AbstractConversationActionListener implements ActionListener, StateHolder
32  {
33      private String conversationName;
34  
35      private transient boolean isTransient;
36      
37      public AbstractConversationActionListener()
38      {
39      }
40  
41      /**
42       * @return the conversation name this listener is associated to
43       */
44      public String getConversationName()
45      {
46          return conversationName;
47      }
48  
49      /**
50       * set the conversation name this listener should be associated to
51       * 
52       * @param conversationName
53       */
54      public void setConversationName(String conversationName)
55      {
56          this.conversationName = conversationName;
57      }
58  
59  
60      public Object saveState(FacesContext context)
61      {
62          return new Object[]
63          {
64              conversationName
65          };
66      }
67  
68      public void restoreState(FacesContext context, Object state)
69      {
70          Object[] states = (Object[]) state;
71          conversationName = (String) states[0];
72      }
73  
74      public boolean isTransient()
75      {
76          return isTransient;
77      }
78  
79      public void setTransient(boolean newTransientValue)
80      {
81          isTransient = newTransientValue;
82      }
83  
84      public void processAction(ActionEvent actionEvent) throws AbortProcessingException
85      {
86          AbstractConversationComponent startOrEndconversation = ConversationUtils.findStartOrEndConversationComponent(actionEvent.getComponent(), getConversationName());
87          
88          doConversationAction(startOrEndconversation);
89      }
90      
91      /**
92       * override this to do your conversation action
93       */
94      public abstract void doConversationAction(AbstractConversationComponent abstractConversationComponent);
95  }