Documentation
Home
Quick overview (new)
Tutorial
Download
Installation
Javadoc

Tag Library Reference
Components Tags
Extension Tags

Printer Versions
Quick Overview (new)
Tutorial
Overview (old)

Old Documents
Overview (old)

Components Tag Library
Components Tag Library
This tag library provides templates / components tags.
Components and templates are the same and are used indiferently (for historical reasons). Also, a lot of tags and attribute names are left for backward compatibility.
To know more about tags defined in this library, check the associated documentation : comps-doc.
Tag NameDescription
insert Insert a component/template.
definition Create a component / template definition bean.
put Put an attribute into component/template context.
putList Declare a list that will be pass as attribute to component.
add Add an element to the surrounding list. Equivalent to 'put', but for list element.
get Gets the content from request scope that was put there by a put tag.
getAsString Render the value of the specified component/template attribute to the current JspWriter
useAttribute Use attribute value inside page.
importAttribute Import Component's attribute in specified context.
initComponentDefinitions Initialize Component definitions factory.
insert - Insert a component/template.
Insert a component/template with the possibility to pass parameters (called attribute). A component can be seen as a procedure that can take parameters or attributes. <template:insert> allows to define these attributes and pass them to the inserted jsp page, called template. Attributes are defined using nested tag <template:put> or <template:putList>.
You must specify one of this tag attribute :
  • template, for inserting a component/template page,
  • component, for inserting a component/template page, (same as template)
  • page for inserting a JSP page, (same as template)
  • definition, for inserting a definition from definitons factory
  • attribute, surrounding component's attribute name whose value is used.
    If attribute is associated to 'direct' flag (see put), and flag is true, write attribute value (no insertion).
  • name, to let 'insert' determine the type of entities to insert. In this later case, search is done in this order : definitions, components/templates, pages.

In fact, Page, component and template, are equivalent as a component or template are jsp page.
Example :

          <comp:insert page="/basic/myLayout.jsp" flush="true">
            <comp:put name="title"  value="My first page" />
            <comp:put name="header" value="/common/header.jsp" />
            <comp:put name="footer" value="/common/footer.jsp" />
            <comp:put name="menu"   value="/basic/menu.jsp" />
            <comp:put name="body"   value="/basic/helloBody.jsp" />
          </comp:insert>
Attribute NameDescription
template A string representing the URI of a template (a JSP page).
'page', 'component' and 'template' are synonyms : they have exactly the same behavior.
[RT Expr]
component Path (relative or absolute to webapps) of the component to insert.
'page', 'component' and 'template' are synonyms : they have exactly the same behavior.
[RT Expr]
page Path (relative or absolute to webapps) of the page to insert.
'page', 'component' and 'template' are synonyms : they have exactly the same behavior.
[RT Expr]
definition Name of the definition to insert. Definition are defined in a centralized file. For now, only definition from factory can be inserted with this attribute. To insert a definiton defined with tag <template:definition>, use beanName="". [RT Expr]
attribute Name of an attribute in current component context. Value of this attribute is passed to 'name' (see attribute 'name').
name Name of an entity to insert. Search is done in this order : definition, attribute, [component/template/page]. [RT Expr]
beanName Name of the bean used as value. Bean is retrieved from specified context, if any. Otherwise, method pageContext.findAttribute is used. If beanProperty is also specified, retrieve value from the corresponding bean property.
If found bean (or property value) is instance of one of Attribute class (Direct, Instance, ...), insertion is done according to the class type. Otherwise, the toString method is called on the bean, and returned String is used as name to insert (see 'name' attribute).
[RT Expr]
beanProperty Bean property name. If specified, value is retrieve from this property. Support nested/indexed properties. [RT Expr]
beanScope Scope into which bean is searched. If not specified, method pageContext.findAttribute is used. Scope can be any JSP scope, 'component', or 'template'. In these two later cases, bean is search in component/template context.
flush True or false. If true, current page out stream is flushed before insertion.
ignore If this attribute is set to true, and the attribute specified by the name does not exist, simply return without writing anything. The default value is false, which will cause a runtime exception to be thrown. [RT Expr]
role If the user is in the specified role, the tag is taken into account; otherwise, the tag is ignored (skipped). [RT Expr]
definition - Create a component / template definition bean.
Create a component or template definition as a bean. Newly created bean will be saved under specified "id", in the requested "scope". Definition tag has same syntax as insert tag. The new definition can extends a definition described in factory (XML file), and overload any previously defined parameters.
Attribute NameDescription
id Specifies the name under which the newly created definition bean will be saved. [Required]
scope Specifies the variable scope into which the newly defined bean will be created. If not specified, the bean will be created in page scope.
template A string representing the URI of a component/template (a JSP page). [RT Expr]
page URL of the template / component to insert. Same as "template". [RT Expr]
role Role to check before inserting this definition. If role is not defined for current user, definition is not inserted. Checking is done at insert time, not during definition process. [RT Expr]
extends Name of a parent definition that is used to initialize this new definition. Parent definition is searched in definitions factory. [RT Expr]
put - Put an attribute into component/template context.
Define an attribute to pass to component/template. This tag can only be used inside 'insert' or 'definition' tag. Value (or content) is specified using attribute 'value' (or 'content'), or using the tag body. It is also possible to specify the type of the value :
  • string : Content is writed directly.
  • page | template : Content is included from specified URL. Name is used as an URL.
  • definition : Content come from specified definition (from factory). Name is used as definition name.
