1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.tiles.jsp.taglib;
23
24 import javax.servlet.jsp.tagext.TagSupport;
25
26 /***
27 * <p><strong>Put an attribute in enclosing attribute container tag.</strong></p>
28 * <p>Enclosing attribute container tag can be :
29 * <ul>
30 * <li><initContainer></li>
31 * <li><definition></li>
32 * <li><insertAttribute></li>
33 * <li><insertDefinition></li>
34 * <li><putList></li>
35 * </ul>
36 * (or any other tag which implements the <code>{@link PutAttributeTagParent}</code> interface.
37 * Exception is thrown if no appropriate tag can be found.</p>
38 * <p>Put tag can have following atributes :
39 * <ul>
40 * <li>name : Name of the attribute</li>
41 * <li>value : value to put as attribute</li>
42 * <li>type : value type. Only valid if value is a String and is set by
43 * value="something" or by a bean.
44 * Possible type are : string (value is used as direct string),
45 * template (value is used as a page url to insert),
46 * definition (value is used as a definition name to insert)</li>
47 * <li>direct : Specify if value is to be used as a direct string or as a
48 * page url to insert. This is another way to specify the type. It only apply
49 * if value is set as a string, and type is not present.</li>
50 * <li>beanName : Name of a bean used for setting value. Only valid if value is not set.
51 * If property is specified, value come from bean's property. Otherwise, bean
52 * itself is used for value.</li>
53 * <li>beanProperty : Name of the property used for retrieving value.</li>
54 * <li>beanScope : Scope containing bean. </li>
55 * <li>role : Role to check when 'insert' will be called. If enclosing tag is
56 * <insert>, role is checked immediately. If enclosing tag is
57 * <definition>, role will be checked when this definition will be
58 * inserted.</li>
59 * </ul></p>
60 * <p>Value can also come from tag body. Tag body is taken into account only if
61 * value is not set by one of the tag attributes. In this case Attribute type is
62 * "string", unless tag body define another type.</p>
63 *
64 * @version $Rev: 739526 $ $Date: 2009-01-31 09:50:58 +0100 (sab, 31 gen 2009) $
65 */
66 public class PutAttributeTag extends AddAttributeTag {
67
68 /***
69 * Name of attribute to put in attribute context.
70 */
71 protected String name = null;
72
73 /***
74 * If <code>true</code>, the attribute will be cascaded to all nested
75 * definitions.
76 */
77 private boolean cascade = false;
78
79 /***
80 * Returns the name of the attribute.
81 *
82 * @return The name of the attribute.
83 */
84 public String getName() {
85 return name;
86 }
87
88 /***
89 * Sets the name of the attribute.
90 *
91 * @param name The name of the attribute.
92 */
93 public void setName(String name) {
94 this.name = name;
95 }
96
97 /***
98 * Checks if the attribute should be cascaded to nested definitions.
99 *
100 * @return <code>true</code> if the attribute will be cascaded.
101 * @since 2.1.0
102 */
103 public boolean isCascade() {
104 return cascade;
105 }
106
107 /***
108 * Sets the property that tells if the attribute should be cascaded to
109 * nested definitions.
110 *
111 * @param cascade <code>true</code> if the attribute will be cascaded.
112 * @since 2.1.0
113 */
114 public void setCascade(boolean cascade) {
115 this.cascade = cascade;
116 }
117
118 /*** {@inheritDoc} */
119 @Override
120 protected void reset() {
121 super.reset();
122 name = null;
123 cascade = false;
124 }
125
126 /*** {@inheritDoc} */
127 @Override
128 protected void execute() throws TilesJspException {
129 PutAttributeTagParent parent = (PutAttributeTagParent)
130 TagSupport.findAncestorWithClass(this, PutAttributeTagParent.class);
131
132
133 if (parent == null) {
134 throw new TilesJspException(
135 "Error: no enclosing tag accepts 'putAttribute' tag.");
136 }
137
138 parent.processNestedTag(this);
139 }
140 }