Drag and Drop

This example demonstrates an advanced scenario with ajax enhanced draggables, droppables.

Squad
Squad
No records found.

Source

<h:form prependId="false">

    <p:growl id="growl" showDetail="true"/>

    <h:panelGrid columns="2" columnClasses="lineup,squad">

        <p:panel header="Squad">
            <p:dataGrid id="availablePlayers" value="#{barcelona.players}" var="player" columns="4">
                <p:column>
                    <p:graphicImage id="player" value="/images/barca/#{player.photo}" styleClass="playerImage"/>

                    <p:draggable for="player" revert="true" scope="#{player.position}" stack=".playerImage"/>
                </p:column>
            </p:dataGrid>
        </p:panel>

        <h:panelGroup>
            <h:panelGrid columns="3" style="margin-left:40px;">
                <p:outputPanel id="LF" styleClass="slot">
                    <p:droppable  tolerance="fit" activeStyleClass="slotActive" scope="forward" onDrop="handleDrop" datasource="availablePlayers">
                        <p:ajax listener="#{barcelona.onDrop}" update="selectedPlayers growl" />
                    </p:droppable>
                </p:outputPanel>

                <p:outputPanel id="CF" styleClass="slot">
                    <p:droppable  tolerance="fit" activeStyleClass="slotActive" scope="forward" onDrop="handleDrop" datasource="availablePlayers">
                        <p:ajax listener="#{barcelona.onDrop}" update="selectedPlayers growl" />
                    </p:droppable>
                </p:outputPanel>

                <p:outputPanel id="RF" styleClass="slot">
                    <p:droppable  tolerance="fit" activeStyleClass="slotActive" scope="forward" onDrop="handleDrop" datasource="availablePlayers">
                        <p:ajax listener="#{barcelona.onDrop}" update="selectedPlayers growl" />
                    </p:droppable>
                </p:outputPanel>
            </h:panelGrid>

            <h:panelGrid columns="3" style="margin-left:40px;">
                <p:outputPanel id="LCM" styleClass="slot">
                    <p:droppable  tolerance="fit" activeStyleClass="slotActive" scope="midfield" onDrop="handleDrop" datasource="availablePlayers">
                        <p:ajax listener="#{barcelona.onDrop}" update="selectedPlayers growl" />
                    </p:droppable>
                </p:outputPanel>

                <p:outputPanel id="DM" styleClass="slot">
                    <p:droppable  tolerance="fit" activeStyleClass="slotActive" scope="midfield" onDrop="handleDrop" datasource="availablePlayers">
                        <p:ajax listener="#{barcelona.onDrop}" update="selectedPlayers growl" />
                    </p:droppable>
                </p:outputPanel>

                <p:outputPanel id="RCM" styleClass="slot">
                    <p:droppable  tolerance="fit" activeStyleClass="slotActive" scope="midfield" onDrop="handleDrop" datasource="availablePlayers">
                        <p:ajax listener="#{barcelona.onDrop}" update="selectedPlayers growl" />
                    </p:droppable>
                </p:outputPanel>
            </h:panelGrid>

            <h:panelGrid columns="4">
                <p:outputPanel id="LB" styleClass="slot">
                    <p:droppable  tolerance="fit" activeStyleClass="slotActive" scope="defence" onDrop="handleDrop" datasource="availablePlayers">
                        <p:ajax listener="#{barcelona.onDrop}" update="selectedPlayers growl" />
                    </p:droppable>
                </p:outputPanel>

                <p:outputPanel id="CB1" styleClass="slot">
                    <p:droppable  tolerance="fit" activeStyleClass="slotActive" scope="defence" onDrop="handleDrop" datasource="availablePlayers">
                        <p:ajax listener="#{barcelona.onDrop}" update="selectedPlayers growl" />
                    </p:droppable>
                </p:outputPanel>

                <p:outputPanel id="CB2" styleClass="slot">
                    <p:droppable  tolerance="fit" activeStyleClass="slotActive" scope="defence" onDrop="handleDrop" datasource="availablePlayers">
                        <p:ajax listener="#{barcelona.onDrop}" update="selectedPlayers growl" />
                    </p:droppable>
                </p:outputPanel>

                <p:outputPanel id="RB" styleClass="slot">
                    <p:droppable  tolerance="fit" activeStyleClass="slotActive" scope="defence" onDrop="handleDrop" datasource="availablePlayers">
                        <p:ajax listener="#{barcelona.onDrop}" update="selectedPlayers growl" />
                    </p:droppable>
                </p:outputPanel>
            </h:panelGrid>

            <h:panelGrid columns="1" style="margin-left:120px;">
                <p:outputPanel id="GK" styleClass="slot">
                    <p:droppable  tolerance="fit" activeStyleClass="slotActive" scope="goalkeeper" onDrop="handleDrop" datasource="availablePlayers">
                        <p:ajax listener="#{barcelona.onDrop}" update="selectedPlayers growl" />
                    </p:droppable>
                </p:outputPanel>
            </h:panelGrid>
        </h:panelGroup>


    </h:panelGrid>

    <p:panel header="Squad">
        <p:dataList value="#{barcelona.selectedPlayers}" var="player" id="selectedPlayers">
            #{player.number} - #{player.name}
        </p:dataList>
    </p:panel>

</h:form>