Skip to content

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.
Terminal window
blade create -t portlet-toolbar-contributor pdf-export-contributor
pdf-export-contributor/src/main/java/com/example/pdfexport/PdfExportContributor.java
@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
);
}
}
// In your portlet's JS file
function exportToPdf() {
Liferay.Util.fetch("/o/pdf-export-contributor/export/pdf")
.then((response) => response.blob())
.then((blob) => {
const url = URL.createObjectURL(blob);
window.open(url);
});
}
  • Document Export: Export portlet data as PDF/CSV.
  • Custom Actions: “Share on Social Media” button.