|
|||||||||||||||||||
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 | 90% | 85.7% | 50% | 85% |
|
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.services.DataSqueezer;
|
|
25 |
|
|
26 |
/**
|
|
27 |
* Implements a hidden field within a {@link Form}. [ <a
|
|
28 |
* href="../../../../../ComponentReference/Hidden.html">Component Reference </a>]
|
|
29 |
*
|
|
30 |
* @author Howard Lewis Ship
|
|
31 |
*/
|
|
32 |
|
|
33 |
public abstract class Hidden extends AbstractFormComponent |
|
34 |
{ |
|
35 |
|
|
36 | 8 |
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
37 |
{ |
|
38 | 8 |
IForm form = getForm(cycle); |
39 | 8 |
boolean formRewound = form.isRewinding();
|
40 |
|
|
41 | 8 |
String name = form.getElementId(this);
|
42 |
|
|
43 |
// If the form containing the Hidden isn't rewound, then render.
|
|
44 |
|
|
45 | 8 |
if (!formRewound)
|
46 |
{ |
|
47 |
// Optimiziation: if the page is rewinding (some other action or
|
|
48 |
// form was submitted), then don't bother rendering.
|
|
49 |
|
|
50 | 4 |
if (cycle.isRewinding())
|
51 | 0 |
return;
|
52 |
|
|
53 | 4 |
String externalValue = null;
|
54 |
|
|
55 | 4 |
if (getEncode())
|
56 |
{ |
|
57 | 2 |
Object value = getValue(); |
58 |
|
|
59 | 2 |
try
|
60 |
{ |
|
61 | 2 |
externalValue = getDataSqueezer().squeeze(value); |
62 |
} |
|
63 |
catch (IOException ex)
|
|
64 |
{ |
|
65 | 0 |
throw new ApplicationRuntimeException(ex.getMessage(), this, null, ex); |
66 |
} |
|
67 |
} |
|
68 |
else
|
|
69 | 2 |
externalValue = (String) getBinding("value").getObject(String.class); |
70 |
|
|
71 | 4 |
String id = getElementId(); |
72 |
|
|
73 | 4 |
form.addHiddenValue(name, id, externalValue); |
74 |
|
|
75 | 4 |
return;
|
76 |
} |
|
77 |
|
|
78 | 4 |
String externalValue = cycle.getParameter(name); |
79 | 4 |
Object value = null;
|
80 |
|
|
81 | 4 |
if (getEncode())
|
82 |
{ |
|
83 | 2 |
try
|
84 |
{ |
|
85 | 2 |
value = getDataSqueezer().unsqueeze(externalValue); |
86 |
} |
|
87 |
catch (IOException ex)
|
|
88 |
{ |
|
89 | 0 |
throw new ApplicationRuntimeException(ex.getMessage(), this, null, ex); |
90 |
} |
|
91 |
} |
|
92 |
else
|
|
93 | 2 |
value = externalValue; |
94 |
|
|
95 |
// A listener is not always necessary ... it's easy to code
|
|
96 |
// the synchronization as a side-effect of the accessor method.
|
|
97 |
|
|
98 | 4 |
setValue(value); |
99 |
|
|
100 | 4 |
IActionListener listener = getListener(); |
101 |
|
|
102 | 4 |
if (listener != null) |
103 | 1 |
listener.actionTriggered(this, cycle);
|
104 |
} |
|
105 |
|
|
106 |
public abstract String getElementId();
|
|
107 |
|
|
108 |
/** @since 2.2 * */
|
|
109 |
|
|
110 |
public abstract DataSqueezer getDataSqueezer();
|
|
111 |
|
|
112 |
public abstract Object getValue();
|
|
113 |
|
|
114 |
public abstract void setValue(Object value); |
|
115 |
|
|
116 |
public abstract IActionListener getListener();
|
|
117 |
|
|
118 |
/**
|
|
119 |
* Returns false. Hidden components are never disabled.
|
|
120 |
*
|
|
121 |
* @since 2.2
|
|
122 |
*/
|
|
123 |
|
|
124 | 0 |
public boolean isDisabled() |
125 |
{ |
|
126 | 0 |
return false; |
127 |
} |
|
128 |
|
|
129 |
/**
|
|
130 |
* Returns true if the compent encodes object values using a
|
|
131 |
* {@link org.apache.tapestry.util.io.DataSqueezerImpl}, false if values are always Strings.
|
|
132 |
*
|
|
133 |
* @since 2.2
|
|
134 |
*/
|
|
135 |
|
|
136 |
public abstract boolean getEncode(); |
|
137 |
} |
|