Java Programming/Struts/Struts Tag Library
Struts provides a library of JSP tags for use in constructing an application.
Common Features
[edit | edit source]All Struts tags are designed to accept common attributes, and share a common method of interacting with the environment. These attributes all refer to keyed beans stored in the page, request, session, or application objects using the setAttribute()
function of each. The four most common features are:
Attribute | Attribute Name |
---|---|
Name | The key to find the bean under. |
Scope | The Scope attribute identifies the context to find the key in. If the scope is undefined, every available context will be searched in the order of page, request, session, and then application. |
id | The name of the scripting value that is created in the page context by this tag. |
Property | Specifies the Java Bean property to be placed in the page context. If this is not specified, the bean itself will be placed in the page context. |
All of these attributes, where they apply, are used in similar ways in order to simplify the interface.
Nested References
[edit | edit source]The struts tag library also provides the ability to call deeper than just what's been added to the available contexts. For instance, to access the bean b within the bean a, you would set the name attribute to "a" and the property attribute to "b". However, if b had a property containing another bean (c) that you wished to access, the property attribute could be set to "b.c".
Additionally, indexed references can be used. If a an array of b, item two of the array could be referenced using a property value of "b[2]".
In summary:
In Struts Tags | Expressed in java |
---|---|
< ... name="a" property="b" >
|
context.getAttribute("a").getB()
|
< ... name="a" property="b.c" >
|
context.getAttribute("a").getB().getC()
|
< ... name="a" property="b[2]" >
|
context.getAttribute("a").getB(2)
|
< ... name="puppy" property="cat.rabbit[8]" >
|
context.getAttribute("puppy").getCat().getRabbit(8)
|
Bean tags
[edit | edit source]These tags all relate to Java Beans. They are used to create and access objects that use the JavaBeans standard. Because the design of Struts is intended to decouple logic and presentation, these tags are unable to modify beans.
Html tags
[edit | edit source]These tags create HTML entities. They are used to avoid the use of scriptlets for tasks like prepopulating forms or determining the targets of links.
Logic tags
[edit | edit source]These tags are used for control flow within the document. If constructions, iteration, and page redirects are included in this namespace.
Nesting tags
[edit | edit source]Further Reading
[edit | edit source]More Struts Tutorials : http://www.strutsmypassion.com