1
votes

I'm updating my web application to PF5.1 (was in PF4.0)

A simple update on the <p:dataTable> component now destroy totally my datatable FILTER.

update=":#{p:component('tbl_queue')}"

I had to change my column filter because of the new PF5.1 version, so I modified my filters with :

<f:facet name="filter"  >
    <p:selectOneMenu ... >
        <f:selectItem ... />
        <f:selectItems ... />
    </p:selectOneMenu>
</f:facet>

And the old filters version was :

<p:column id="..." 
    filterBy=...
    filterOptions="..."
    filterMatchMode="exact"
>
...
</p:column>

EDIT : My request is simple, it's to do a remove on a filtered datatable by selection (and to keep the filter alive). It was possible on PF4.0, it seems not of PF5.

Like that :

Step 1 : Filter the datatable

enter image description here

Step 2 : Remove one line by clicking 'Envoyer' = Remove (J91GT N9 03:17:00)

enter image description here

It's working fine on PF4, but I can't find a solution to do the same in PF5. EDIT 2:

  <p:dataTable id="tbl_queue" var="c"
    value="#{queueModificationController.cartQueue}" 
    widgetVar="queueTable"
    filteredValue="#{queueModificationController.filteredCartQueue}"
    rowKey = "#{c.id}"
>
    <p:column 
        id="Bumper_column" 
        filterBy="#{c.name_bumper}"
        headerText="Bumper"
        filterMatchMode="exact"
    >
     <f:facet name="filter" >
        <p:selectOneMenu onchange="PF('queueTable').filter()" id="selectFilterBumper" >
            <f:selectItem itemLabel="Aucun" itemValue="#{null}" noSelectionOption="true" />
            <f:selectItems value="#{queueModificationController.nameBumperOptionsString}" />
        </p:selectOneMenu>
    </f:facet>
                <h:outputText value="#{c.name_bumper}" />
    </p:column>
    <p:column>
        //...
    </p:column>
        //...
        //...

    <p:column id="validation_column" 
    headerText="Validation">
        <p:commandButton
            action="#{productionQueue.updateAfterSending()}"
            value="Validation"
            update=":#{p:component('tbl_queue')}"
            <f:setPropertyActionListener value="#{c}"
                target="#{productionQueue.selectedCart}" />
        </p:commandButton>
</p:column>
</p:dataTable>

--

@ManagedBean(name = "productionQueue")
@SessionScoped
private ArrayList<CartInQueueConsult> cartQueue; //filled by Database in bean initialisation
private ArrayList<CartInQueueConsult> filteredCartQueue = new ArrayList<CartInQueueConsult>(cartQueue);

        public void updateAfterSending()
        {
            ... (remove in database)
            filteredCartQueue.remove(selectedCart);
            cartQueue.remove(selectedCart);
        }

EDIT : MCVE Example of the error :

