Coverage Report - net.sf.beanform.LinkForm
 
Classes in this File Line Coverage Branch Coverage Complexity
LinkForm
50% 
N/A 
0
 
 1  
 // Copyright 2006 Daniel Gredler
 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 net.sf.beanform;
 16  
 
 17  
 import org.apache.tapestry.IForm;
 18  
 import org.apache.tapestry.IMarkupWriter;
 19  
 import org.apache.tapestry.IRender;
 20  
 import org.apache.tapestry.IRequestCycle;
 21  
 import org.apache.tapestry.engine.DirectServiceParameter;
 22  
 import org.apache.tapestry.engine.ILink;
 23  
 import org.apache.tapestry.form.Form;
 24  
 import org.apache.tapestry.form.FormSupport;
 25  
 import org.apache.tapestry.form.FormSupportImpl;
 26  
 
 27  
 /**
 28  
  * A form that expects to be contained by a {@link BeanForm} instance and whose direct
 29  
  * service link corresponds to the containing {@link BeanForm}, rather than itself.
 30  
  *
 31  
  * @author Daniel Gredler
 32  
  */
 33  2
 public abstract class LinkForm extends Form {
 34  
 
 35  
     @Override
 36  
     protected FormSupport newFormSupport( IMarkupWriter writer, IRequestCycle cycle ) {
 37  1
         return new LinkFormSupport( writer, cycle, this );
 38  
     }
 39  
 
 40  
     /**
 41  
      * Providing an instance of this class in {@link LinkForm#newFormSupport(IMarkupWriter, IRequestCycle)}
 42  
      * is the functional equivalent of overriding {@link Form#getLink(IRequestCycle)} so that it returns a
 43  
      * link to the containing {@link BeanForm}, which we can't do because it is a private method.
 44  
      */
 45  2
     public class LinkFormSupport extends FormSupportImpl {
 46  1
         public LinkFormSupport( IMarkupWriter writer, IRequestCycle cycle, IForm form ) {
 47  1
             super( writer, cycle, form );
 48  1
         }
 49  
         @Override
 50  
         public void render( String method, IRender render, ILink link, String scheme, Integer port ) {
 51  0
             IRequestCycle cycle = LinkForm.this.getPage().getRequestCycle();
 52  0
             BeanForm beanForm = (BeanForm) cycle.getAttribute( BeanForm.BEAN_FORM_ATTRIBUTE );
 53  0
             Object parameter = new DirectServiceParameter( beanForm );
 54  0
             link = LinkForm.this.getDirectService().getLink( true, parameter );
 55  0
             super.render( method, render, link, scheme, port );
 56  0
         }
 57  
     }
 58  
 
 59  
 }