KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > Hidden


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 java.io.IOException JavaDoc;
18
19 import org.apache.hivemind.ApplicationRuntimeException;
20 import org.apache.tapestry.IActionListener;
21 import org.apache.tapestry.IForm;
22 import org.apache.tapestry.IMarkupWriter;
23 import org.apache.tapestry.IRequestCycle;
24 import org.apache.tapestry.listener.ListenerInvoker;
25 import org.apache.tapestry.services.DataSqueezer;
26
27 /**
28  * Implements a hidden field within a {@link Form}. [ <a
29  * HREF="../../../../../ComponentReference/Hidden.html">Component Reference </a>]
30  *
31  * @author Howard Lewis Ship
32  * @author Paul Ferraro
33  */

34 public abstract class Hidden extends AbstractFormComponent
35 {
36     /**
37      * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle)
38      */

39     protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
40     {
41         IForm form = getForm();
42         String JavaDoc externalValue = null;
43
44         if (getEncode())
45         {
46             Object JavaDoc value = getValue();
47
48             try
49             {
50                 externalValue = getDataSqueezer().squeeze(value);
51             }
52             catch (IOException JavaDoc e)
53             {
54                 throw new ApplicationRuntimeException(e.getMessage(), this, null, e);
55             }
56         }
57         else
58             externalValue = (String JavaDoc) getBinding("value").getObject(String JavaDoc.class);
59
60         String JavaDoc id = getClientId();
61
62         form.addHiddenValue(getName(), id, externalValue);
63     }
64     
65     /**
66      * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IRequestCycle)
67      */

68     protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
69     {
70         String JavaDoc parameter = cycle.getParameter(getName());
71
72         Object JavaDoc value = parameter;
73
74         if (getEncode())
75         {
76             try
77             {
78                 value = getDataSqueezer().unsqueeze(parameter);
79             }
80             catch (IOException JavaDoc ex)
81             {
82                 throw new ApplicationRuntimeException(ex.getMessage(), this, null, ex);
83             }
84         }
85
86         // A listener is not always necessary ... it's easy to code
87
// the synchronization as a side-effect of the accessor method.
88

89         setValue(value);
90
91         getListenerInvoker().invokeListener(getListener(), this, cycle);
92     }
93
94     /** @since 2.2 * */
95     public abstract DataSqueezer getDataSqueezer();
96
97     public abstract Object JavaDoc getValue();
98
99     public abstract void setValue(Object JavaDoc value);
100
101     public abstract IActionListener getListener();
102
103     /**
104      * Injected.
105      *
106      * @since 4.0
107      */

108
109     public abstract ListenerInvoker getListenerInvoker();
110
111     /**
112      * Returns false. Hidden components are never disabled.
113      *
114      * @since 2.2
115      */

116     public boolean isDisabled()
117     {
118         return false;
119     }
120
121     /**
122      * Returns true if the compent encodes object values using a
123      * {@link org.apache.tapestry.util.io.DataSqueezerImpl}, false if values are always Strings.
124      *
125      * @since 2.2
126      */

127     public abstract boolean getEncode();
128 }
Popular Tags