简体   繁体   中英

How to use Primefaces slider component with decimal values?

I am using JSF 2.2 , Primefaces 4.0 , and I am using slider component from Primefaces .

<p:slider displayTemplate="Between {min} and {max}" minValue="20" maxValue="40" step="1"/>

I would like to ask you if is possibile to have step as decimal value. Eg step="0.1" , or perhaps some ideas about how to solve this issue.

I have tried but I'm getting errors like :

javax.el.ELException: Cannot convert 0.1 of type class java.lang.String to int] with root cause

Thank you.

As most of the primefaces widgets are based on Jquery UI Widgets,so remove step attribute from <p:slider> and pass it with Jquery

<p:slider id="slder" displayTemplate="Between {min} and {max}" minValue="20" 
          maxValue="40" />

Script to manipulate this

       $(window).load(function(){  // should be  $(window).load to load widget
            $('#slder').slider({
                   step: 0.1
                  });
        });

NOTE : This trick works for any Primefaces widget which is based on Jquery UI widget

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM