简体   繁体   English

如何使用带有十进制值的Primefaces滑块组件?

[英]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 . 我正在使用JSF 2.2Primefaces 4.0 ,我正在使用Primefaces slider组件。

<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. 我想问你是否有可能将step作为decimal值。 Eg step="0.1" , or perhaps some ideas about how to solve this issue. 例如step="0.1" ,或者也许是关于如何解决这个问题的一些想法。

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 由于大多数primefaces小部件都基于Jquery UI Widgets,因此从<p:slider>删除step属性并使用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 注意:此技巧适用于任何基于Jquery UI小部件的Primefaces小部件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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