Primefaces: Value attribute to Draggable and Droppable

Created on 12 Apr 2015  Β·  5Comments  Β·  Source: primefaces/primefaces

Draggable and Droppable should have value attributes to easily identify what has been dragged and dropped onto.

new feature

Most helpful comment

on this moment I found only one workaround, but in my opinion this is bad way

<p:treeNode>
    <h:outputText id="selectedCategoryNode" value="#{node}" />
    <p:droppable for="selectedCategoryNode" scope="tabletotree"
    datasource="nomenclatureTable" activeStyleClass="ui-state-highlight" tolerance="touch">
        <p:ajax listener="#{catalogBean.onDragDropTree}" update="nomenclatureTable msgs"/>
        <f:attribute name="category" value="#{node}" />
    </p:droppable>
</p:treeNode>
<!-- <p:dataTable id="nomenclatureTable" -->
<p:column id="drag" style="width:20px">
    <h:outputText id="dragIcon" styleClass="ui-icon ui-icon-arrow-4" />
    <p:draggable for="dragIcon" scope="tabletotree" revert="true" helper="clone" />
</p:column>
    public void onDragDropTree(DragDropEvent event) {
        FacesMessage message;
        try {
            Nomenclature nomenclature = (Nomenclature) event.getData();
            Nomenclature category;

            if (event.getComponent().getAttributes().get("category") instanceof String) {
                category = new Nomenclature(0L, "НомСнклатура");
            } else {
                category = (Nomenclature) event.getComponent().getAttributes()
                        .get("category");
            }

            nomenclatureService.move(category, nomenclature);
            nomenclatureList = nomenclatureService.getNomenclature(parentId);
            message = new FacesMessage(FacesMessage.SEVERITY_INFO,
                    "ΠŸΠ΅Ρ€Π΅ΠΌΡ–Ρ‰Π΅Π½Π½Ρ", "НомСнклатура " + nomenclature
                            + " ΠΏΠ΅Ρ€Π΅ΠΌΡ–Ρ‰Π΅Π½Π° Π² ΠΊΠ°Ρ‚Π΅Π³ΠΎΡ€Ρ–ΡŽ " + category);
        } catch (Exception e) {
            message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Помилка",
                    "Π’ΠΈΠ½ΠΈΠΊΠ»Π° ΠΏΠΎΠΌΠΈΠ»ΠΊΠ° ΠΏΡ€ΠΈ ΠΏΠ΅Ρ€Π΅ΠΌΡ–Ρ‰Π΅Π½Π½Ρ–");
        }
        FacesContext.getCurrentInstance().addMessage(null, message);
    }

All 5 comments

be wonderful to see some API methods like this:

public void onDragDrop(DragDropEvent event) {
    List<Car> selectedCarsToMove = (List<Car>) event.getDragObject();
    TreeNode dropNodeCategory = (TreeNode) event.getDropObject();
}

for others people old link of discussions:
https://code.google.com/p/primefaces/issues/detail?id=1469
http://forum.primefaces.org/viewtopic.php?f=3&t=5952

on this moment I found only one workaround, but in my opinion this is bad way

<p:treeNode>
    <h:outputText id="selectedCategoryNode" value="#{node}" />
    <p:droppable for="selectedCategoryNode" scope="tabletotree"
    datasource="nomenclatureTable" activeStyleClass="ui-state-highlight" tolerance="touch">
        <p:ajax listener="#{catalogBean.onDragDropTree}" update="nomenclatureTable msgs"/>
        <f:attribute name="category" value="#{node}" />
    </p:droppable>
</p:treeNode>
<!-- <p:dataTable id="nomenclatureTable" -->
<p:column id="drag" style="width:20px">
    <h:outputText id="dragIcon" styleClass="ui-icon ui-icon-arrow-4" />
    <p:draggable for="dragIcon" scope="tabletotree" revert="true" helper="clone" />
</p:column>
    public void onDragDropTree(DragDropEvent event) {
        FacesMessage message;
        try {
            Nomenclature nomenclature = (Nomenclature) event.getData();
            Nomenclature category;

            if (event.getComponent().getAttributes().get("category") instanceof String) {
                category = new Nomenclature(0L, "НомСнклатура");
            } else {
                category = (Nomenclature) event.getComponent().getAttributes()
                        .get("category");
            }

            nomenclatureService.move(category, nomenclature);
            nomenclatureList = nomenclatureService.getNomenclature(parentId);
            message = new FacesMessage(FacesMessage.SEVERITY_INFO,
                    "ΠŸΠ΅Ρ€Π΅ΠΌΡ–Ρ‰Π΅Π½Π½Ρ", "НомСнклатура " + nomenclature
                            + " ΠΏΠ΅Ρ€Π΅ΠΌΡ–Ρ‰Π΅Π½Π° Π² ΠΊΠ°Ρ‚Π΅Π³ΠΎΡ€Ρ–ΡŽ " + category);
        } catch (Exception e) {
            message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Помилка",
                    "Π’ΠΈΠ½ΠΈΠΊΠ»Π° ΠΏΠΎΠΌΠΈΠ»ΠΊΠ° ΠΏΡ€ΠΈ ΠΏΠ΅Ρ€Π΅ΠΌΡ–Ρ‰Π΅Π½Π½Ρ–");
        }
        FacesContext.getCurrentInstance().addMessage(null, message);
    }

Will this feature be added/implemented anytime soon?

No plans but you can sponsor it via PrimeFaces Pro or provide a PR ;)

This issue is marked as stale because there was no activity on it for the last 2 years. Remove stale label or comment or this will be closed in 30 days

Was this page helpful?
0 / 5 - 0 ratings

Related issues

melloware picture melloware  Β·  5Comments

richmondspears picture richmondspears  Β·  5Comments

ghost picture ghost  Β·  3Comments

mertsincan picture mertsincan  Β·  4Comments

MatthiasScherrerFGCZ picture MatthiasScherrerFGCZ  Β·  4Comments