Send your remarks, comments or wishes to doc team
Subject:
Message:
Your name:
Your email:

JBoss.org Community Documentation

- Prev
- Next

## 6.47. < rich:dropSupport >

### 6.47.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.95. <rich:dropSupport> component

### 6.47.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.191. 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", then of all AJAX-rendered on the page components only those will be updated, which ID's are passed to the "reRender" attribute of the describable component. "false"-the default value-means that all components with ajaxRendered="true" will be updated.
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
similarityGroupingId | If there are any component requests with identical IDs then these requests will be grouped.
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 | The attribute associates a type of dragable zone (dragType) with <rich:dndParam> defined for <rich:dropSupport> for passing parameter value to <rich:dragIndicator>. It uses JSON format: (drag_type: parameter_name).
value | The current value for this component

Table 6.192. 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.47.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.47.4. Creating the Component Dynamically Using Java

Example:

    import org.richfaces.component.html.HtmlDropSupport;

    ...

    HtmlDropSupport myDragZone = new HtmlDropSupport();

    ...

### 6.47.5. Details of Usage

The key attribute for <rich:dropSupport> is "acceptedTypes" . It defines, which types of dragable items (zones) could be accepted by the current drop zone. Check the example below:

    ...

    <rich:panel styleClass="dropTargetPanel">

         <f:facet name="header">

              <h:outputText value="PHP Frameworks" />

         </f:facet>

         <rich:dropSupport id="php" acceptedTypes="PHP" dropValue="PHP" dropListener="#{eventBean.processDrop}" reRender="phptable, src">

         </rich:dropSupport>

         ...

    </rich:panel>

    ...

and here is what happens on the page:

Figure 6.96. Drop zone accepts dragable item with "PHP" type only

"typeMapping" . Previous example shows that a drop zone could accept a dragable item or not. Special markers, which are placed at <rich:dragIndicator> , inform user about drop zone’s possible behaviors: "checkmark" appears if drop is accepted and "No stop" sign if it is not. Moreover, some extra information (e.g. text message) could be put into the Indicator to reinforce the signal about drop zone’s behavior or pass some other additional sense. This reinforcement could be programmed and attributed to drop zone via "typeMapping" attribute using JSON syntax. The type of dragged zone (dragType) should be passed as "key" and name of <rich:dndParam> that gives needed message to Indicator as "value":

    ...

    <rich:panel styleClass="dropTargetPanel">

         <f:facet name="header">

              <h:outputText value="PHP Frameworks" />

         </f:facet>

         <rich:dropSupport id="php" acceptedTypes="PHP" dropValue="PHP" dropListener="#{eventBean.processDrop}" reRender="phptable, src"

                                  typeMapping="{PHP: text_for_accpet, DNET: text_for_rejection}">

              <rich:dndParam name="text_for_accepting" value="Drop accepted!" />

              <rich:dndParam name="text_for_rejecting" value="Drop is not accepted!" />

         </rich:dropSupport>

         ...

    </rich:panel>

    ...

What happens on the page:

Figure 6.97. "typeMapping" helps to add some extra information to <rich:drag indicator>

In examples above dropping a dragable item triggers the use a parameter in the event processing; Ajax request is sent and dropListener defined for the component is 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.98. 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.47.6. Look-and-Feel Customization

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

### 6.47.7. Relevant Resources Links

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

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