01: package com.icesoft.faces.context;
02:
03: import org.w3c.dom.Document;
04: import org.w3c.dom.Element;
05:
06: import java.io.Serializable;
07: import java.util.Map;
08: import java.util.Random;
09:
10: public class ElementController implements Serializable {
11: private transient final static Random RANDOM = new Random();
12: private transient String focusCode = "";
13: private transient String selectCode = "";
14: private transient String clickCode = "";
15:
16: public static ElementController from(Map session) {
17: String key = ElementController.class.toString();
18: if (!session.containsKey(key)) {
19: session.put(key, new ElementController());
20: }
21:
22: return (ElementController) session.get(key);
23: }
24:
25: public void focus(String elementID) {
26: focusCode = "'" + elementID + "'.asExtendedElement().focus();"
27: + randomComment();
28: }
29:
30: public void select(String elementID) {
31: selectCode = "'" + elementID
32: + "'.asExtendedElement().select();" + randomComment();
33: }
34:
35: public void click(String elementID) {
36: clickCode = "'" + elementID + "'.asExtendedElement().click();"
37: + randomComment();
38: }
39:
40: private String randomComment() {
41: return "//" + RANDOM.nextInt(99999);
42: }
43:
44: public void addInto(Element element) {
45: Document document = element.getOwnerDocument();
46:
47: Element focusElement = (Element) element.appendChild(document
48: .createElement("script"));
49: focusElement.setAttribute("id", "focus-code");
50: focusElement.appendChild(document.createTextNode(focusCode));
51:
52: Element selectElement = (Element) element.appendChild(document
53: .createElement("script"));
54: selectElement.setAttribute("id", "select-code");
55: selectElement.appendChild(document.createTextNode(selectCode));
56:
57: Element clickElement = (Element) element.appendChild(document
58: .createElement("script"));
59: clickElement.setAttribute("id", "click-code");
60: clickElement.appendChild(document.createTextNode(clickCode));
61: }
62: }
|