Why do we need an expression language (EL)?

Expressions are found throughout computer science today. The best known example of expressions is Regular Expressions. Regular expressions is a mini language that allows you to describe and parse text. It is at the heart of many programming languages, programming environments and programs themselves. The reason regular expressions are found in so many areas is because they are extremely powerful.

Regular expressions allow you to master your data. In essence, it is a mini programming language that gives you the ability to control and put your data to work for you. You are able to solve problems with a compact notation that would otherwise require complex or cumbersome programming.

Regular expressions was developed to solve a unique set of problems relating to text processing. EL was designed to solve a unique set of problems relating to JSP which when mastered allows you to master your data.

So lets look at a few examples to highlight the difference between normal JSP code and WW enhanced JSP code.

Readability example:

EL improves readability of code. For instance, in the example above WW calls getGuessBean() on Action and then calls getNumGuesses() on the bean. Now compare the compact notation versus the second listing. WW's is more compact, easier to read, and is more expressive. We didn't worry about scope, class, method name, etc. A page designer shouldn't be bothered with this information.

Conditional example:

In this example, we are performing conditional testing. WW will call getGuessBean() on the Action and then call getSuccess() to return a Boolean. If success is true, then the body will be evaluated. Compare this to the typical JSP version. WW's example is again easier to read primarily because you are not bothered by intrusive <%, %> and Java code. In addition, WW is supporting a conditional equals operator. Also note how WW handles encoding urls with its url tag.

Complex data example:

In this example, we are working through a series of Maps. In WW's version, bucket A1 is retrieved, then bucket A2 from within A1, and then bucket A3 is retrieved within A2 and finally isEmpty() is called. This is more compact than JSP's example. We did not have to write Java code to unwind the data. EL gave us the ability to expand through the series of Maps and retrieve the data we want. Again, the page designer does not have to worry about writing Java code or viewing it in their presentation.

We looked at a few examples to highlight differences between the typical JSP world and WW. They highlighted readability, conditional testing, and the ability to master your data with EL. But this is just the tip of the iceberg.

Where can I use EL?

EL may be used for any attribute of a WW tag except id. id should just be a string without apostrophes. Conditional expressions may only be used in the test attribute for if and elseIf tags.

For instance, take the subset tag. EL is used in all of its attributes. Subset has three attributes, source, count, and start.

In this example, we specify 10 and 5 for subset attributes start and count respectively. EL will evaluate these and turn them into Integers.

<iterator:subset start="10" count="5">
	<webwork:iterator>
		<webwork:property/><br>
	</webwork:iterator>
</iterator:subset>

Types of expressions

There are two main uses of EL. These are value expressions and conditional expressions. Value expressions are expressions that allow you to pull values from multiple locations, scopes, and object types. Conditional expresssions allow you to use conditional operators to evaluate one or more operands. These operands themselves are value expressions.

Value Expressions

Value expressions are expressions that allow you to pull values from multiple locations, scopes, and object types. For instance,

Conditional Expressions

Conditional expressions are expressions that allow you to use conditional operators to evaluate one or more operands. These operands themselves are value expressions. For instance,

In summary, WW's expression language is a powerful tool that gives you great flexibility in accessing data. It allows page designers to easily pull data into views.