Errors : - 1: The filter is not working (strange thing because all of my filters are working properly on no-MVCE example - 2: When you remove a Line with the button "Remove" the Filters are broken (my initial problem)

import java.io.Serializable;
import java.util.ArrayList;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.SelectItem;


@ManagedBean(name = "testController")
@ViewScoped
public class TestController implements Serializable
{
    private ArrayList<String> cartQueue; 

    private String selectedCart;

    private ArrayList<String> filteredCartQueue;

    private SelectItem nameBumperOptionsString[] = {new SelectItem(1,"1"),new SelectItem(2,"2"),new SelectItem(3,"3"),new SelectItem(4,"4"),new SelectItem(5,"5")};

    @PostConstruct
    public void initialize()
    {
        cartQueue = new ArrayList<String>();
        cartQueue.add("1");
        cartQueue.add("2");
        cartQueue.add("3");
        cartQueue.add("4");
        cartQueue.add("5");
        cartQueue.add("6");
        filteredCartQueue = cartQueue;
    }

    public void remove()
    {
        try
        {
            filteredCartQueue.remove(selectedCart);
            cartQueue.remove(selectedCart);
        }
        catch (Exception ex)
        {
            System.out.println("EXCEPTION : "+ ex.getMessage());
        }
    }

    public ArrayList<String> getFilteredCartQueue() {
        return filteredCartQueue;
    }

    public void setFilteredCartQueue(ArrayList<String> filteredCartQueue) {
        this.filteredCartQueue = filteredCartQueue;
    }

    public SelectItem[] getNameBumperOptionsString() {
        return nameBumperOptionsString;
    }

    public void setNameBumperOptionsString(SelectItem nameBumperOptionsString[]) {
        this.nameBumperOptionsString = nameBumperOptionsString;
    }

    public ArrayList<String> getCartQueue() {
        return cartQueue;
    }

    public void setCartQueue(ArrayList<String> cartQueue) {
        this.cartQueue = cartQueue;
    }

    public String getSelectedCart() {
        return selectedCart;
    }

    public void setSelectedCart(String selectedCart) {
        this.selectedCart = selectedCart;
    }
}

_

   <p:dataTable 
    id="test_queue" var="c"
    value="#{testController.cartQueue}" widgetVar="testTable"
    emptyMessage="Pas de file d'attente" 
    filteredValue="#{testController.filteredCartQueue}"
    paginator="true" 
    currentPageReportTemplate="Nb Rows : {totalRecords}"
    paginatorTemplate="{CurrentPageReport}" 
    >
        <p:column id="number_column" 
        filterBy="#{c}"
        headerText="Number"
        filterMatchMode="exact"
        >
       <f:facet name="filter"  >
            <p:selectOneMenu onchange="PF('testTable').filter()" >
                <f:selectItem itemLabel="Nothing" itemValue="#{null}" noSelectionOption="true" />
                <f:selectItems value="#{testController.nameBumperOptionsString}" />
            </p:selectOneMenu>
        </f:facet>
        <center>
            <h:outputText value="#{c}" />
        </center>
    </p:column>
    <p:column headerText="Remove">
        <center>
            <p:commandButton
                action="#{testController.remove()}"
                value="Remove"
                update="test_queue" >

                <f:setPropertyActionListener value="#{c}" target="#{testController.selectedCart}" />

            </p:commandButton>
        </center>
    </p:column>
</p:dataTable>

--

EDIT 3 : Lib :

enter image description here

1
Your question is confusing. At first sight it looks like that you already have solved the problem and are merely asking why PrimeFaces guys decided to change from approach X to approach Y. If you're really asking like that, you should be asking that directly to PrimeFaces guys. If not, please reframe your question to ask about the actual technical problem. - BalusC
It's true, sorry for the confusing. I've edited the question. - Quentin T.
The code is incomplete, so it's a bit hard to pinpoint the exact cause (a MCVE would help more), but this should work if you have set <p:dataTable filteredValue> on a @ViewScoped bean property and the delete action method returns null or void. - BalusC
Mojarra 2.0.1? Really? This is over 5 years old and bug ridden. It's currently already at 2.1.29. Give it a try. Moreover, JSF 2.2 should even work on your config. - BalusC
The libs is indeed a mess .. Servletcontainer specific libs don't belong in webapp's /WEB-INF/lib. You should remove from /WEB-INF/lib at least javaee-* JARs and all JARs which are already present in Servletcontainer's (in your case Tomcat's) own /lib folder such as catalina-*, tomcat-*, jasper-*, servlet-*, jsp-* and el-*. I myself have in my test project only JSF, JSTL and PrimeFaces libs. - BalusC

1 Answers

3
votes

Your code looked fine and it worked fine for me too. I was never able to reproduce your problem and therefore I was not able to pinpoint the true root cause.

Your concrete problem is most likely caused by having a dirty runtime classpath with a bunch of servletcontainer specific libraries (never do that!) and a heavily outdated JSF implementation (more than 5 years old). And indeed, when you cleaned up the runtime classpath and upgraded the JSF implementation, it worked fine for you too.