Attributes - Your First $1000 online (2014)

Your First $1000 online (2014)

Chapter 5: Attributes

“From a programmer's point of view, the user is a peripheral that types when you issue a read request.”-Peter Williams

You might want to customize how your tags function so that you can display your web page. This could be because you want to have more control over the way you display content on your web page or because you want to make an app, too. The attribute is used to modify the element by assigning a value to it. This way the web page developer can manipulate the element to change it. One can make attributes inside tags with start tags. This is done to create various section, identifiers or to present information in a certain way.

Some tags are used simply to break a line and such tags are mostly empty. These are empty tags that are similar to the start tag and they do not utilize end tags. Here’s an example of aline break tag:<br>.

There are 3 types of attributes: simple attributes, fragment attributes and dynamic attributes.

Simple Attributes

Simple attributes have the following syntax:attr="value".

These can be seen in the start tag. You can usestringconstants or expression language to set this attribute. Here’s an example of how string constants can be used for simple attributes:

<string name="hello_world">Hello world!</string>

This specific attribute was used to determine the name of the Hello World app. Consequentially, the app’s name appeared to be as follows:“Hello World!”

Jsp.attribute elements can be used for these attributes too. This enables you to change the values of various attributes inside the XML body rather than doing so via the XML attributes.

Fragment Attributes

A tag handler uses fragments in order to customize content on the web page. For this you need to declare theFragmentand define the values for these attributes. Also, when using thejsp:attributeelement remember that no scripting elements can be included. These can only include static texts, custom and standard tags. This means you cannot include comments, directives, declarations, scriptlets or expressions. These will not show on the web browser.

Dynamic Attributes

These are not specified in tags. The names of these attributes might not be known when the web page is still being developed. Here’s an example of a tag that describes more than one attribute:

<colored:colored color1="red" color2="yellow" color3="blue"/>

You can read about more attributes here: http://www.tutorialspoint.com/html/html_attributes_reference.htm.

Summary

Attributes can be used to customize different tags. This chapter teaches you about the 3 basic types of attributes and when these can be used to give effects to tags.

Questions

1. What are attributes?

2. What do these have to do with elements?

3. Why is it beneficial for a programmer to use the Jsp.attribute element?