Thursday, February 12, 2015

Liferay 6.2 - How to submit a form on another pages portlet to populate fields on another page in a different portlet

So, lets say I have a search form at the top of a page in one portlet. All you want it to do is take the parameters and forward it to a search form. Simple right?

Sort of... So let me copy all the code that pertains to this whole thing in order of processing.


[PORTLET A: VIEW.JSP]

<portlet:actionURL var="editContentURL">
    <portlet:param name="method" value="find-a-job" />
</portlet:actionURL>

<aui:form action="<%= editContentURL %>" method="post">
 <aui:input name="<portlet:namespace />jobTitle" placeholder="Job Title" />
<aui:button type="submit" value="Submit" />
</aui:form>


[PORTLET A: CUSTOM MVC PORTLET > processAction( )]

ThemeDisplay themeDisplay = (ThemeDisplay)aReq.getAttribute(WebKeys.THEME_DISPLAY);
String jobTitle = ParamUtil.getString(aReq, "<portlet:namespace />jobTitle");
String redirect = themeDisplay.getPortalURL() + "/web/48924/jobseekers/find-a-job?jobTitle=" + jobTitle;
aResp.sendRedirect(redirect);


[PORTLET B: CUSTOM MVC PORTLET > doView() ]

HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));
String jobTitle = httpReq.getParameter("jobTitle");

log.info("jobTitle = " + jobTitle);
renderRequest.setAttribute("jobTitle",  jobTitle);


[PORTLET B: VIEW.JSP ]

<% String jobTitle = (String)request.getAttribute("jobTitle"); %>
<aui:input label="Job Title or Keywords" name="<portlet:namespace />title" cssClass="title1" value="<%= jobTitle %>" />

Friday, February 6, 2015

Liferay 6.2 - Display a sub-tree layout type side nav bar in Liferay

<%@ include file="init.jsp" %>
<%
        long groupId = themeDisplay.getLayout().getGroupId();
List<Layout> rootLayouts = LayoutLocalServiceUtil.getLayouts(layout.getGroupId(), layout.isPrivateLayout());

String friendlyURL = themeDisplay.getLayout().getFriendlyURL();
friendlyURL = friendlyURL.substring(friendlyURL.indexOf("/") + 1);
String rootURL = friendlyURL.substring(0, friendlyURL.indexOf("/"));

%>


<ul class="unstyled">
<% 

for (Layout layout1 : rootLayouts ) { 
if ( layout1.getFriendlyURL().contains(rootURL)) {
%>       
            <li><a href="/web/<%= groupId %><%= layout1.getFriendlyURL() %>"><%= layout1.getName() %></a></li>
        <% } } %>