Skip to content

Instantly share code, notes, and snippets.

@sammso
Last active November 16, 2017 09:49
Show Gist options
  • Save sammso/e0e4b7e0513f8ec751bc4d835d8132c8 to your computer and use it in GitHub Desktop.
Save sammso/e0e4b7e0513f8ec751bc4d835d8132c8 to your computer and use it in GitHub Desktop.

Liferay Nordic Bootcamp Gist

SuperCool

Questions: sampsa sohlman at liferay com

https://www.dropbox.com/s/wsspavxno4gesw4/supercoolmvc.zip?dl=0

<%@ include file="/init.jsp" %>

<%@ page import="com.liferay.portal.kernel.util.Constants" %>
<%@ page import="com.example.SuperCoolMVCConfig" %>
<%@ page import="com.liferay.portal.kernel.util.GetterUtil" %>
<%
SuperCoolMVCConfig configuration = 
	(SuperCoolMVCConfig)  renderRequest.getAttribute(SuperCoolMVCConfig.class.getName());

String globalColor = configuration.favoriteColor();
String color = globalColor;

String selectedColor = renderRequest.getPreferences().getValue("favoriteColor", "default");

if (!"default".equals(selectedColor)) {
	color = selectedColor;
}
boolean isCache = GetterUtil.getBoolean(renderRequest.getPreferences().getValue("iscache", "false"));
%>

<liferay-portlet:actionURL portletConfiguration="<%= true %>"
    var="configurationActionURL" />

<liferay-portlet:renderURL portletConfiguration="<%= true %>"
    var="configurationRenderURL" />

<aui:form action="<%= configurationActionURL %>" method="post" name="fm">

    <aui:input name="<%= Constants.CMD %>" type="hidden"
        value="<%= Constants.UPDATE %>" />

    <aui:input name="redirect" type="hidden"
        value="<%= configurationRenderURL %>" />

    <aui:fieldset>

        <aui:select name="favoriteColor" label="Favorite Color"
            value="<%= selectedColor %>">
            <aui:option value="indigo">Indigo</aui:option>
            <aui:option value="blue">Blue</aui:option>
            <aui:option value="green">Green</aui:option>
            <aui:option value="yellow">Yellow</aui:option>
            <aui:option value="orange">Orange</aui:option>
            <aui:option value="red">Red</aui:option>
            <aui:option value="default">default</aui:option> 
        </aui:select>

    </aui:fieldset>
    <aui:button-row>
        <aui:button type="submit"></aui:button>
    </aui:button-row>
    
    <aui:input type="checkbox" name="preferences--iscache--" checked="<%=isCache %>" />
</aui:form>


WHEEEEEE CONFIGURE ME NOW!

<p>Favorite color: 
	<span style="color: <%= color %>;"><%= color %></span>
</p>
<p>Global color: 
	<span style="color: <%= globalColor %>;"><%= globalColor %></span>
</p>

Fixes for the Gradebook AssetPublisher part

AssignmentRenderingFactory

@Reference(target = "(osgi.web.symbolicname=com.liferay.training.space.gradebook)")
private ServletContext _servletContext;
@Override
public PortletURL getURLAdd(
	LiferayPortletRequest liferayPortletRequest,
	LiferayPortletResponse liferayPortletResponse, long classTypeId) {
	PortletURL portletURL = null;

	ThemeDisplay themeDisplay =
		  (ThemeDisplay)liferayPortletRequest.getAttribute(
		  	WebKeys.THEME_DISPLAY);
	  
	portletURL = _portal.getControlPanelPortletURL(
				liferayPortletRequest, getGroup(liferayPortletRequest),
				GradebookPortletKeys.PORTLET_NAME, 0, 0, PortletRequest.RENDER_PHASE);
	
	portletURL.setParameter("mvcRenderCommandName", "/gradebook/assignment/edit");
	portletURL.setParameter("showback", Boolean.FALSE.toString());
	
	return portletURL;
}

gradebook-web/build.gradle

change version

compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.6.0"

GOGO Shell scripting example

portalUtilReference=(serviceReference "com.liferay.portal.kernel.util.PortalUtil")
portalUtil=(service $portalUtilReference)
defaultCompanyId=($portalUtil getDefaultCompanyId)
userServiceReference=(serviceReference "com.liferay.portal.kernel.service.UserLocalService")
userService=(service $userServiceReference)
users=$userService getCompanyUsers $defaultCompanyId 0 100   
each $users { $it getFullName }

JSP hooks

How to include page at JSP fragment

<liferay-util:include page="/create_account.portal.jsp" servletContext="<%= application %>"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment