admin管理员组文章数量:1425786
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()
}"
>
版权声明:本文标题:jsf 2 - Calling a Bean Function in a JavaScript if statement for eveluating Primefaces object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745451031a2658884.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论