Making a component draggable

Any component can be enhanced with draggable behavior. To enable draggable functionality on any PrimeFaces component, we always need a component called Draggable.

In this recipe, we will see how to make a component draggable and learn some basic features of Draggable. To demonstrate these features, we will make several p:panel components draggable.

How to do it...

A component can be made draggable by using p:draggable. The component ID must match the for attribute of the p:draggable component. If the for attribute is omitted, the parent component will be selected as a draggable target. Let's make some panel components draggable and apply some basic features:

<p:panel id="pnl" header="Draggable panel with default settings"> ...

Get PrimeFaces Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.