type=page
status=published
title=Attributes of a Composite Component
next=jsf-advanced-cc002.html
prev=jsf-advanced-cc.html
~~~~~~
= Attributes of a Composite Component


[[GKHWV]]

[[attributes-of-a-composite-component]]
Attributes of a Composite Component
-----------------------------------

A composite component is a special type of JavaServer Faces template
that acts as a component. If you are new to composite components, see
link:jsf-facelets005.html#GIQZR[Composite Components] before you proceed
with this chapter.

You define an attribute of a composite component by using the
`composite:attribute` tag. link:#GKHVF[Table 14-1] lists the commonly
used attributes of this tag.

[[sthref74]][[GKHVF]]

*Table 14-1 Commonly Used Attributes of the composite:attribute Tag*

[width="70%",cols="15%,55%"]
|=======================================================================
|*Attribute* |*Description*
|`name` |Specifies the name of the composite component attribute to be
used in the using page. Alternatively, the `name` attribute can specify
standard event handlers such as `action`, `actionListener`, and managed
bean.

|`default` |Specifies the default value of the composite component
attribute.

|`required` |Specifies whether it is mandatory to provide a value for
the attribute.

|`method-signature` a|
Specifies a subclass of `java.lang.Object` as the type of the composite
component's attribute. The `method-signature` element declares that the
composite component attribute is a method expression. The `type`
attribute and the `method-signature` attribute are mutually exclusive.
If you specify both, `method-signature` is ignored. The default type of
an attribute is `java.lang.Object.`

Note: Method expressions are similar to value expressions, but rather
than supporting the dynamic retrieval and setting of properties, method
expressions support the invocation of a method of an arbitrary object,
passing a specified set of parameters and returning the result from the
called method (if any).

|`type` |Specifies a fully qualified class name as the type of the
attribute. The `type` attribute and the `method-signature` attribute are
mutually exclusive. If you specify both, `method-signature` is ignored.
The default type of an attribute is `java.lang.Object.`
|=======================================================================


The following code snippet defines a composite component attribute and
assigns it a default value:

[source,oac_no_warn]
----
<composite:attribute name="username" default="admin"/>
----

The following code snippet uses the `method-signature` element:

[source,oac_no_warn]
----
<composite:attribute name="myaction"
                     method-signature="java.lang.String action()"/>
----

The following code snippet uses the `type` element:

[source,oac_no_warn]
----
<composite:attribute name="dateofjoining" type="java.util.Date"/>
----
