6.42.  < rich:dropSupport >

6.42.1. Description

This component transforms a parent component into a target zone for drag-and-drop operations. When a draggable element is moved and dropped onto the area of the parent component, Ajax request processing for this event is started.

<rich:dropSupport> component

Figure 6.73.  <rich:dropSupport> component


6.42.2. Key Features

  • Encodes all necessary JavaScript to perform drop actions

  • Can be used within any component type that provides the required properties for drop operations

  • Built-in Ajax processing

  • Supports drag-and-drop between different forms

Table 6.156. rich : dropSupport attributes

Attribute NameDescription
acceptCursorslist of comma separated cursors that indicates when acceptable draggable over dropzone
acceptedTypesA list of drag zones types, which elements are accepted by a drop zone
actionMethodBinding pointing at the application action to be invoked, if this UIComponent is activated by you, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property
actionListenerMethodBinding pointing at method accepting an ActionEvent with return type void
ajaxSingleif "true", submits ONLY one field/link, instead of all form controls
bindingThe attribute takes a value-binding expression for a component property of a backing bean
bypassUpdatesIf "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input
cursorTypeMappingmapping between drop types and acceptable cursors
dataSerialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax
disableDefaultDisable default action for target event (append "return false;" to JavaScript)
dropListenerMethodBinding representing an action listener method that will be notified after drop operation.
dropValueData to be processed after a drop event
eventsQueueName of requests queue to avoid send next request before complete other from same event. Can be used to reduce number of requests of frequently events (key press, mouse move etc.)
focusid of element to set focus after request completed on client side
idEvery component may have a unique id that is automatically created if omitted
ignoreDupResponsesAttribute allows to ignore an Ajax Response produced by a request if the newest 'similar' request is in a queue already. ignoreDupResponses="true" does not cancel the request while it is processed on the server, but just allows to avoid unnecessary updates on the client side if the response isn't actual now
immediateTrue means, that the default ActionListener should be executed immediately (i.e. during Apply Request Values phase of the request processing lifecycle), rather than waiting until the Invoke Application phase
limitToListIf "true", updates on client side ONLY elements from this 'reRender' property. If "false" (default) updates all rendered by ajax region components
onbeforedomupdateJavaScript code for call before DOM has been updated on client side
oncompleteJavaScript code for call after request completed on client side
ondragenterA JavaScript event handler called on enter draggable object to zone
ondragexitA JavaScript event handler called after a drag object leaves zone
ondropA JavaScript event handler called after a drag object is dropped to zone
ondropendA JavaScript handler for event fired on a drop even the drop for a given type is not available
onsubmitJavaScript code for call before submission of ajax event
processId['s] (in format of call UIComponent.findComponent()) of components, processed at the phases 2-5 in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection
rejectCursorslist of comma separated cursors that indicates when rejectable draggable over dropzone
renderedIf "false", this component is not rendered
requestDelayAttribute defines the time (in ms.) that the request will be wait in the queue before it is ready to send. When the delay time is over, the request will be sent to the server or removed if the newest 'similar' request is in a queue already
reRenderId['s] (in format of call UIComponent.findComponent()) of components, rendered in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection
statusID (in format of call UIComponent.findComponent()) of Request status component
timeoutResponse waiting time on a particular request. If a response is not received during this time, the request is aborted
typeMappingMap between a draggable type and an indicator name on zone. it's defined with the pair (drag type:indicator name))
valueThe current value for this component

Table 6.157. Component identification parameters

NameValue
component-typeorg.richfaces.DropSupport
component-classorg.richfaces.component.html.HtmlDropSupport
component-familyorg.richfaces.DropSupport
renderer-typeorg.richfaces.DropSupportRenderer
tag-classorg.richfaces.taglib.DropSupportTag

6.42.3. Creating the Component with a Page Tag

This simple example shows how to make a panel component a potential drop target for drag-and-drop operations using "text" elements as the dragged items.

Example:


...
    <rich:panel>
        <rich:dropSupport acceptedTypes="text"/>
    </rich:panel>
...

6.42.4. Creating the Component Dynamically Using Java

Example:


import org.richfaces.component.html.HtmlDropSupport;
...
HtmlDropSupport myDragZone = new HtmlDropSupport();
...

6.42.5. Details of Usage

As shown in the example, the key attribute for <rich:dropSupport> is "acceptedTypes" . This attribute defines the types of draggable items that can be dropped onto the designated drop zone.

The second most important attribute for <rich:dropSupport> is "typeMapping" . This attribute maps a specific type among the acceptable types for draggable items to a specific <rich:dndParam> child element under <rich:dropSupport> .

Example:


...
    <rich:dropSupport acceptedTypes="[iconsDragged, textDragged]" typeMapping="{iconsDragged: DropIcon}"> 
        <rich:dndParam name="DropIcon">
            <h:graphicImage value="/images/drop-icon.png"/>
        </rich:dndParam>
...

In this example, dropping a draggable item of an "iconsDragged" type will trigger the use a parameter named "DropIcon" in the event processing after a drop event. (Also, an Ajax request is sent, and the action and dropListener defined for the component are called.)

Here is an example of moving records between tables. The example describes all the pieces for drag-and-drop. (To get extra information on these components, read the sections for these components.)

As draggable items, this table contains a list of such items designated as being of type "text":

Example:


...
    <rich:dataTable value="#{capitalsBean.capitals}" var="caps">
        <f:facet name="caption">Capitals List</f:facet>
        <h:column>
        <a4j:outputPanel>
            <rich:dragSupport dragIndicator=":form:ind" dragType="text">
                <a4j:actionParam value="#{caps.name}" name="name"/>
            </rich:dragSupport>
            <h:outputText value="#{caps.name}"/> 
        </a4j:outputPanel>
        </h:column>
    </rich:dataTable>
...

As a drop zone, this panel will accept draggable items of type "text" and then rerender an element with the ID of "box":

Example:


...
    <rich:panel style="width:100px;height:100px;">
        <f:facet name="header">Drop Zone</f:facet>
        <rich:dropSupport acceptedTypes="text" reRender="box" 
                        dropListener="#{capitalsBean.addCapital2}"/>
    </rich:panel>
...

As a part of the page that can be updated in a partial page update, this table has an ID of "box":

Example:


...
    <rich:dataTable value="#{capitalsBean.capitals2}" var="cap2" id="box">
        <f:facet name="caption">Capitals chosen</f:facet>
        <h:column>
            <h:outputText value="#{cap2.name}"/>
        </h:column>
    </rich:dataTable>
...

And finally, as a listener, this listener will implement the dropped element:

Example:


...
    public void addCapital2(DropEvent event) {
        FacesContext context = FacesContext.getCurrentInstance();
        Capital cap = new Capital();
        cap.setName(context.getExternalContext().getRequestParameterMap().get("name").toString());
        capitals2.add(cap);
    }
...

Here is the result after a few drops of items from the first table:

Results of drop actions

Figure 6.74. Results of drop actions


In this example, items are dragged element-by-element from the rendered list in the first table and dropped on a panel in the middle. After each drop, a drop event is generated and a common Ajax request is performed that renders results in the third table.

As with every Ajax action component, <rich:dropSupport> has all the common attributes ( "timeout", "limitToList", "reRender", etc.) for Ajax request customization.

Finally, the component has the following extra attributes for event processing on the client:

  • ondragenter

  • ondragexit

  • ondrop

  • ondropend

Developers can use their own custom JavaScript functions to handle these events.

Information about the "process" attribute usage you can find here.

6.42.6. Look-and-Feel Customization

<rich:dropSupport> has no skin parameters and custom style classes , as the component isn't visual.

6.42.7. Relevant Resources Links

Here you can see the example of <rich:dropSupport> usage and sources for the given example.