1

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

Quentin T.
  • 267
  • 2
  • 8
  • 27
  • 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 Mar 23 '15 at 17:06
  • It's true, sorry for the confusing. I've edited the question. – Quentin T. Mar 24 '15 at 06:47
  • 1
    The code is incomplete, so it's a bit hard to pinpoint the exact cause (a [MCVE](http://stackoverflow.com/help/mcve) would help more), but this should work if you have set `` on a `@ViewScoped` bean property and the delete action method returns `null` or `void`. – BalusC Mar 24 '15 at 06:52
  • As per your edit: this code is still incomplete. Please click the MCVE link and carefully read it. The code which you have edited in the question appears to be working code for PF 4.0, not problematic code for PF 5.1. Moreover, I tried to reproduce it with simplest possible example based on the information provided so far on a blank playground project with everything set to default. However, it works just fine for me. – BalusC Mar 24 '15 at 09:00
  • As per your second edit: Sorry, this all still works for me. I'd bet it's just a design mistake somewhere in the code not visible in the information provided so far. Perhaps the `@SessionScoped` is from the wrong package. Perhaps you're performing business logic in a getter method. Etc. A true MCVE would quickly have nailed down that by just a glance over the code snippet by an expert. – BalusC Mar 24 '15 at 09:31
  • I'm doing it as MCVE soon. – Quentin T. Mar 24 '15 at 11:37
  • Here we go, MVCE done, but I have another strange error with filter. – Quentin T. Mar 25 '15 at 12:24
  • Sorry, this still works just fine for me (when "obviously" placed in a ``, which was missing in your MCVE). The filter works and after delete I get the empty table message. I used PF 5.1 + Mojarra 2.2.10 + Tomcat 8.0.18. Perhaps you didn't test in a completely blank project? Perhaps you extended a template which in turn contained the root mistake (e.g. duplicate manual inclusion of jQuery or something else causing a JS error)? Perhaps you've added some non-default context params to `web.xml`? – BalusC Mar 25 '15 at 12:53
  • Ok so I'm not mad, it's a good news ! ^^ (thanks for the form, it's working too for me for the 1st issue : the 2nd issue still the same). I don't test in a blank project. My Config : PF5.1 + Mojarra 2.0.1-FCS + Tomcat 7.0.56 + Java 1.6 – Quentin T. Mar 25 '15 at 12:56
  • 1
    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 Mar 25 '15 at 12:56
  • Is it possible to update to 2.2.10 directly ? Or the max version for my config is 2.1.29 ? – Quentin T. Mar 25 '15 at 13:10
  • Yes, but that would possibly require changes in existing PrimeFaces code and config, namely JSF 2.2 ships with among others native file upload support which is detected by PrimeFaces and it could behave differently. – BalusC Mar 25 '15 at 13:20
  • Excuse me, but where can I find an example of j2ee project configuration like your ? My biggest problem here is always with configuration because I work with an old project configuration (not mine) and it's totally a mess (to be very polite)... (as you can see in my new edit on the last picutre...). I work on a full portable environnement : portable JRE (OpenSDK Portable), portable Tomcat 7.0.56, ... That why I have a lof of conflict now with the configuration (can't use maven, or install anything). – Quentin T. Mar 25 '15 at 14:04
  • 1
    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 Mar 25 '15 at 14:11
  • Done, it's working, I've update : PF5.1 to PF 5.2 RC & Mojarra 2.0.1-FCS to Mojarra 2.2.10 & Tomcat 7.0.56 to Tomcat 8.0 & Java 1.6 to Java 1.7 (JPortable 1.7) & Eclipse Juno to Eclipse Luna (Portable edition 4.4). And now my project has just 5 librairies jstl, jstl-api, jsf-api, jsf-impl, primefaces. I pretty sure that the Mojarra was deprecated. You can post the answer now. – Quentin T. Mar 26 '15 at 08:44

1 Answers1

3

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555