Chapter 6. Building a view: tags
This chapter covers
- Working with data tags
- Controlling flow with control tags
- Surveying the miscellaneous tags
- Exploring the OGNL expression language
In this chapter, we’ll start looking at the Struts 2 tag library in detail. We’ll provide a good reference to the tags and clear examples of their usage. We’ll also finish exploring the Object-Graph Navigation Language (OGNL). We’ve already seen how OGNL is used to bind form fields to Java properties, such as those exposed on our action, to guide the framework’s automatic data transfer mechanism. In chapter 5 we learned about the type conversion aspects of OGNL in the context of data entering the framework.
Now, we’ll focus on the OGNL expression language (EL) in the context of data exiting the framework through the Struts 2 tag API. While the previous chapter showed us how to map incoming request parameters to Java properties exposed on the ValueStack, this chapter will show you how to pull data off of those properties for the rendering of result pages. We’ll explore the syntax of the OGNL EL and study the locations from which it can pull data. In particular, we’ll look closely at the ValueStack and the ActionContext. These objects hold all of the data important to processing a given request, including your action object. While it may be possible to blissfully ignore their existence during much of your development, we think the benefits are too high not to spend a few minutes getting to know them.