Skip to content

Instantly share code, notes, and snippets.

View evaldeslacasa's full-sized avatar

Enrique Valdes Lacasa evaldeslacasa

  • Thirdwave LLC
  • Madrid
View GitHub Profile
@evaldeslacasa
evaldeslacasa / dynamicButtonURL.jsp
Last active August 29, 2015 14:08
Added script using Liferay to generate a Portlet URL dynamically depending on the clicked button
<aui:button value="Button 1" name="button1"
onClick='<%=renderResponse.getNamespace() + "getButtonId(1);"%>'/>
<aui:button value="Button 2" name="button2"
onClick='<%=renderResponse.getNamespace() + "getButtonId(2);"%>'/>
<aui:button value="Button 3" name="button3"
onClick='<%=renderResponse.getNamespace() + "getButtonId(3);"%>'/>
<aui:button value="Button 4" name="button4"
@evaldeslacasa
evaldeslacasa / Sign Out button for Liferay (Velocity)
Last active August 29, 2015 14:13
Sign out button for Liferay Theme 6.2.1 CE
#if($is_signed_in)
<a href="$sign_out_url" title="#language("go-to") $company_name" class="signout">Sign Out</a>
#end
@evaldeslacasa
evaldeslacasa / retrieveHTMLContent.java
Last active August 29, 2015 14:14
Retrieve Web Content article in HTML - Liferay 6.1.1 CE. To retrieve the HTML of a web content added in the Site Scope... which is based on a template and structure from Global Scope
protected String retrieveHTMLContent(ThemeDisplay themeDisplay) throws SystemException, PortalException{
String structureId="MY_STRUCTURE_ID";
String templateId = "MY_TEMPLATE_ID";
Company company = CompanyLocalServiceUtil.getCompanyByMx(PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID));
long globalGroupId = company.getGroup().getGroupId();
long groupId = themeDisplay.getLayout().getGroupId();
JournalStructure rememberMe = JournalStructureLocalServiceUtil.getStructure(globalGroupId,structureId);
JournalArticle rememberMeContent =
@evaldeslacasa
evaldeslacasa / retrieveHTMLContent2.java
Last active August 29, 2015 14:14
Retrieve Web Content article in HTML (Part II) - Liferay 6.1.1 CE. To retrieve the HTML of a web content from Site Scope... but if in the Site Scope is not available...retrieve it from Global Scope
protected String retrieveHTMLContent(ThemeDisplay themeDisplay) throws SystemException, PortalException{
String structureId="MY_STRUCTURE_ID";
String templateId = "MY_TEMPLATE_ID";
Company company = CompanyLocalServiceUtil.getCompanyByMx(PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID));
long globalGroupId = company.getGroup().getGroupId();
long groupId = themeDisplay.getLayout().getGroupId();
JournalStructure rememberMe = JournalStructureLocalServiceUtil.getStructure(globalGroupId,structureId);
JournalArticle rememberMeContent;
@evaldeslacasa
evaldeslacasa / usersPopUpsSearchContainer.jsp
Created January 28, 2015 22:42
Add pop up URLs for each user displayed in a search container column text (URLs stored in an arraylist)
<%
List<String> popUpURLs = new ArrayList();
for(String userId:userIds){
User user = UserLocalServiceUtil.getUser(Long.valueOf(userId));
%>
<portlet:renderURL var="viewUserPopUp" windowState="pop_up">
<portlet:param name="userId"
value="<%=String.valueOf(user.getUserId())%>" />
@evaldeslacasa
evaldeslacasa / structureIdWorkAround.groovy
Last active August 29, 2015 14:14
This script aims to avoid patching the bug happening in Liferay 6.2 CE ga2 where Structure Ids weren't exposed, even when disabling the autogeneration of Ids. It can be run through the scripting console in the Control Panel. To understand the issue, visit: https://issues.liferay.com/browse/LPS-48441.
import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
import com.liferay.portlet.journal.model.JournalStructure;
List<JournalStructure> lista = JournalStructureLocalServiceUtil.getStructures();
println(lista);
JournalStructure myStructure = JournalStructureLocalServiceUtil.getStructure(10903);
// hard coded id of the structure that you want, mine was 10903
println(myStructure);
myStructure.setStructureId("MY_STRUCTURE_ID");
println(myStructure);
@evaldeslacasa
evaldeslacasa / refreshPage.jsp
Created February 11, 2015 16:41
Script in pop up to close pop up and refresh the page in Liferay
<script type="text/javascript">
AUI().ready(function(A) {
window.top.location.href = window.top.location;
});
</script>
@evaldeslacasa
evaldeslacasa / adt_document_library.vm
Last active June 3, 2021 13:27
ADT to display Document Library files' links in Asset Publisher - Liferay 6.2
#set($dlFileEntryService = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService"))
#if (!$entries.isEmpty())
<div id="$portletInstance" class="documents-links">
#foreach ($entry in $entries)
#set($renderer = $entry.getAssetRenderer() )
#set($className = $renderer.getClassName() )
#if( $className == "com.liferay.portlet.documentlibrary.model.DLFileEntry" )
#set($classPk = $entry.getClassPK())
#set($fileEntry = $dlFileEntryService.getDLFileEntry($classPk))
@evaldeslacasa
evaldeslacasa / myAccountUrlGist.vm
Last active August 29, 2015 14:18
My Account button for users to edit their account in a pop up display for Liferay 6.2
## Add this in portal_normal.vm to get a link to My Account
#set ($my_account_url = $theme_display.getURLMyAccount() + "&controlPanelCategory=my")
<a href="javascript:Liferay.Util.openWindow({dialog: {destroyOnHide: true}, title: 'My Account', uri: '$my_account_url'});">
@evaldeslacasa
evaldeslacasa / getNodeText.java
Created June 8, 2015 14:56
Java class with method to get node value from JSON String using Jackson
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
/**
* The readNodeValue method allows us to get a node value
* using the JSON Jackson library in Java. In this case
* we are interested in getting the value of a child node
* nested inside of a father node.
*
* The JSON input would be like this: