Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces Slider does not call setter

Tags:

primefaces

I have a primefaces (version 3.4.2) slider and an inputText for output value of the slider value. The problem is that a change of the slider update the displayed value of the inputText, but the setter bind to the inputText is not called.

Here is my slider:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:a4j="http://richfaces.org/a4j">

    <h:head>
        <title>Zinsrechner</title>
    </h:head>

    <h:body>

        <h:form>
            <h:panelGrid columns="1" style="margin-bottom:10px">
                <p:inputText id="x" value="#{zinsrechner.monatlicherBeitrag}" />
                <p:slider minValue="0" maxValue="150" for="x" />
            </h:panelGrid>
        </h:form>

    </h:body>

</html>

And this is my Setter, which is NOT called:

public void setMonatlicherBeitrag( Double beitrag ) {
    monatlicherBeitrag = beitrag;
}

The Getter IS called:

public Double getMonatlicherBeitrag() {
    return GuiParameter.getSpareinlageProMonat();
} 
like image 289
Karina Avatar asked Nov 22 '12 11:11

Karina


2 Answers

Adding a <p:ajax> inside your Slider will to the trick.

Example:

<p:slider minValue="0" maxValue="150" for="x">
    <p:ajax event="slideEnd" process="x" />
</p:slider>
like image 146
Patrick Trautmann Avatar answered Sep 20 '22 23:09

Patrick Trautmann


I was facing the same problem, but in my case the thing was that I was setting the <p:inputNumber .../> label as read only. I removed that attribute and everything worked.

like image 45
Julio Avatar answered Sep 19 '22 23:09

Julio