我需要显示一个更改日期的滑块,并在标签中显示所选日期。 此滑块应具有开始和结束日期,因此用户只能在两者之间进行更改,并且只需一天的步骤。
<h:outputText value="Selected Date: " />
<h:outputText id="output" value="#{myBean.sliderValue}" >
<f:convertDateTime type="date" pattern="#{myBean.dateTimeFormatSeconds}"/>
</h:outputText>
<h:inputHidden id="hiddenDateSliderValue" value="#{myBean.sliderValue}" />
<p:slider for="hiddenDateSliderValue" min="#{myBean.sliderMinValue}" max="#{myBean.sliderMaxValue}" step="#{myBean.sliderStepValue}">
<p:ajax event="slideEnd" listener="#{myBean.onSlideEnd}" />
</p:slider>
我编写的代码很简单,但只适用于int值。有谁知道如何使用p:slider的long或Date值?我写的代码很简单,但只适用于int值。有没有人知道如何使用长或日期值与p:slider?
public void onSlideEnd(SlideEndEvent event) {
event.getValue();
//The above code returns int, I need long or Date so one of the lines below may work.
//Date theDate = event.getValue();
//Date theDate = new Date(event.getValue());
}
有什么想法吗?
答案 0 :(得分:-2)
我用了这个(没有日期可走,对不起)。如下所述,这是针对PrimeNg,而不是Primefaces。 javascript应该仍然可以工作:
<p-slider [(ngModel)]="cursornum" [min]="cursormin" [max]="cursormax" (onChange)="cursorChange($event)" [style]="{'width':'100%'}" ></p-slider>
和
this.cursormin = new Date().getTime(); //get milliseconds for slider min
this.cursormax = new Date(y, m, d).getTime();//get milliseconds for slider max
this.cursornum = new Date(n.getFullYear(), m + 3, d).getTime();//get milliseconds for slider cursor three months from now
具有:
cursorChange(e) {
this.cursornum = e.value; //get new milliseconds
this.cursor = new Date(e.value).toDateString(); //convert to date and show as string
}