执行侦听器方法后调用Onstart

时间:2014-10-06 04:36:53

标签: ajax jsf primefaces

为什么在执行监听器方法后调用onstart? 在执行侦听器方法之前,我该怎么做才能调用onstart方法? 使用jsf 2.1和primefaces 4.0。

<p:ajax event="eventMove" listener="#{myBean.onEventMove}"
    update="mygrwlmsg" onstart="setLStorageDateToBean();"
    oncomplete="if(args.facesMessagesAvailable){handleEditEventRequest(args.eventList);scheduleWidget.update();}" />

通过remoteCommand调用bean方法

function setLStorageDateToBean()
{
    if(typeof(Storage)!=='undefined')
    {
        if((localStorage.startDate || localStorage.getItem('startDate') != null) 
            &amp;&amp; (localStorage.endDate || localStorage.getItem('endDate') != null))
        {
            var sDate = parseInt((localStorage.startDate)/1000);
            var eDate = parseInt((localStorage.endDate)/1000);
            var lCalRefresh = parseInt((localStorage.lastCalRefresh)/1000);

            setLocalStorageDate([{name:'startDate',value:sDate},{name:'endDate',value:eDate},{name:'lastCalRefresh',value:lCalRefresh}]);               
        }
    }
}

<p:remoteCommand name="setLocalStorageDate" actionListener="#{myBean.setDateFromLocaStorage}" >
</p:remoteCommand>

Bean方法

public void setDateFromLocaStorage()
{
    int startDate = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("startDate"));
    int endDate = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("endDate"));
    int lCalRefresh = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("lastCalRefresh"));

    setlStorStartDate(startDate);
    setlStorEndDate(endDate);
    setlStorLastRefresh(lCalRefresh);       
}

1 个答案:

答案 0 :(得分:3)

找到解决方案。 将ajax修改为(删除侦听器)

<p:ajax event="eventMove" 
    update="mygrwlmsg" onstart="callOnAjax();"
    oncomplete="if(args.facesMessagesAvailable)handleEditEventRequest(args.eventList); 
    scheduleWidget.update();}" />

创建一个新的remoteCommand组件

<p:remoteCommand name="myListener" actionListener="#{myBean.onEventMove}">
</p:remoteCommand>

创建了一个新的javascript函数

function callOnAjax(){
   setDateFromLocaStorage();
   myListener();
}