1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwe.app.client.web.request;
18
19 import java.util.HashMap;
20
21 import javax.servlet.http.HttpServletRequest;
22
23 import org.gwe.app.client.config.ClientConfig;
24 import org.gwe.app.client.web.view.Renderer;
25
26
27
28
29
30 public class PageModel extends HashMap<String, Object> {
31
32 public PageModel(HttpServletRequest request, ClientConfig config) {
33 for (Param field : Param.values())
34 setParam(field, field.extractFrom(request));
35
36 put("request", request);
37 put("config", config);
38 put("version", config.getAppContext().getDistribution().getVersion());
39 put("renderer", new Renderer());
40 }
41
42 public Object setParam(Param field, Object value) {
43 return put(field.getFieldId(), value);
44 }
45
46 public <VALUE_TYPE> VALUE_TYPE getParam(Param<VALUE_TYPE, ?> field) {
47 Object value = get(field.getFieldId());
48 VALUE_TYPE result = field.parse(value);
49 return "".equals(result) ? null : result;
50 }
51
52 public Operation getOperation() {
53 return Operation.getOperation(getParam(Param.OPER));
54 }
55
56 public <VALUE_TYPE, OBJECT_TYPE> void addIdentifiedObject(Param<VALUE_TYPE, OBJECT_TYPE> field, OBJECT_TYPE object) {
57 put(field.getObjectIdentifiedName(), object);
58 }
59
60 public <VALUE_TYPE, OBJECT_TYPE> OBJECT_TYPE getIdentifiedObject(Param<VALUE_TYPE, OBJECT_TYPE> field) {
61 return (OBJECT_TYPE) get(field.getObjectIdentifiedName());
62 }
63 }