Drag'n'Drop Operations

Top  Previous  Next

Drag and drop components allow to use standard drag and drop operations between two or more components or inside the ones.

 

Drag and drop components have two boolean attributes to enable drag and drop functionality:

dragEnabled – allows to drag the component or it's part to other component(s)
dropEnabled – allows to drop other drag and drop components to the given component

These attributes can be used in any combinations. By default both attributes are false.

 

Drag and drop components have client and server side event listeners:

userFunctionOnDrop – client side JavaScript function to be used upon drop event occurs
onDropListener – server side listener, must implement com.softaspects.jsf.component.base.draganddrop.event.OnDropEventListener

 

To setup drag and drop operation it's required to set appropriate drag and drop Strategy.

 

When user makes drag and drop operation client side JavaScript function is called. Then AJAX request is sent to the component's server side. Target component's Strategy is called to perform exact drag and drop operation. Then the server side onDropListener is called for the components involved in the drag and drop operations. Optionally some components may be refreshed by AJAX automatically.

 

It is possible to use default or custom drag and drop Strategy by setting component "strategy" property.

 

For custom Strategies the corresponding property should refer to full class name or faces value binding.  In the case of default Strategies it is possible to use the following pre-defined short names:

 

copy – copy data from the source component to the target one
move – move data from the source component to the target one
remove – remove data from the source component
create – create data at the target component based on the source component data
copySelfMove – combination of copy and move operations – move inside component, otherwise perform copy operation

 

To create custom drag and drop Strategy com.softaspects.jsf.component.base.draganddrop.strategy.DnDStrategy interface should be implemented. This interface contains the following method:

 

public DnDOperationResult doDragOperation(DnDMetaData from, DnDMetaData to);

 

The method should perform drag and drop operation for source and target components. Parameters are Drag and Drop components meta data which can contain additional data for particular components (like tree path, row, cell, etc.). It returns the resulting DnDOperationResult object indicating what exact components should be refreshed (one, both or none).