If type is specified, it is taken into account by 'get' or 'insert' inside the inserted component.
If 'type' attribute is not specified, content is 'untyped', unless it comes from a typed bean.
Note that using 'direct="true"' is equivalent to 'type="string"'.
Attribute NameDescription
name Name of the attribute.
value Attribute value. Could be a String or an Object. Value can come from a direct assignement (value="aValue") or from a bean. One of 'value' 'content' or 'beanName' must be present. [RT Expr]
content Content that's put into component scope. Synonym to value. Attribute added for compatibility with JSP Template. [RT Expr]
direct Determines how content is handled: true means content is printed directly; false, the default, means content is included. This is another way to specify content type. If 'direct=true' content is 'string', if 'direct=false', content is 'page'. Attribute added for compatibility with JSP Template.
type Specify content type: string, page, template or instance.
  • String : Content is printed directly.
  • page | template : Content is included from specified URL. Name is used as an URL.
  • definition : Value denote a definition defined in factory (xml file). Definition will be searched in the inserted component, in a <template:insert attribute="attributeName"> tag, where 'attributeName' is the name used for this tag.
If 'type' attribute is not specified, content is 'untyped', unless it comes from a typed bean.
beanName Name of the bean used as value. Bean is retrieved from specified context, if any. Otherwise, method pageContext.findAttribute is used. If beanProperty is specified, retrieve value from the corresponding bean property. [RT Expr]
beanProperty Bean property name. If specified, value is retrieve from this property. Support nested/indexed properties. [RT Expr]
beanScope Scope into which bean is searched. If not specified, method pageContext.findAttribute is used. Scope can be any JSP scope, 'component', or 'template'. In these two later cases, bean is search in component/template context.
role If the user is in the specified role, the tag is taken into account; otherwise, the tag is ignored (skipped). [RT Expr]
putList - Declare a list that will be pass as attribute to component.
Declare a list that will be pass as attribute to component. List elements are added using the tag 'add'. This tag can only be used inside 'insert' or 'definition' tag.
Attribute NameDescription
name Name of the list. [Required]
add - Add an element to the surrounding list. Equivalent to 'put', but for list element.
Add an element to the surrounding list. This tag can only be used inside putList tag. Value can come from a direct assignement (value="aValue") or from a bean. One of 'value' or 'beanName' must be present.
Attribute NameDescription
value Element value. Can be a String or Object.
content Element value. Can be a String or Object. Synonym to value. Attribute added for compatibility with JSP Template. [RT Expr]
direct Determines how content is handled: true means content is printed directly; false, the default, means content is included. This is another way to specify content type. If 'direct=true' content is 'string', if 'direct=false', content is 'page'. Attribute added for compatibility with JSP Template.
type Specify content type: string, page, template or instance.
  • String : Content is printed directly.
  • page | template : Content is included from specified URL. Name is used as an URL.
  • definition : Value denote a definition defined in factory (xml file). Definition will be searched in the inserted component, in a <insert attribute="attributeName"> tag, where 'attributeName' is the name used for this tag.
