Portlet Toolbar Contributor
Adds custom buttons or actions to a portlet’s toolbar (e.g., “Publish”, “Share”).
- Extend default portlet functionality (e.g., add “Export to PDF”).
- Provide quick actions without modifying the original portlet.
Implementation
Section titled “Implementation”Create the Module
Section titled “Create the Module”blade create -t portlet-toolbar-contributor pdf-export-contributorAdd a Toolbar Button
Section titled “Add a Toolbar Button”@Component( property = { "javax.portlet.name=" + MyPortletKeys.MY_PORTLET, // Target portlet "mvc.command.name=/export/pdf" // Action command }, service = PortletToolbarContributor.class)public class PdfExportContributor implements PortletToolbarContributor { @Override public void contribute( PortletToolbarContext portletToolbarContext, HttpServletRequest httpServletRequest ) { portletToolbarContext.addButton( "export-pdf", // Button ID "Export PDF", // Label "download", // Lexicon icon "javascript:exportToPdf()" // JS action ); }}Add JavaScript Logic
Section titled “Add JavaScript Logic”// In your portlet's JS filefunction exportToPdf() { Liferay.Util.fetch("/o/pdf-export-contributor/export/pdf") .then((response) => response.blob()) .then((blob) => { const url = URL.createObjectURL(blob); window.open(url); });}Use Cases
Section titled “Use Cases”- Document Export: Export portlet data as PDF/CSV.
- Custom Actions: “Share on Social Media” button.