|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Hidden.java | 87.5% | 84.6% | 50% | 83.3% |
|
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;
|
|
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 |
*/
|
|
33 |
|
|
34 |
public abstract class Hidden extends AbstractFormComponent |
|
35 |
{ |
|
36 |
|
|
37 | 8 |
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
38 |
{ |
|
39 | 8 |
IForm form = getForm(cycle); |
40 | 8 |
boolean formRewound = form.isRewinding();
|
41 |
|
|
42 | 8 |
String name = form.getElementId(this);
|
43 |
|
|
44 |
// If the form containing the Hidden isn't rewound, then render.
|
|
45 |
|
|
46 | 8 |
if (!formRewound)
|
47 |
{ |
|
48 |
// Optimiziation: if the page is rewinding (some other action or
|
|
49 |
// form was submitted), then don't bother rendering.
|
|
50 |
|
|
51 | 4 |
if (cycle.isRewinding())
|
52 | 0 |
return;
|
53 |
|
|
54 | 4 |
String externalValue = null;
|
55 |
|
|
56 | 4 |
if (getEncode())
|
57 |
{ |
|
58 | 2 |
Object value = getValue(); |
59 |
|
|
60 | 2 |
try
|
61 |
{ |
|
62 | 2 |
externalValue = getDataSqueezer().squeeze(value); |
63 |
} |
|
64 |
catch (IOException ex)
|
|
65 |
{ |
|
66 | 0 |
throw new ApplicationRuntimeException(ex.getMessage(), this, null, ex); |
67 |
} |
|
68 |
} |
|
69 |
else
|
|
70 | 2 |
externalValue = (String) getBinding("value").getObject(String.class); |
71 |
|
|
72 | 4 |
String id = getElementId(); |
73 |
|
|
74 | 4 |
form.addHiddenValue(name, id, externalValue); |
75 |
|
|
76 | 4 |
return;
|
77 |
} |
|
78 |
|
|
79 | 4 |
String externalValue = cycle.getParameter(name); |
80 | 4 |
Object value = null;
|
81 |
|
|
82 | 4 |
if (getEncode())
|
83 |
{ |
|
84 | 2 |
try
|
85 |
{ |
|
86 | 2 |
value = getDataSqueezer().unsqueeze(externalValue); |
87 |
} |
|
88 |
catch (IOException ex)
|
|
89 |
{ |
|
90 | 0 |
throw new ApplicationRuntimeException(ex.getMessage(), this, null, ex); |
91 |
} |
|
92 |
} |
|
93 |
else
|
|
94 | 2 |
value = externalValue; |
95 |
|
|
96 |
// A listener is not always necessary ... it's easy to code
|
|
97 |
// the synchronization as a side-effect of the accessor method.
|
|
98 |
|
|
99 | 4 |
setValue(value); |
100 |
|
|
101 | 4 |
getListenerInvoker().invokeListener(getListener(), this, cycle);
|
102 |
} |
|
103 |
|
|
104 |
public abstract String getElementId();
|
|
105 |
|
|
106 |
/** @since 2.2 * */
|
|
107 |
|
|
108 |
public abstract DataSqueezer getDataSqueezer();
|
|
109 |
|
|
110 |
public abstract Object getValue();
|
|
111 |
|
|
112 |
public abstract void setValue(Object value); |
|
113 |
|
|
114 |
public abstract IActionListener getListener();
|
|
115 |
|
|
116 |
/**
|
|
117 |
* Injected.
|
|
118 |
*
|
|
119 |
* @since 4.0
|
|
120 |
*/
|
|
121 |
|
|
122 |
public abstract ListenerInvoker getListenerInvoker();
|
|
123 |
|
|
124 |
/**
|
|
125 |
* Returns false. Hidden components are never disabled.
|
|
126 |
*
|
|
127 |
* @since 2.2
|
|
128 |
*/
|
|
129 |
|
|
130 | 0 |
public boolean isDisabled() |
131 |
{ |
|
132 | 0 |
return false; |
133 |
} |
|
134 |
|
|
135 |
/**
|
|
136 |
* Returns true if the compent encodes object values using a
|
|
137 |
* {@link org.apache.tapestry.util.io.DataSqueezerImpl}, false if values are always Strings.
|
|
138 |
*
|
|
139 |
* @since 2.2
|
|
140 |
*/
|
|
141 |
|
|
142 |
public abstract boolean getEncode(); |
|
143 |
} |
|