--- title: Generating Dynamic Resources Based On URI Or Parameters order: 28 layout: page --- [[generating-dynamic-resources-based-on-uri-or-parameters]] = Generating dynamic resources based on URI or parameters You can dynamically generate responses based on e.g. query parameters by creating your own `RequestHandler` and registering it with the session. In this way, you can for instance create an image that draws a text, given as a parameter to the image. This has been done in the example below: [source,java] .... public class DynamicImageUI extends UI { public static final String IMAGE_URL = "myimage.png"; private final RequestHandler requestHandler = new RequestHandler() { @Override public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { if (("/" + IMAGE_URL).equals(request.getPathInfo())) { // Create an image, draw the "text" parameter to it and output // it to the browser. String text = request.getParameter("text"); BufferedImage bi = new BufferedImage(100, 30, BufferedImage.TYPE_3BYTE_BGR); bi.getGraphics().drawChars(text.toCharArray(), 0, text.length(), 10, 20); response.setContentType("image/png"); ImageIO.write(bi, "png", response.getOutputStream()); return true; } // If the URL did not match our image URL, let the other request // handlers handle it return false; } }; @Override public void init(VaadinRequest request) { Resource resource = new ExternalResource(IMAGE_URL + "?text=Hello!"); getSession().addRequestHandler(requestHandler); // Add an image using the resource Image image = new Image("A dynamically generated image", resource); setContent(image); } @Override public void detach() { super.detach(); // Clean up getSession().removeRequestHandler(requestHandler); } } .... iffstats
path: root/src/main/javassist/bytecode/AccessFlag.java
blob: 736135ec425892b2ecccfe457466e9e302692293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134