When you use renderRequest, renderResponse, and portletConfig objects in a JSP, your Rational or Eclipse-based IDE will usually give a validation error – “renderRequest cannot be resolved,” for example. Having red-x validation errors in your IDE is annoying as all-hell, so here’s a nice work-around for that…
<%@ page import="javax.portlet.RenderRequest" %> <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%> <%! RenderRequest renderRequest; %> <portlet:defineObjects /> <%-- String portletSiteArea = renderRequest.getPreferences().getValue("sitearea", ""); // code... --%>
- ines 1 and 2 represent the area atop your JSP where you do your imports and taglib references. I’ve put those two in because we’re using both in the code that follows.
- Line 5 is the key. We’re declaring the the renderRequest object so that our IDE will shut up and stop telling us it cannot be resolved.
- Line 8 is important – it’s the tag that establishes the renderRequest, renderResponse, and portletConfig objects so that you can access them in your JSP. It is crucially important to ensure this tag always comes after your declaration of any of those javax.portlet objects. When the <portlet:defineObjects /> tag does its thing, the objects you declared will be overridden by the real deal.
- Line 11 is just a random example showing how you might be using the object in your code to do some real work. The renderRequest instance in that line would normally get a squiggly red underline.
Happy coding! (Unless you’re on a death-march – to which I can only say: hang in there, buddy.))