2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.renderer;
19
20 import java.io.IOException;
21 import java.util.Map;
22
23 import javax.faces.component.UIComponent;
24 import javax.faces.context.FacesContext;
25 import javax.faces.context.ResponseWriter;
26 import javax.faces.render.Renderer;
27
28 import org.apache.shale.component.Token;
29
30 /***
31 * <p>Renderer for a {@link Token} component, dealing with a transaction
32 * token used to catch duplicate form submits.</p>
33 *
34 * $Id: TokenRenderer.java 464373 2006-10-16 04:21:54Z rahul $
35 */
36 public class TokenRenderer extends Renderer {
37
38
39
40
41
42 /***
43 * <p>Save the submitted value if this component was actually rendered.</p>
44 *
45 * @param context <code>FacesContext</code> for the current request
46 * @param component <code>UIComponent</code> to be decoded
47 */
48 public void decode(FacesContext context, UIComponent component) {
49
50 if ((context == null) || (component == null)) {
51 throw new NullPointerException();
52 }
53
54 Token token = (Token) component;
55 if (token.isRendered()) {
56 String clientId = token.getClientId(context);
57 Map map = context.getExternalContext().getRequestParameterMap();
58 token.setSubmittedValue(map.get(clientId));
59 }
60
61 }
62
63
64 /***
65 * <p>Render the start of a hidden input element containing the transaction
66 * token value for this component.</p>
67 *
68 * @param context <code>FacesContext</code> for the current request
69 * @param component <code>UIComponent</code> to be decoded
70 *
71 * @exception IOException if an input/output error occurs
72 */
73 public void encodeBegin(FacesContext context, UIComponent component)
74 throws IOException {
75
76 if ((context == null) || (component == null)) {
77 throw new NullPointerException();
78 }
79
80 Token token = (Token) component;
81 if (token.isRendered()) {
82 ResponseWriter writer = context.getResponseWriter();
83 writer.startElement("input", token);
84 String clientId = token.getClientId(context);
85 writer.writeAttribute("id", clientId, "id");
86 writer.writeAttribute("name", clientId, "id");
87 writer.writeAttribute("type", "hidden", null);
88 writer.writeAttribute("value", token.getToken(), null);
89 }
90
91 }
92
93
94 /***
95 * <p>Render the end of a hidden input element containing the transaction
96 * token value for this component.</p>
97 *
98 * @param context <code>FacesContext</code> for the current request
99 * @param component <code>UIComponent</code> to be decoded
100 *
101 * @exception IOException if an input/output error occurs
102 */
103 public void encodeEnd(FacesContext context, UIComponent component)
104 throws IOException {
105
106 if ((context == null) || (component == null)) {
107 throw new NullPointerException();
108 }
109
110 Token token = (Token) component;
111 if (token.isRendered()) {
112 ResponseWriter writer = context.getResponseWriter();
113 writer.endElement("input");
114 }
115
116 }
117
118
119 }