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
20 package org.apache.myfaces.renderkit.html.util;
21
22 /**
23 * @author Manfred Geiler (latest modification by $Author: skitching $)
24 * @version $Revision: 673833 $ $Date: 2008-07-03 16:58:05 -0500 (Thu, 03 Jul 2008) $
25 */
26
27 import javax.faces.component.UIViewRoot;
28 import javax.faces.context.FacesContext;
29 import javax.faces.event.PhaseEvent;
30 import javax.faces.event.PhaseId;
31 import javax.faces.event.PhaseListener;
32 import org.apache.myfaces.shared_tomahawk.renderkit.html.util.JavascriptUtils;
33
34 /**
35 * This Phase listener is necessary for the autoscroll feature.
36 * Its only purpose is to determine the former viewId and store it in request scope
37 * so that we can later determine if a navigation has happened during rendering.
38 */
39 public class AutoScrollPhaseListener
40 implements PhaseListener
41 {
42 private static final long serialVersionUID = -1087143949215838058L;
43
44 public PhaseId getPhaseId()
45 {
46 return PhaseId.RESTORE_VIEW;
47 }
48
49 public void beforePhase(PhaseEvent event)
50 {
51 }
52
53 public void afterPhase(PhaseEvent event)
54 {
55 if(event != null)
56 {
57 FacesContext facesContext = event.getFacesContext();
58 UIViewRoot view = facesContext.getViewRoot();
59 if(view != null)
60 {
61 String viewId = view.getViewId();
62 if (viewId != null)
63 {
64 JavascriptUtils.setOldViewId(facesContext.getExternalContext(), viewId);
65 }
66 }
67 }
68 }
69
70 }