I am using Primefaces Schedule and I am using which has a listener parameter of org.primefaces.event.DateSelectEvent
.
Based on whether DateSelectEvent.getDate is a weekeday or a weekend, I need to open a dialog box or just disable ajax (or don't do anything). For that I need to make a decision in the onpelete attribute of . I have gone as far as this:
<p:ajax event="dateSelect" listener="#{myBean.onDateSelect}" onplete="
if (onDateSelect.getDate == WeekDay) {
eventDialog.show()
} else {
myschedule.update()
}"
>
Well, obviously onDateSelect.getDate == Weekday
doesn't work and must be taken care of by a function on my backing bean, but how can I evaluate my backing bean method in JS function?
I am using Primefaces Schedule and I am using which has a listener parameter of org.primefaces.event.DateSelectEvent
.
Based on whether DateSelectEvent.getDate is a weekeday or a weekend, I need to open a dialog box or just disable ajax (or don't do anything). For that I need to make a decision in the onpelete attribute of . I have gone as far as this:
<p:ajax event="dateSelect" listener="#{myBean.onDateSelect}" onplete="
if (onDateSelect.getDate == WeekDay) {
eventDialog.show()
} else {
myschedule.update()
}"
>
Well, obviously onDateSelect.getDate == Weekday
doesn't work and must be taken care of by a function on my backing bean, but how can I evaluate my backing bean method in JS function?
3 Answers
Reset to default 2The onplete
attribute of PrimeFaces ponents doesn't support evaluating requestbased EL expressions. One of the ways is to use RequestContext#execute()
inside onDateSelect
listener method instead of a onplete
.
RequestContext requestContext = RequestContext.getCurrentInstance();
if (isWeekDay(onDateSelect.getDate())) {
requestContext.execute("eventDialog.show()");
} else {
requestContext.execute("myschedule.update()");
}
Another way is to ajax-update a <h:outputScript>
block containing the desired EL expressions.
<p:ajax event="dateSelect" listener="#{myBean.onDateSelect}" update="script" />
...
<h:panelGroup id="script">
<h:outputScript>
if (#{myBean.weekDaySelected}) {
eventDialog.show()
} else {
myschedule.update()
}
</h:outputScript>
</h:panelGroup>
As per the requirement you've mentioned I believe you are looking for something with which you can use a Javascript
function and invoke your backing bean method
to evaluate if its a weekday.
You can use Ajax4jsf's a4j:jsFunction
like:
<p:ajax event="dateSelect"
listener="#{myBean.onDateSelect}"
onplete="checkWeekDay"/>
<a4j:jsFunction name="checkWeekDay" action="#{beanName.methodName}"/>
You can use EL in the javascript mands too. So I assume you have method named isWeekDay similar to folowing, or just use your own function to determine whether the date is a week day or not:
public boolean isWeekDay()
{
Calendar c = Calendar.getInstance();
c.setTime(yourDate);
return c.get(Calendar.DAY_OF_WEEK) < 5;
}
<p:ajax event="dateSelect" listener="#{myBean.onDateSelect}" onplete="
if (#{yourBean.weekDay()}) {
eventDialog.show()
} else {
myschedule.update()
}"
>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745451031a4628268.html
评论列表(0条)