1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.wotonomy.web;
20
21 import net.wotonomy.foundation.NSArray;
22 import net.wotonomy.foundation.NSDictionary;
23
24 /***
25 * Used to generate any HTML element dynamically. It only creates the opening tag without a closing tag.
26 * To generate HTML elements that have opening and closing tags, as well as some content in between,
27 * use WOGenericContainer instead.
28 * @author michael@mpowers.net
29 * @author $Author: cgruber $
30 * @version $Revision: 905 $
31 */
32 public class WOGenericElement extends WODynamicElement {
33
34 static NSArray bindings = new NSArray( new Object[]
35 { "elementName", "omitTags", "elementID", "otherTagString",
36 "formValue", "formValues", "invokeAction" } );
37
38 public WOGenericElement() {
39 super();
40 }
41
42 public WOGenericElement(String n, NSDictionary m, WOElement t) {
43 super(n, m, t);
44 }
45
46 public String elementName(WOContext c) {
47 String x = (String)valueForProperty("elementName", c.component());
48 if (x != null)
49 return x;
50 return c.elementID();
51 }
52
53 public void takeValuesFromRequest(WORequest r, WOContext c) {
54 if ( c.elementID().equals( c.senderID() ) )
55 {
56 Object value;
57 value = r.formValueForKey( c.elementID() );
58 setValueForProperty( "formValue", value, c.component() );
59 value = r.formValuesForKey( c.elementID() );
60 setValueForProperty( "formValues", value, c.component() );
61 }
62 }
63
64 public WOActionResults invokeAction(WORequest r, WOContext c)
65 {
66 WOActionResults result = null;
67 String action = stringForProperty( "invokeAction", c.component() );
68 if ( action != null && c.elementID().equals( c.senderID() ) )
69 {
70 result = c.component().performAction( action );
71 }
72 return result;
73 }
74
75 public void appendToResponse(WOResponse r, WOContext c) {
76 WOComponent component = c.component();
77 if ( !booleanForProperty( "omitTags", component ) )
78 {
79 r.appendContentString("<");
80 r.appendContentString(elementName(c));
81 String other = stringForProperty( "otherTagString", component );
82 if ( other != null )
83 {
84 r.appendContentString( " " );
85 r.appendContentString( other );
86 }
87 String add = additionalHTMLProperties(component, bindings);
88 if (add.length() > 0)
89 r.appendContentString(add);
90 r.appendContentString(">");
91 }
92 setValueForProperty( "elementID", c.elementID(), component );
93 }
94
95 }