JSF Languages

Some earlier web technologies intermingle HTML or XHTML and various other programming languages. Disadvantages include:

JSF is designed to use different languages for different aspects of a web application. These languages include:

Extensible Markup Language (XML)

XML is not really a single language. It is a metalanguage for capturing document structures in textual form. XML defines a syntax for adding markup tags to text, but does not itself define any markup tags. It is left to individual languages to specify the markup tags and their meaning.

In JSF there are a few configuration files that use specialized XML variants. These files are placed into the "Web Pages/WEB_INF" folder in the NetBeans development view.

For developers, the most important XML-based language for JSF is XHTML. For writing XHTML it is useful to understand the motivation and structure of XML tags.

Motivation

A flexible document structuring language must be able to model hierarchical structures, much like the Composite design pattern. Generally such languages need to deal with three problems:

Programming languages such as C, C++, and Java, for example, have a structure for if statements. This form is shown below with color coding to indicate the language elements for dealing with the three needs described above.

if (condition) {
statements
}

XML based languages meet the three needs with a different syntax as shown below.

<tag-name attributes-list>
content
</tag-name>

XML Tags

<tag-name attributes-list>
content
</tag-name>

Here tag-name identifies the type of element such as head, body, ul, or table in XHTML. attributes-list is a space-separated sequence of attributes, each with the form

    attribute-name=attribute-value
      

where attribute-name is the name of an attribute and attribute-value is a single-quoted or double-quoted string specifying the value of the attribute. Most XHTML elements, for example, can have attributes named class and id. The value for class is just a name that can be used in style sheet rules to control the styling. The value for id identifies elements that need to be referenced by other elements.

content is a mixture of ordinary text and elements, allowing the overall structure to be viewed as an example of the Composite design pattern.

Extensible HyperText Markup Language (XHTML)

XHTML is HTML that adheres to the stricter tag rules of XML. It is used for web pages that are designed to avoid browser variations due to the laxity of HTML. XHTML file names have a ".xhtml" suffix. In NetBeans they appear in the "Web Pages" folder of the development view.

Each screen of a JSF application is normally specified by an XHTML file. Using the extensibility of XHTML, JSF has several tag libraries specifying new tags that can be used:

Cascading Style Sheets (CSS)

CSS is the standard web language for controlling the style of web pages. CSS file names have a ".css" suffix. They can be referenced by several XHTML files to facilitate consistent styling of web pages. In NetBeans they are usually placed in the "Web Pages/resources/css" folder of the development view.

JavaScript

JavaScript is the standard web language for incorporating client-side executable code. JavaScript file names have a ".js" suffix. They can be referenced by several XHTML files to facilitate consistent client-side behavior for web pages. In NetBeans they are usually placed in the "Web Pages/resources/javascript" folder of the development view.

Java

In JSF, Java is the language for all of the business logic. There are three Java technologies that play an important "glue" role in connecting the business logic to other parts of a JSF application. In NetBeans they are usually placed in package subfolders of the "Source Packages" folder of the development view.

Structured Query Language (SQL)

SQL is a standard language for accessing relational databases such as Oracle, Apache Derby, MySQL, and PostgreSQL. SQL file names have a ".sql" suffix. In NetBeans they are usually placed in the "Web Pages/resources/sql" folder of the development view.

SQL code can be embedded into Java with the JDBC libraries. With the addition of a simple Java class the embedded code can be avoided allowing the code to be read from SQL files.

Expression Language (EL)

Any complex web application framework need some mechanism for linking web pages with application and business logic. JSF uses EL embedded in the XHTML files for this purpose. EL expressions can be identified by their "${" and "}" delimiters.

EL is kept simple to avoid problems with embedded quotation and escape mechanisms. Have you ever worked with regular expressions in Java?