From the course: Learning Java Enterprise Edition

JSP EL in practice - Java EE Tutorial

From the course: Learning Java Enterprise Edition

Start my 1-month free trial

JSP EL in practice

- [Instructor] We are now going to take a look at some code examples that demonstrate how expression language is used in the Cargo Tracker application to control what part of the view is rendered, and how the navigation links can be generated from implicit object properties. Okay, so let's have a look. Let's get back to the track page that we looked at earlier on in the course. This page demonstrates two examples of expression language usage that we saw in our previous video. If we have a look at the panel group element, we can see that the component that it wraps will be rendered depending on the value, or the rendered element. And here we use the expression language not empty syntax to determine if the cargo element is empty. If the rendered expression evaluates to true, than the component is rendered by JSF, otherwise the component is ignored. Now scrolling down, we can see further examples where expression language is used to make decisions about what parts of the view is displayed. As we scroll down further to the bottom of the screen, we can see another use of expression language. Here we're using the implicit object that refers to the HTTP request. What we want to do here is to get the context path of the application, and use it to form a back link to the homepage. Now the context path is the prefix or the URL path that is used to select the context to which an incoming request is past. Context path is just one of the many properties available from our HTTP request object. Let's have a look and see how we can see what other properties we can get access to. Now using your IDE auto suggest feature, we can have a look and see exactly what they are. So by doing this, we can scroll down this list of suggestions, and see exactly what kind of methods are available, and what kind of properties we can get access to. So for example, here is our context path, but also what we can get access to is the content type We can get access to the content length. We can continue scrolling down here, we can get access to the cookie. Various other properties can be accessed such as your locale for example, even the local port. The attP method as well can be accessed, as well as various parameter maps and names also. Path info, in fact there's a whole range of various, different properties that can be accessed in this way. By using expression language, we can have quite a lot of power over the information we get access to.

Contents