我有两个同一形式的日历,都是rich:calendar
。一个是开始日期(或激活日期),另一个是结束日期(或停用日期)。
我想要实现的是在结束日期日历中标记选定的开始日期。
例如:
7月14日(红色)是开始日期,7月16日是当前选定的结束日期。
我的问题似乎是,我无法通过JQuery获得开始日期的价值。我尝试在页面的某个地方“隐藏”这个值,这样我就可以使用$('#myForm\\:hiddenActivationDate').val();
来访问它,它几乎可以工作......但是其他一切都停止了工作。
这些是我写的脚本函数:
var currentDate = new Date();
function activationDateDisablementFunction(day) {
return currentDate.getDate() <= day.date.getDate();
}
function activationDateClassProv(day) {
if (currentDate.getDate() > day.date.getDate()) {
return "disabledDay";
}
}
function deactivationDateDisablementFunction(day) {
var hiddenActivationDate = $('#myForm\\:hiddenActivationDate').val();
var activationDate = new Date(Date.parse(hiddenActivationDate));
return day.date.getDate() >= activationDate.getDate(); // true = enabled, false =disabled
}
function deactivationDateClassProv(day) {
var hiddenActivationDate = $('#myForm\\:hiddenActivationDate').val();
var activationDate = new Date(Date.parse(hiddenActivationDate));
if (day.date.getDate() < activationDate.getDate()) {
return "disabledDay";
}
if (day.date.getDate() === activationDate.getDate()) {
return "activatedDay";
}
}
这里有两个日历:
<!-- start date -->
<a4j:outputPanel id="activationDateCalendar" layout="block" >
<rich:calendar value="#{myBean.activationDate}"
popup="true"
datePattern="#{myBean.dateFormat}"
boundaryDatesMode="scroll"
jointPoint="bottomAuto"
showWeeksBar="false"
showApplyButton="false"
dayClassFunction="activationDateClassProv"
dayDisableFunction="activationDateDisablementFunction"
style="width:320px">
<a4j:ajax render="@this, hiddenActivationDate, deactivationDateCalendar, activationDatePreview, deactivationDatePreview, durationPreview" />
</rich:calendar>
</a4j:outputPanel>
<!-- my hidden date -->
<h:inputHidden id="hiddenActivationDate" value="#{myBean.activationDate}" />
<!-- end date -->
<a4j:outputPanel id="deactivationDateCalendar" layout="block" >
<rich:calendar value="#{myBean.deactivationDate}"
popup="true"
datePattern="#{myBean.dateFormat}"
boundaryDatesMode="scroll"
jointPoint="bottomAuto"
showWeeksBar="false"
showApplyButton="false"
dayClassFunction="activationDateClassProv"
dayDisableFunction="activationDateDisablementFunction"
style="width:320px">
<a4j:ajax render="@this, activationDatePreview, deactivationDatePreview, durationPreview" />
</rich:calendar>
</a4j:outputPanel>
简而言之
我想要做的是直接从JQuery函数deactivationDateClassProv
中访问开始日期值,而不从隐藏字段中获取它。
这可能吗?或者是否有“Richfaces方式”?
答案 0 :(得分:3)
RichFaces组件有一个JS API,请阅读docs。
在您的情况下,您只需通过以下方式访问日期:
function deactivationDateClassProv(day) {
var hiddenActivationDate = #{rich:component('firstCalendarId')}.getValue();
…
}
请注意,该功能仅在需要时调用,如果您只是关闭并打开日历,则不会再次调用它(除非您切换月份或将isRendered
设置为false)。