Skip to content

Commit

Permalink
LPD-40036 Make Taglib Sample Portlet extensible so it can be used wit…
Browse files Browse the repository at this point in the history
…h other taglibs
  • Loading branch information
antonio-ortega authored and brianchandotcom committed Dec 17, 2024
1 parent f143f2c commit 2aec476
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*/
public class TaglibSamplePortletKeys {

public static final String FRONTEND_SAMPLE_DISPLAY_CONTEXT =
"FRONTEND_TAGLIB_DISPLAY_CONTEXT";

public static final String SEARCH_PAGINATOR_DISPLAY_CONTEXT =
"SEARCH_PAGINATOR_DISPLAY_CONTEXT";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/

package com.liferay.frontend.taglib.sample.web.internal.display.context;

import com.liferay.frontend.taglib.clay.servlet.taglib.util.TabsItem;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.TabsItemListBuilder;

import java.util.List;

/**
* @author Antonio Ortega
*/
public class FrontendSampleDisplayContext {

public List<TabsItem> getTabsItems() {
if (_tabsItems != null) {
return _tabsItems;
}

_tabsItems = TabsItemListBuilder.add(
tabsItem -> {
tabsItem.setActive(true);
tabsItem.setLabel("Search Paginator");
tabsItem.setPanelId("search_paginator");
}
).build();

return _tabsItems;
}

private List<TabsItem> _tabsItems;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.liferay.frontend.taglib.sample.web.internal.portlet;

import com.liferay.frontend.taglib.sample.web.internal.constants.TaglibSamplePortletKeys;
import com.liferay.frontend.taglib.sample.web.internal.display.context.FrontendSampleDisplayContext;
import com.liferay.frontend.taglib.sample.web.internal.display.context.SearchPaginatorDisplayContext;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.util.Portal;
Expand Down Expand Up @@ -56,6 +57,10 @@ public void doDispatch(
new SearchPaginatorDisplayContext(
_portal, renderRequest, renderResponse));

renderRequest.setAttribute(
TaglibSamplePortletKeys.FRONTEND_SAMPLE_DISPLAY_CONTEXT,
new FrontendSampleDisplayContext());

super.doDispatch(renderRequest, renderResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@
taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %><%@
taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>

<%@ page import="com.liferay.frontend.taglib.sample.web.internal.constants.TaglibSamplePortletKeys" %><%@
<%@ page import="com.liferay.frontend.taglib.clay.servlet.taglib.util.TabsItem" %><%@
page import="com.liferay.frontend.taglib.sample.web.internal.constants.TaglibSamplePortletKeys" %><%@
page import="com.liferay.frontend.taglib.sample.web.internal.display.context.FrontendSampleDisplayContext" %><%@
page import="com.liferay.frontend.taglib.sample.web.internal.display.context.SearchPaginatorDisplayContext" %>
<%@ page import="java.util.List" %>
<%
FrontendSampleDisplayContext frontendSampleDisplayContext = (FrontendSampleDisplayContext)request.getAttribute(TaglibSamplePortletKeys.FRONTEND_SAMPLE_DISPLAY_CONTEXT);
%>
<liferay-theme:defineObjects />
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,24 @@

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

<liferay-util:include page="/partials/fieldset.jsp" servletContext="<%= application %>" />
<liferay-util:include page="/partials/search_paginator.jsp" servletContext="<%= application %>" />
<%
List<TabsItem> tabsItems = frontendSampleDisplayContext.getTabsItems();
%>

<clay:tabs
tabsItems="<%= tabsItems %>"
>

<%
for (TabsItem tabsItem : tabsItems) {
%>

<clay:tabs-panel>
<liferay-util:include page='<%= "/partials/" + tabsItem.get("panelId") + ".jsp" %>' servletContext="<%= application %>" />
</clay:tabs-panel>

<%
}
%>

</clay:tabs>

0 comments on commit 2aec476

Please sign in to comment.