Create new RichFaces Documentation Jira issue

This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.orgCommunity Documentation

6.7.5.  < rich:dropSupport > available since 3.0.0

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.


Table 6.141. rich : dropSupport attributes

Attribute Name Description
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
ajaxSingleLimits JSF tree processing (decoding, conversion, validation and model updating) only to a component that sends the request. Boolean
binding JSF: The 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 an element to set focus after request is completed on client side
id JSF: Every 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", 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.
onbeforedomupdateThe client-side script method to be called before DOM is updated
oncompleteThe client-side script method to be called after the request is completed
ondragenterThe client-side script method to be called when a draggable object enters the zone
ondragexitThe client-side script method to be called after a draggable object leaves the zone
ondropThe client-side script method to be called when a draggable object is dropped into the available zone
ondropendThe client-side script method to be called when a draggable object is dropped into any zone
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
rendered JSF: If "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
similarityGroupingIdIf there are any component requests with identical IDs then these requests will be grouped.
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
typeMappingThe 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 JSF: The current value for this component

Table 6.142. Component identification parameters

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

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

Example:

import org.richfaces.component.html.HtmlDropSupport;

...
HtmlDropSupport myDragZone = new HtmlDropSupport();
...

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:


Using the "typeMapping" attribute. 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" symbol 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_accepting, DNET: text_for_rejecting}">
          <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:


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:


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 in the "Decide what to process" guide section .

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

On the component Live Demo page you can see the example of <rich:dropSupport> usage and sources for the given example.