public
Created

Liferay portlet: Passing attributes to JSP

  • Download Gist
CustomPortlet.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14
public class CustomPortlet extends MVCPortlet {
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) {
 
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
User currentUser = themeDisplay.getUser();
 
renderRequest.setAttribute("currentFirstName", currentUser.getFirstName());
// Add attributes as required
 
super.doView(renderRequest, renderResponse);
}
}
view.jsp
Java Server Pages
1 2 3 4 5
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 
<portlet:defineObjects />
 
<div> Your first name is: <%= request.getAttribute("currentFirstName"); %> </div>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.