Primefaces: How to persist reordered data from a p:orderList?

不想你离开。 提交于 2021-01-28 04:07:20

问题


I am still working on with the primefaces component p:orderlist. I have managed to implement a drag and drop behaviour (to put items from another list in to the p:orderlist) and I also make the p:commandButton work inside the p:orderlist.

Now I have a new problem. You can drag and drop items inside the p:order list, to give them a new order. (That is, why the component is called orderlist, nothing to do with a shopping order ;-) ).

But if I reorder my items I get no notification or event, which tells my bean, that something was changed.

Has anybody an idea how to make this possible?

Here is my p:orderlist, like it looks know:

 <h:panelGroup>

           <p:remoteCommand name="removeTechniker" actionListener="#{systemlandschaftRessourceHandler.removeTechnikerByRemoteCommand}"
                     out="technikersTable" update="@form"/>

           <p:orderList id="technikersTable"
                        value="#{systemlandschaftRessourceHandler.entity.technikers}" 
                        var="_techniker"  
                        itemValue="#{_techniker}" 
                        converter="#{entityConverter}"
                        controlsLocation="none">  

                <f:facet name="caption">Techniker</f:facet>  

                <p:column>    
                    <p:commandButton id="deleteTechnikerFromListButton" 
                                    styleClass="colButton" 
                                    icon="ui-icon-trash" 
                                    type="button" 
                                    onclick="removeTechniker([{name:'id', value:'#{_techniker.id}'}]);"
                                    update="@form"/>
                </p:column>
                <p:column style="width:75%;" id="outTech">  
                   <p:outputLabel value="#{_techniker.verantwortlich.displayName}"/>
                </p:column>

            </p:orderList>

            <p:droppable id="technikerDrop" 
                        for="technikersTable" 
                        tolerance="touch" 
                        activeStyleClass="ui-state-highlight" 
                        datasource=":systemLandschaftTabView:sysObjektDetailPanelForm:userTable" 
                        scope="userDraggable">  
                    <p:ajax listener="#{systemlandschaftRessourceHandler.onDropTechniker}" update="@form" />  
            </p:droppable>  
            </h:panelGroup>

I already found something on the primefaces community, but this doesn't work, can' even say why. Link: http://forum.primefaces.org/viewtopic.php?f=3&t=26539

Regards LStrike

Just for info, here are my solved items, regarding the p:orderlist:

Primefaces: CommandButton inside Orderlist not working

and

Primefaces: Orderlist: index out of bound exception while reordering


回答1:


Figured out a solution myself. It's some kind of hack, but it works. I use the setter of the list, I want to have sorted and send it to the database. For reading the list I use the @OrderBy annotation on the getter.

@OrderBy("ranking ASC")
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name="MWEB_SYSLAND_RES_ENTWUSER_L", joinColumns = {@JoinColumn(name = "ID_SYSLAND_RES", nullable = false, updatable = false)} ,inverseJoinColumns = { @JoinColumn(name ="ID_SYSLAND_USER", nullable = false, updatable = false) })
    public List<SystemlandschaftUser> getEntwicklers() {
        return entwicklers;
    }

    public void setEntwicklers(List<SystemlandschaftUser> entwicklers) {
        this.entwicklers = sortSysUserList(entwicklers);

@Transient
    private List<SystemlandschaftUser> sortSysUserList(List<SystemlandschaftUser> input){
        if(input != null && input.size() > 0){
            for(int i=1, size=input.size(); i <= size; i++){
                SystemlandschaftUser t = input.get(i-1);
                t.setRanking(i);
            }
        }
        return input;
    }


来源:https://stackoverflow.com/questions/19443356/primefaces-how-to-persist-reordered-data-from-a-porderlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!