Coverage Report - org.apache.tapestry.form.Hidden
 
Classes in this File Line Coverage Branch Coverage Complexity
Hidden
0%
0/25
0%
0/6
1.6
 
 1  
 // Copyright 2004, 2005 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.tapestry.form;
 16  
 
 17  
 import org.apache.hivemind.ApplicationRuntimeException;
 18  
 import org.apache.tapestry.IActionListener;
 19  
 import org.apache.tapestry.IForm;
 20  
 import org.apache.tapestry.IMarkupWriter;
 21  
 import org.apache.tapestry.IRequestCycle;
 22  
 import org.apache.tapestry.listener.ListenerInvoker;
 23  
 import org.apache.tapestry.services.DataSqueezer;
 24  
 
 25  
 /**
 26  
  * Implements a hidden field within a {@link Form}. [ <a
 27  
  * href="../../../../../components/form/hidden.html">Component Reference </a>]
 28  
  * 
 29  
  * @author Howard Lewis Ship
 30  
  * @author Paul Ferraro
 31  
  */
 32  0
 public abstract class Hidden extends AbstractFormComponent
 33  
 {
 34  
     /**
 35  
      * Returns false.
 36  
      */
 37  
 
 38  
     protected boolean getCanTakeFocus()
 39  
     {
 40  0
         return false;
 41  
     }
 42  
 
 43  
     /**
 44  
      * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter,
 45  
      *      org.apache.tapestry.IRequestCycle)
 46  
      */
 47  
     protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 48  
     {
 49  0
         IForm form = getForm();
 50  0
         String externalValue = null;
 51  
 
 52  0
         if (getEncode())
 53  
         {
 54  0
             Object value = getValue();
 55  
 
 56  
             try
 57  
             {
 58  0
                 externalValue = getDataSqueezer().squeeze(value);
 59  
             }
 60  0
             catch (Exception e)
 61  
             {
 62  0
                 throw new ApplicationRuntimeException(e.getMessage(), this, null, e);
 63  0
             }
 64  0
         }
 65  
         else
 66  0
             externalValue = (String) getBinding("value").getObject(String.class);
 67  
         
 68  0
         form.addHiddenValue(getName(), getClientId(), externalValue);
 69  0
     }
 70  
 
 71  
     /**
 72  
      * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IRequestCycle)
 73  
      */
 74  
     protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
 75  
     {
 76  0
         String parameter = cycle.getParameter(getName());
 77  
 
 78  0
         Object value = parameter;
 79  
 
 80  0
         if (getEncode())
 81  
         {
 82  
             try
 83  
             {
 84  0
                 value = getDataSqueezer().unsqueeze(parameter);
 85  
             }
 86  0
             catch (Exception ex)
 87  
             {
 88  0
                 throw new ApplicationRuntimeException(ex.getMessage(), this, null, ex);
 89  0
             }
 90  
         }
 91  
 
 92  
         // A listener is not always necessary ... it's easy to code
 93  
         // the synchronization as a side-effect of the accessor method.
 94  
 
 95  0
         setValue(value);
 96  
 
 97  0
         getListenerInvoker().invokeListener(getListener(), this, cycle);
 98  0
     }
 99  
 
 100  
     /** @since 2.2 * */
 101  
     public abstract DataSqueezer getDataSqueezer();
 102  
 
 103  
     public abstract Object getValue();
 104  
 
 105  
     public abstract void setValue(Object value);
 106  
 
 107  
     public abstract IActionListener getListener();
 108  
 
 109  
     /**
 110  
      * Injected.
 111  
      * 
 112  
      * @since 4.0
 113  
      */
 114  
 
 115  
     public abstract ListenerInvoker getListenerInvoker();
 116  
 
 117  
     /**
 118  
      * Returns false. Hidden components are never disabled.
 119  
      * 
 120  
      * @since 2.2
 121  
      */
 122  
     public boolean isDisabled()
 123  
     {
 124  0
         return false;
 125  
     }
 126  
 
 127  
     /**
 128  
      * Returns true if the compent encodes object values using a
 129  
      * {@link org.apache.tapestry.util.io.DataSqueezerImpl}, false if values are always Strings.
 130  
      * 
 131  
      * @since 2.2
 132  
      */
 133  
     public abstract boolean getEncode();
 134  
 }