Book Image

Primefaces Cookbook Second Edition

Book Image

Primefaces Cookbook Second Edition

Overview of this book

Table of Contents (20 chapters)
PrimeFaces Cookbook Second Edition
Credits
Foreword
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Snapping to the edges of nearest elements


With PrimeFaces, we can snap the dragged component to the inner or outer boundaries of another component (a component's DOM element).

In this recipe, we will discuss snapping and its options in detail. As an example, we will develop a big h:panelGroup component as a snap target and three other small h:panelGroup components as draggable components, with various snapping options.

How to do it…

Generally, the snapping behavior is activated by setting the attribute snap to true. The snapping behavior is configurable with two options—snapMode and snapTolerance. The first option, snapMode, determines which edges of snap elements the draggable component will snap to. The second option, snapTolerance, determines a distance in pixels the draggable component must be from the element when snapping is invoked.

<h:panelGroup id="snaptarget" layout="block"
  styleClass="ui-widget-content"
  style="height:150px;width:450px;">
  <p class="ui-widget-header"...