01: package org.araneaframework.example.main.web.demo;
02:
03: import org.araneaframework.example.main.TemplateBaseWidget;
04: import org.araneaframework.jsp.support.TagAttr;
05: import org.araneaframework.jsp.util.AutomaticFormElementUtil;
06: import org.araneaframework.uilib.form.FormElement;
07: import org.araneaframework.uilib.form.FormWidget;
08: import org.araneaframework.uilib.form.control.TextControl;
09: import org.araneaframework.uilib.form.data.StringData;
10:
11: /**
12: * Demonstrates {@link FormElement} rendering with JSP <ui:automaticFormElement>
13: * tag, which allows dynamically changing the tag with which {@link FormElement}
14: * is rendered.
15: *
16: * @author Taimo Peelo (taimo@araneaframework.org)
17: */
18: public class DemoAutomaticFormElement extends TemplateBaseWidget {
19: private FormWidget form;
20: private FormElement first;
21: private boolean editable = false;
22:
23: protected void init() throws Exception {
24: setViewSelector("demo/demoAutomaticFormElement");
25:
26: form = new FormWidget();
27: first = form.addElement("first", "#First", new TextControl(),
28: new StringData(), "InitialFirst", false);
29: changeFormTags();
30:
31: addWidget("form", form);
32: }
33:
34: public void handleEventReverse() {
35: changeFormTags();
36: }
37:
38: private void changeFormTags() {
39: editable = !editable;
40: if (!editable) {
41: AutomaticFormElementUtil.setFormElementTag(first,
42: "textInputDisplay", new TagAttr[] { new TagAttr(
43: "styleClass", "name") });
44: } else {
45: AutomaticFormElementUtil.setFormElementTag(first,
46: "textInput", new TagAttr[] { new TagAttr(
47: "styleClass", "inpt") });
48: }
49: }
50: }
|