我想使用带有十进制值的' InputText Slider'来自我的JSF2.2页面中的Primefaces.org,如下所示:
slider.xhtml
<h:panelGrid columns="1" style="margin-bottom: 10px">
<p:inputText id="decimal" value="#{sliderView.number2}" />
<p:slider for="decimal" minValue="0.2" maxValue="7.1" step="0.1" />
</h:panelGrid>
和SliderView.java类:
import javax.faces.bean.ManagedBean;
@ManagedBean
public class SliderView {
private float number2;
public float getNumber2() {
return number2;
}
public void setNumber2(float number2) {
this.number2 = number2;
}
}
在这种情况下,它会抛出javax.el.ELException: Cannot convert [0.2] of type [class java.lang.String] to [int]
。
即使我将minValue
,maxValue
和step
的值更改为托管bean(例如#{sliderView.min}
,#{sliderView.max}
和#{sliderView.step}
)它产生整数结果:
slider.xhtml
<h:panelGrid columns="1" style="margin-bottom: 10px">
<p:inputText id="decimal" value="#{sliderView.number2}" />
<p:slider for="decimal" minValue="#{sliderView.min}" maxValue="#
{sliderView.max}" step="#{sliderView.step}" />
</h:panelGrid>
SliderView.java类:
import javax.faces.bean.ManagedBean;
@ManagedBean
public class SliderView {
private float min = 0.2f;
private float max = 7.1f;
private float step = 0.1f;
private float number2;
public float getMin() {
return min;
}
public void setMin(float min) {
this.min = min;
}
public float getMax() {
return max;
}
public void setMax(float max) {
this.max = max;
}
public float getStep() {
return step;
}
public void setStep(float step) {
this.step = step;
}
public float getNumber2() {
return number2;
}
public void setNumber2(float number2) {
this.number2 = number2;
}
}
似乎未正确支持float或double值。 据我所知,Primefaces Tag Documentation slider标签仅支持Integer值。但是为什么他们在ShowCase中给出了如此奇怪的代码示例?