For those of you developing themes, you may have realized that the markup you place in portlet.vm to flesh out your designs fails big – it doesn’t even attend the party – when your user turns the portlet borders off with the portlet look-and-feel option. The java developers among you won’t be fazed. Fixing the problem – really fixing it – is just a small edit to portlet.jsp.
But you design folks, the ones who usually have this problem, may wonder if you have any server-side solutions available at all. (This could just as easily be solved with client-side JavaScript, with the usual disadvantages of that approach.)
As a theme developer, you have the final say in how the UI is presented. That’s right. You have the ability to edit almost all of the markup related to the page before it’s packaged up and set back to the client as a response. But, in the case of borderless portlets, it isn’t so easy.
Below is a small modification to /html/common/themes/portlet.jsp
<% /** * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ %> <%@ include file="/html/common/init.jsp" %> <portlet:defineObjects /> <tiles:useAttribute id="tilesPortletContent" name="portlet_content" classname="java.lang.String" ignore="true" /> <tiles:useAttribute id="tilesPortletDecorate" name="portlet_decorate" classname="java.lang.String" ignore="true" /> <tiles:useAttribute id="tilesPortletPadding" name="portlet_padding" classname="java.lang.String" ignore="true" /> <% Portlet portlet = (Portlet)request.getAttribute(WebKeys.RENDER_PORTLET); /** * MODIFICATION #1 * CUSTOM BOOLEAN - This will be set by the current theme. */ boolean customThemeBorders = GetterUtil.getBoolean(themeDisplay.getTheme().getSetting("custom-theme-borders"), false); PortletPreferences portletSetup = PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletDisplay.getId()); RenderResponseImpl renderResponseImpl = (RenderResponseImpl)renderResponse; // Portlet decorate boolean tilesPortletDecorateBoolean = GetterUtil.getBoolean(tilesPortletDecorate, true); boolean portletDecorateDefault = false; if (tilesPortletDecorateBoolean) { portletDecorateDefault = GetterUtil.getBoolean(theme.getSetting("portlet-setup-show-borders-default"), PropsValues.THEME_PORTLET_DECORATE_DEFAULT); } boolean portletDecorate = GetterUtil.getBoolean(portletSetup.getValue("portlet-setup-show-borders", String.valueOf(portletDecorateDefault))); Boolean portletDecorateObj = (Boolean)renderRequest.getAttribute(WebKeys.PORTLET_DECORATE); if (portletDecorateObj != null) { portletDecorate = portletDecorateObj.booleanValue(); request.removeAttribute(WebKeys.PORTLET_DECORATE); } // Portlet title String portletTitle = PortletConfigurationUtil.getPortletTitle(portletSetup, themeDisplay.getLanguageId()); if (portletDisplay.isAccess() && portletDisplay.isActive()) { if (Validator.isNull(portletTitle)) { portletTitle = renderResponseImpl.getTitle(); } } if (Validator.isNull(portletTitle)) { ResourceBundle resourceBundle = portletConfig.getResourceBundle(locale); portletTitle = resourceBundle.getString(JavaConstants.JAVAX_PORTLET_TITLE); } Group group = layout.getGroup(); portletDisplay.setTitle(portletTitle); Boolean renderPortletResource = (Boolean)request.getAttribute(WebKeys.RENDER_PORTLET_RESOURCE); boolean runtimePortlet = (renderPortletResource != null) && renderPortletResource.booleanValue(); boolean freeformPortlet = themeDisplay.isFreeformLayout() && !runtimePortlet && !layoutTypePortlet.hasStateMax(); String containerStyles = StringPool.BLANK; StringBuilder sb = new StringBuilder(); sb.append("style=""); if (freeformPortlet) { Properties freeformStyleProps = PropertiesUtil.load(portletSetup.getValue("portlet-freeform-styles", StringPool.BLANK)); sb.append("height: "); sb.append(GetterUtil.getString(freeformStyleProps.getProperty("height"), "300px")); sb.append(";"); sb.append("overflow: auto;"); } sb.append("""); containerStyles = sb.toString(); %> <c:choose> <c:when test="<%= themeDisplay.isFacebook() %>"> <%@ include file="/html/common/themes/portlet_facebook.jspf" %> </c:when> <c:when test="<%= themeDisplay.isStateExclusive() %>"> <%@ include file="/html/common/themes/portlet_content_wrapper.jspf" %> </c:when> <c:when test="<%= themeDisplay.isStatePopUp() %>"> <div> <c:if test="<%= Validator.isNotNull(tilesPortletContent) %>"> <liferay-util:include page="<%= StrutsUtil.TEXT_HTML_DIR + tilesPortletContent %>" /> </c:if> <c:if test="<%= Validator.isNull(tilesPortletContent) %>"> <% pageContext.getOut().print(renderRequest.getAttribute(WebKeys.PORTLET_CONTENT)); %> </c:if> </div> </c:when> <c:otherwise> <c:choose> <c:when test="<%= portletDecorate %>"> <liferay-theme:wrap-portlet page="portlet.jsp"> <div class="portlet-content-container" <%= containerStyles %>> <%@ include file="/html/common/themes/portlet_content_wrapper.jspf" %> </div> </liferay-theme:wrap-portlet> <c:if test="<%= freeformPortlet && LayoutPermissionUtil.contains(permissionChecker, layout, ActionKeys.UPDATE) %>"> <div class="ui-resizable-handle ui-resizable-se"></div> </c:if> </c:when> <c:otherwise> <div class="portlet-borderless-container" <%= containerStyles %>> <c:if test="<%= (tilesPortletDecorateBoolean && portletDisplay.isShowConfigurationIcon()) || portletDisplay.isShowBackIcon() %>"> <div class="portlet-borderless-bar"> <c:if test="<%= tilesPortletDecorateBoolean && portletDisplay.isShowConfigurationIcon() %>"> <span class="portlet-title-default"><%= portletDisplay.getTitle() %></span> <span class="portlet-actions"> <span class="portlet-css lfr-js-required"> - <a href="<%= portletDisplay.getURLPortletCss() %>"><liferay-ui:message key="look-and-feel" /></a> </span> <span class="portlet-configuration"> - <a href="<%= portletDisplay.getURLConfiguration() %>"><liferay-ui:message key="configuration" /></a> </span> <c:if test="<%= portletDisplay.isShowEditIcon() %>"> <span class="portlet-edit"> - <a href="<%= portletDisplay.getURLEdit() %>"><liferay-ui:message key="preferences" /></a> </span> </c:if> <c:if test="<%= portletDisplay.isShowCloseIcon() %>"> <span class="portlet-close"> - <a href="<%= portletDisplay.getURLClose() %>"><liferay-ui:message key="close" /></a> </span> </c:if> </span> </c:if> <c:if test="<%= portletDisplay.isShowBackIcon() %>"> - <a href="<%= portletDisplay.getURLBack() %>"><liferay-ui:message key="back" /></a> </c:if> </div> </c:if> /** * MODIFICATION #2 * CUSTOM CHOOSE - If the customThemeBorders boolean is true, * each portlet's content will be wrapped by portlet.vm even when * portlet-setup-show-borders is false. * * This will require a change to your portlet.vm in themes with this * enabled. */ <c:choose> <c:when test="<%=customThemeBorders%>"> <liferay-theme:wrap-portlet page="portlet.jsp"> <%@ include file="/html/common/themes/portlet_content_wrapper.jspf" %> </liferay-theme:wrap-portlet> </c:when> <c:otherwise> <%@ include file="/html/common/themes/portlet_content_wrapper.jspf" %> </c:otherwise> </c:choose> </div> <c:if test="<%= freeformPortlet %>"> <div class="portlet-resize-container"> <div class="portlet-resize-handle"></div> </div> </c:if> </c:otherwise> </c:choose> </c:otherwise> </c:choose>/html/common/themes/portlet.jsp
Here is a modified portlet.vm to handle borderless portlets when the theme setting, custom-theme-borders, is enabled:
#set ($portlet_display = $portletDisplay)
#set ($portlet_id = $htmlUtil.escape($portlet_display.getId()))
#set ($portlet_title = $portlet_display.getTitle())
#set ($portlet_content = $portlet_display.getContent())
#set ($portlet_back_url = $portlet_display.getURLBack())
## PREFERENCES
#set ($preferences = $portletDisplay.getPortletSetup())
#set ($bordersEnabled = $preferences.getValue("portlet-setup-show-borders", ""))
## CUSTOM SWITCH
#if ($bordersEnabled == true)
<div class="portlet" id="portlet-wrapper-$portlet_id">
<div class="portlet-topper">
<span class="portlet-title">
$theme.iconPortlet() $portlet_title
</span>
<div class="portlet-icons" id="portlet-small-icon-bar_$portlet_id">
#if ($portlet_display.isShowBackIcon())
<a href="$portlet_back_url" class="portlet-icon-back">#language ("return-to-full-page")</a>
#else
$theme.iconOptions()
$theme.iconMinimize()
$theme.iconMaximize()
$theme.iconClose()
#end
</div>
</div>
<div class="portlet-content">
$portlet_content
</div>
</div>
#else
## BORDERLESS MENU APPEARS HERE: Web Content Display - Look and Feel - Configuration - Close
<div id='custom_markup'>$portlet_content</div>
#end
portlet.vm

