Home » tapestry-src-5.0.19 » org.apache.tapestry5.corelib.components » [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.components;
   16   
   17   import org.apache.tapestry5.ComponentAction;
   18   import org.apache.tapestry5.ComponentResources;
   19   import org.apache.tapestry5.annotations.Environmental;
   20   import org.apache.tapestry5.ioc.annotations.Inject;
   21   import org.apache.tapestry5.services.FormSupport;
   22   
   23   /**
   24    * A non visual component used to provide notifications to its container during a form submission. Records actions into
   25    * the form on {@link org.apache.tapestry5.annotations.BeginRender} and {@link org.apache.tapestry5.annotations.AfterRender}
   26    * that (during the form submission) triggers "BeginSubmit" and "AfterSubmit" events.  The container can receive these
   27    * events to perform setup before a group of components process their submission, and perform cleanup afterwards.
   28    */
   29   public class SubmitNotifier
   30   {
   31       private static final class TriggerEvent implements ComponentAction<SubmitNotifier>
   32       {
   33           private final String eventType;
   34   
   35           public TriggerEvent(String eventType)
   36           {
   37               this.eventType = eventType;
   38           }
   39   
   40           public void execute(SubmitNotifier component)
   41           {
   42               component.trigger(eventType);
   43           }
   44   
   45           @Override
   46           public String toString()
   47           {
   48               return String.format("SubmitNotifier.TriggerEvent[%s]", eventType);
   49           }
   50       }
   51   
   52   
   53       @Inject
   54       private ComponentResources resources;
   55   
   56       @Environmental
   57       private FormSupport formSupport;
   58   
   59       void beginRender()
   60       {
   61           formSupport.store(this, new TriggerEvent("BeginSubmit"));
   62       }
   63   
   64       void afterRender()
   65       {
   66           formSupport.store(this, new TriggerEvent("AfterSubmit"));
   67       }
   68   
   69       private void trigger(String eventType)
   70       {
   71           resources.triggerEvent(eventType, null, null);
   72       }
   73   }

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