concept JSP in category liferay

appears as: JSP, JSP, The JSP
Liferay in Action: The Official Guide to Liferay Portal Development

This is an excerpt from Manning's book Liferay in Action: The Official Guide to Liferay Portal Development.

Listing 2.3. Implementing the JSP for View mode
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %> <jsp:useBean id="userName" class="java.lang.String" scope="request" /> <portlet:defineObjects /> <p>This is the Hello You portlet.</p> <p>Hello <%= userName %>!</p> docroot/view.jsp

Just as you can in a servlet-based web application, you can forward request processing to a JSP from a portlet. And just as in a servlet-based web application, you have to chain a bunch of methods together in order to accomplish it. To make your code neater, you can create a convenience method called include(), shown in the next listing, that chains those methods together for you so all you have to do is call this single method (which has a nice, short name) to forward processing to a JSP.

I must mention one caveat now. Usually, the next step for a developer is to import the project into an IDE, and I don’t want to discourage you from doing this. But I’ve never met an IDE that likes customizing Liferay’s JSPs in a hook. Why? Well, because a hook is one project, and the portal (if you have the source) is another project. If you have a JSP with dependencies from an included JSP in another project (as Liferay does often with its pattern of using init.jsp for imports), the IDE doesn’t know where to find the included file. Because of this, it can’t compile or validate the file. What you wind up with is a file full of red Xs and little squigglies underneath all the objects that the IDE doesn’t understand.

Hooks allow you to replace any of Liferay’s JSP files with your own implementation. Again, this was once only possible to do with Ext. This enables you to modify what is rendered by the JSP files of Liferay’s core portlets. If, for example, you don’t like the way Liferay’s Document Library presents itself, you can modify its JSPs with a hook and include styling in your theme to go along with the modifications. And again, if you undeploy your hook, Liferay will revert back to its default behavior without the need to restart.