p:dataTable sorting/filtering not working

UI Components for JSF
Post Reply
Franke
Posts: 49
Joined: 12 Oct 2010, 08:41

21 Jun 2011, 10:15

I'm having issues with ajax sorting and filtering, without any fancy lazy loading or pagination or anything of that sort. Nothing happens when I try to sort or filter, though my ajax loader icon flashes for a split second.

Markup:

Code: Select all

<h:form>
  <p:dataTable value="#{userController.users}" var="user" >
    <p:column headerText="Login" sortBy="#{user.login}">
      #{user.login}
    </p:column>
  </p:dataTable>
</h:form>
userController.java

Code: Select all

@Named
@ViewScoped
public class UserController implements Serializable{
    private static final long serialVersionUID = 1;

    @Inject SessionController sessionController;
    @Inject UserBean userBean;
    private List<User> users;
    
    public UserController() {
    }

    public List<User> getUsers() {
        if(users == null)
            users = userBean.findAllUsers();
        return users;
    } 
   
}
userBean should be irrelevant. The login field of entity User is a normal String with proper get/set. Using PF 2.2.1 with CDI, seam faces, seam solder on Jboss 6.

Any idea of what can cause this? No javascript error occurs. I've used sorting without problem in earlier projects (without CDI and seam though, and using glassfish instead of jboss). I tried switching to the old @ManagedBean instead, without success.
Using PF 3.0 with default JSF implementation of JBoss 6

User avatar
mediterran81
Posts: 29
Joined: 22 Mar 2011, 12:14
Location: France
Contact:

25 Jun 2011, 18:30

Same problem here! Did you find a solution!??

kumm
Posts: 7
Joined: 21 Nov 2010, 21:07

26 Jun 2011, 12:13

I've run into this issue too several times.
Checklist :
- is your controller at least ViewScoped?
@ViewScoped, @SessionScoped, or @ApplicationScoped are good choices.

- do you return the same list object reference across requests? It's a problem if you always create a new list for the "value" binding.
The right controller pattern for <p:dataTable value="#{customerController.all}> :

Code: Select all

    private List<Customer> all;
    public List<Customer> getAll() {
        if (all==null) {
            all = customerService.findAll();
        }
        return all;
    }
- as of some point (the big p:ajax refactoring) in M2-SNAPSHOT the value binding of the rendered property breaks sorting, filtering.
I will report this bug when M2 released.
Until it's fixed don't use <p:dataTable rendered="#{...}"...>

Franke
Posts: 49
Joined: 12 Oct 2010, 08:41

28 Jun 2011, 09:01

Ah! Just noticed that the cases where sorting doesn't work, I forgot the normal pattern of using a cache in the managed bean. Thanks!

"rendered" in datatables still works for me though.
Using PF 3.0 with default JSF implementation of JBoss 6

User avatar
mediterran81
Posts: 29
Joined: 22 Mar 2011, 12:14
Location: France
Contact:

28 Jun 2011, 22:36

Actually Sorting/Filtering do not work when using ListDataModel in the managed bean.

But what about the cache?.

Could you please supply a snippet that shows how you used Cache in your managed bean as this seems to enable sorting for you.
Thanks!

scorpioleo
Posts: 5
Joined: 28 Jun 2011, 17:10

28 Jun 2011, 23:44

the CDI @Named don't work with @ViewScoped, instead with @ManagedBean

for @ManagedBean (javax.faces.bean.ManagedBean not javax.annotation.ManagedBean)
@ViewScoped @SessionScoped @RequestScoped @ApplicationScoped @CustomScoped

@Named
@SessionScoped @RequestScoped @ApplicationScoped @ConversationScoped

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 47 guests