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.effect;
20  
21  import javax.faces.FacesException;
22  import javax.faces.application.ResourceDependencies;
23  import javax.faces.application.ResourceDependency;
24  import javax.faces.component.UIComponent;
25  import javax.faces.component.behavior.ClientBehavior;
26  import javax.faces.component.behavior.ClientBehaviorContext;
27  import javax.faces.render.ClientBehaviorRenderer;
28  
29  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFClientBehaviorRenderer;
30  
31  @JSFClientBehaviorRenderer(
32          renderKitId = "HTML_BASIC",
33          type = "org.apache.myfaces.custom.effect.EffectHideBehavior")
34  @ResourceDependency(library="oam.custom.prototype", name="prototype.js")
35  public class EffectHideClientBehaviorRenderer extends ClientBehaviorRenderer
36  {
37  
38      @Override
39      public String getScript(ClientBehaviorContext behaviorContext,
40              ClientBehavior behavior)
41      {
42          AbstractEffectHideClientBehavior effectBehavior = (AbstractEffectHideClientBehavior) behavior;
43          
44          UIComponent target = ( effectBehavior.getForId() != null ) ? 
45                  behaviorContext.getComponent().findComponent(effectBehavior.getForId()) : 
46                      behaviorContext.getComponent();
47          if (target == null)
48          {
49              throw new FacesException("Cannot find component set with forId: "+effectBehavior.getForId());
50          }
51          String clientId = target.getClientId();
52          
53          StringBuilder sb = new StringBuilder();
54          
55          sb.append("Element.hide('");
56          sb.append(clientId);
57          sb.append("')");
58          
59          if (effectBehavior.getAppendJs() != null && effectBehavior.getAppendJs().length() > 0)
60          {
61              sb.append(';');
62              sb.append(effectBehavior.getAppendJs());
63          }
64  
65          return sb.toString();
66      }
67  }