Home » tapestry-src-5.0.19 » org.apache.tapestry5.corelib.mixins » [javadoc | source]

    1   // Copyright 2008 The Apache Software Foundation
    2   //
    3   // Licensed under the Apache License, Version 2.0 (the "License");
    4   // you may not use this file except in compliance with the License.
    5   // You may obtain a copy of the License at
    6   //
    7   //     http://www.apache.org/licenses/LICENSE-2.0
    8   //
    9   // Unless required by applicable law or agreed to in writing, software
   10   // distributed under the License is distributed on an "AS IS" BASIS,
   11   // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12   // See the License for the specific language governing permissions and
   13   // limitations under the License.
   14   
   15   package org.apache.tapestry5.corelib.mixins;
   16   
   17   import org.apache.tapestry5.BindingConstants;
   18   import org.apache.tapestry5.ClientElement;
   19   import org.apache.tapestry5.Field;
   20   import org.apache.tapestry5.RenderSupport;
   21   import org.apache.tapestry5.annotations.Environmental;
   22   import org.apache.tapestry5.annotations.InjectContainer;
   23   import org.apache.tapestry5.annotations.Parameter;
   24   import org.apache.tapestry5.json.JSONArray;
   25   import org.apache.tapestry5.services.Heartbeat;
   26   
   27   /**
   28    * A mixin that can be applied to a {@link org.apache.tapestry5.corelib.components.Checkbox} or {@link
   29    * org.apache.tapestry5.corelib.components.Radio} component that will link the input field and a {@link
   30    * org.apache.tapestry5.corelib.components.FormFragment}, making the field control the client-side visibility of the
   31    * FormFragment.
   32    */
   33   public class TriggerFragment
   34   {
   35       @InjectContainer
   36       private Field container;
   37   
   38       /**
   39        * The {@link org.apache.tapestry5.corelib.components.FormFragment} instance to make dynamically visible or hidden.
   40        */
   41       @Parameter(required = true, defaultPrefix = BindingConstants.COMPONENT, allowNull = false)
   42       private ClientElement fragment;
   43   
   44       @Environmental
   45       private RenderSupport renderSupport;
   46   
   47       @Environmental
   48       private Heartbeat heartbeat;
   49   
   50       void beginRender()
   51       {
   52           Runnable r = new Runnable()
   53           {
   54               public void run()
   55               {
   56                   JSONArray spec = new JSONArray();
   57                   spec.put(container.getClientId());
   58                   spec.put(fragment.getClientId());
   59   
   60                   renderSupport.addInit("linkTriggerToFormFragment", spec);
   61               }
   62           };
   63   
   64           // Defer generating the script to ensure that the FormFragment has rendered
   65           // and generated its client id.
   66   
   67           heartbeat.defer(r);
   68       }
   69   }

Home » tapestry-src-5.0.19 » org.apache.tapestry5.corelib.mixins » [javadoc | source]