If 'type' attribute is not specified, content is 'untyped', unless it comes from a typed bean.
beanName Name of the bean used as value. Bean is retrieved from specified context, if any. Otherwise, method pageContext.findAttribute is used. If beanProperty is specified, retrieve value from the corresponding bean property. [RT Expr]
beanProperty Bean property name. If specified, value is retrieve from this property. Support nested/indexed properties. [RT Expr]
beanScope Scope into which bean is searched. If not specified, method pageContext.findAttribute is used. Scope can be any JSP scope, 'component', or 'template'. In these two later cases, bean is search in component/template context.
role If the user is in the specified role, the tag is taken into account; otherwise, the tag is ignored (skipped). [RT Expr]
get - Gets the content from request scope that was put there by a put tag.
Retrieve content from component context and include it.
Take into account the 'type' attribute.
Attribute NameDescription
name The name of the content to get from component scope. [Required] [RT Expr]
ignore If this attribute is set to true, and the attribute specified by the name does not exist, simply return without writing anything. The default value is false, which will cause a runtime exception to be thrown. [RT Expr]
flush True or false. If true, current page out stream is flushed before insertion.
role If the user is in the specified role, the tag is taken into account; otherwise, the tag is ignored (skipped). [RT Expr]
getAsString - Render the value of the specified component/template attribute to the current JspWriter
Retrieve the value of the specified component/template attribute property, and render it to the current JspWriter as a String. The usual toString() conversions is applied on found value.
Throw a JSPException if named value is not found.
Attribute NameDescription
name Attribute name. [Required] [RT Expr]
ignore If this attribute is set to true, and the attribute specified by the name does not exist, simply return without writing anything. The default value is false, which will cause a runtime exception to be thrown. [RT Expr]
role If the user is in the specified role, the tag is taken into account; otherwise, the tag is ignored (skipped). [RT Expr]
useAttribute - Use attribute value inside page.
Declare a Java variable, and an attribute in the specified scope, using component attribute value.
Java variable and attribute will have the name specified by 'id', or the original name if not specified.
Attribute NameDescription
id Declared attribute and variable name.
classname Class of the declared variable.
scope Scope of the declared attribute. Default to 'page'.
name Component's attribute name. [Required] [RT Expr]
ignore If this attribute is set to true, and the attribute specified by the name does not exist, simply return without error. The default value is false, which will cause a runtime exception to be thrown. [RT Expr]
importAttribute - Import Component's attribute in specified context.
Import attribute from component to requested scope. Attribute name and scope are optional. If not specified, all component attributes are imported in page scope. Once imported, an attribute can be used as any other beans from jsp contexts.
Attribute NameDescription
name Component's attribute name. If not specified, all attributes are imported. [RT Expr]
scope Scope into which attribute is imported. Default to page.
ignore If this attribute is set to true, and the attribute specified by the name does not exist, simply return without error. The default value is false, which will cause a runtime exception to be thrown. [RT Expr]
initComponentDefinitions - Initialize Component definitions factory.
Initialize Components definitions factory.
In order to use Component definitions factory, you need to initialize the factory. This is generally done in a initializing servlet. In particular, it is done in "ComponentActionServlet" if you use it. If you don't initialize factory in a servlet, you can initialize it using this tag. You need to provide the description file name, and optionnaly the factory classname. Initialization is done only once, at the first call of this tag. Subsequent calls are ignored (tag check existance of the factory.
Attribute NameDescription
file Definition file name. [Required]
classname If specified, classname of the factory to create and initialized.

Copyright © 2000, Apache Software Foundation
and S1 Corporation