[英]Changing calendar value by input - Prime Faces
I have own calendar in label: 我在标签中有自己的日历:
<cust:customField label="test" forId="calendarId">
<p:calendar id="calendarId"
value etc...
pattern="yyyy-MM-dd HH:mm:ss"
mask="true"
styleClass="ui-inputdate"
readonlyInput="true"
locale="pl"
required="true"
</p:calendar>
</cust:customField>
under that I have input: 在此我输入:
<h:panelGroup>
<p:inputText id="newHour">
<p:ajax event="change" update="calendarId"/>
</p:inputText>
<h:outputText value="h"/>
</h:panelGroup>
I try to make that if anyone send value to "newHour" it would be update "HH" value in "calendarId". 我试图使如果有人将值发送到“ newHour”,则它将更新“ calendarId”中的“ HH”值。 Is that possible? 那可能吗?
.xhtml: .xhtml:
<p:inputText id="newHour" value="#{myBean.hours}>
<p:ajax listener="#{myBean.changeHours()}" update="calendarId"/>
</p:inputText>
myBean: myBean:
private int hours;
private Date date;
public void changeHours(){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, hours);
date = calendar.getTime();
}
//getter + setter
Note that date.setHours() would also work instead of using an extra calendar, but the constructor is deprecated because of some issues with internationalization. 请注意,date.setHours()也可以使用而不是使用额外的日历,但是由于国际化的一些问题,不建议使用构造函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.