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.autoscroll;
20  
21  import javax.faces.application.ResourceDependency;
22  import javax.faces.component.behavior.ClientBehaviorBase;
23  import javax.faces.component.behavior.ClientBehaviorContext;
24  
25  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFBehavior;
26  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
27  import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
28  import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
29  import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
30  /**
31   * Adds to a command link or button a javascript that enable automatic scrolling 
32   * behavior after the event is invoked.
33   * 
34   * @since 1.1.10
35   * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
36   * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (miƩ, 03 sep 2008) $
37   */
38  @JSFBehavior(name="t:autoScroll",bodyContent="empty")
39  @ResourceDependency(library="org.apache.myfaces", name="oamSubmit.js")
40  public class AutoscrollBehavior extends ClientBehaviorBase
41  {
42  
43      public static final String BEHAVIOR_ID = "org.apache.myfaces.custom.autoscroll.AutoscrollBehavior";
44      
45      @Override
46      public String getScript(ClientBehaviorContext behaviorContext)
47      {
48          FormInfo nestedFormInfo = RendererUtils.findNestingForm(behaviorContext.getComponent(), behaviorContext.getFacesContext());
49          StringBuilder script = new StringBuilder();
50          HtmlRendererUtils.appendAutoScrollAssignment(behaviorContext.getFacesContext(), script, nestedFormInfo.getFormName());
51          return script.toString();
52      }
53      
54      /**
55       * The event that this client behavior should be attached.
56       * 
57       * @return
58       */
59      @JSFProperty
60      private String getEvent()
61      {
62          return null;
63      }
64  }