0
votes

I have a little problem with PrimeFaces, I am trying to add an event listener to colReorder event but when I add this the whole stuff fails with Uncaught SyntaxError: Unexpected token.

The code looks like this:

<p:dataTable
   width="100%" 
   value="#{myBean.getItems()}"
   var="item"
   id="resultList"
   draggableColumns="true"
>
<p:ajax event="colReorder" listener="#{myController.onColumnReorder}" />

...

And the backing bean:

@Named
@RequestScoped
public class MyController implements Serializable{

    public void onColumReorder(ReorderEvent event) {
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Row Moved", "From: " + event.getFromIndex() + ", To:" + event.getToIndex());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
}

The strange is that if I remove the p:ajax everything works fine I can change the columns.

Any idea, is it a known bug or I am missing something?

To avoid confusion getItems looks like this in a sessionscoped bean:

@Named
@SessionScoped
   public class MyBean extends DataModel<E> implements Serializable {
   private List<E> items;

   ...

  public List<E> getItems () {
  return items;
}
1
If you are getting a list of items (rows from the associated data-store) through a getter method in the corresponding bean as implied by value="#{myBean.getItems()}" then, please stop doing it and do the same thing in its own place such as a method annotated with @PostConstruct.Tiny
This getter is not a simple getter I cant really modify thaterik.c
Getters should be simple by design. If you can't modify that one add another one and use that which e.g. calls the other getter in a lazy wayKukeltje
Ok I was not correct, the getter itself simply returns a List from a sessionScoped Bean ( which is a jsf2 DataModel) so it is pretty simple it does not do any kind of magic. I added this part to the desciprtionerik.c

1 Answers

0
votes

Actually org.primefaces.event.ReorderEvent seems not to be allowed for column reordering but only for row reordering. You should use an AjaxBehaviorEvent as parameter of your method like :

public void onColumReorder(AjaxBehaviorEvent event) {

}