0

我实现了freedays的延迟加载数据。当我需要加载更多数据时使用 remoteCommand 时,我的变量仍然具有初始值。我什至在加载函数中打印数据,它打印正确,但函数完成后,值从 init 回滚到旧值,没有任何消息或错误。代码:

@SessionScoped
@Named 
public class CalendarBean implements Serializable {
    private static String freeDays; //it should be static ?? without static the init func dont update there data. 

    public  String getFreeDays() {
         return freeDays;
    }

    public  void setFreeDays(String freeDayss) {
        this.freeDays= freeDayss;
    }

    public void loadDataFromDB(){
         freeDays=freeDays+//DB query with more data lazyloading
         ...
         System.out.print(freeDays); // it prints updated value with more object, but when the functions finish and I print CalendarBean.freeDays in Jscript it haves value from the init ...
    }

    public void initDays(){
         freeDays=//DB query
    }
}

.xhtml

<h:inputHidden id="hiddenButton2" value="#{CalendarBean.freeDays}"/>
<p:remoteCommand name="updateDaysJS" actionListener="#{CalendarBean.loadDataFromDB()}"/> //on default it is asynchronous i supose

Javascript

jQuery(document).ready(function() {
    #{CalendarBean.initDays()}
});
someFunction(){
    updateDaysJS();//this func triggered when i need more data of days
    //i ve tried also document.getElementById('MyForm:hiddenButton2').value = updateDaysJS(); but still not works(i ve changed ofc return type etc when i used this one
}
4

0 回答 0