JBoss.org Community Documentation

- Prev
- Next

## 6.45. < rich:dropSupport >

### 6.45.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.

Figure 6.89. <rich:dropSupport> component

### 6.45.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.162. rich : dropSupport attributes

Attribute Name | Description
--- | ---
acceptCursors | List of comma separated cursors that indicates when acceptable draggable over dropzone
acceptedTypes | A list of drag zones types, which elements are accepted by a drop zone
action | MethodBinding 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
actionListener | MethodBinding pointing at method accepting an ActionEvent with return type void
ajaxSingle | boolean attribute which provides possibility to limit JSF tree processing(decoding, conversion/validation, value applying) to the component which send the request only
binding | The attribute takes a value-binding expression for a component property of a backing bean
bypassUpdates | If "true", after process validations phase it skips updates of model beans on a force render response. It can be used for validating components input
cursorTypeMapping | Mapping between drop types and acceptable cursors
data | Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax
disableDefault | Disable default action for target event (append "return false;" to JavaScript)
dropListener | MethodBinding representing an action listener method that will be notified after drop operation.
dropValue | Data to be processed after a drop event
eventsQueue | Name 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.)
focus | id of element to set focus after request completed on client side
id | Every component may have a unique id that is automatically created if omitted
ignoreDupResponses | Attribute 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
immediate | True 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
limitToList | If "true", updates on client side ONLY elements from this 'reRender' property. If "false" (default) updates all rendered by ajax region components
onbeforedomupdate | JavaScript code for call before DOM has been updated on client side
oncomplete | JavaScript code for call after request completed on client side
ondragenter | A JavaScript event handler called on enter draggable object to zone
ondragexit | A JavaScript event handler called after a drag object leaves zone
ondrop | A JavaScript event handler called after a drag object is dropped to zone
ondropend | A JavaScript handler for event fired on a drop even the drop for a given type is not available
process | Id['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
rejectCursors | List of comma separated cursors that indicates when rejectable draggable over dropzone
rendered | If "false", this component is not rendered
requestDelay | Attribute 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
reRender | Id['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
status | ID (in format of call UIComponent.findComponent()) of Request status component
timeout | Response waiting time on a particular request. If a response is not received during this time, the request is aborted
typeMapping | Map between a draggable type and an indicator name on zone. it's defined with the pair (drag type:indicator name))
value | The current value for this component

Table 6.163. Component identification parameters

Name | Value
--- | ---
component-type | org.richfaces.DropSupport
component-class | org.richfaces.component.html.HtmlDropSupport
component-family | org.richfaces.DropSupport
renderer-type | org.richfaces.DropSupportRenderer
tag-class | org.richfaces.taglib.DropSupportTag

### 6.45.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.45.4. Creating the Component Dynamically Using Java

Example:

    import org.richfaces.component.html.HtmlDropSupport;

    ...

    HtmlDropSupport myDragZone = new HtmlDropSupport();

    ...

### 6.45.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:

Figure 6.90. 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.45.6. Look-and-Feel Customization

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

### 6.45.7. Relevant Resources Links

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

- Prev6.44. < rich:dragSupport >
- Top of page
- Front page
- Next6.46. < rich:dragListener >