JSF 2.0, Mojarra 2.0.1, PrimeFaces 3.4.1
There are similar questions but I need sth. else; javascript function has to wait for the backing bean method, which is filling the variable that wanted to be pulled from js function. What I want to say is:
<p:commandLink action="#{statusBean.getStatuses}" oncomplete="afterLoad()"/>
Assuming js function just getting the value and printing it to the screen.
function afterLoad() {
alert("#{statusBean.size}");
}
And here is the birthday kid:
@ManagedBean
@ViewScoped
public class StatusBean {
public int size=0;
List<Status> panelList = new ArrayList<Status>();
public void getStatuses() {
this.panelList = fillList();
this.size = panelList.size(); //Assuming 3
}
//getter and setters
}
So function alerts the size as 0 which is the initial value of it, while we're expecting to see 3.
How it's working: If I add the @PostConstruct
annotation to bean's head surely it gets the correct size, because bean is already constructed before the page load. But this means redundant processes, value just needed after the commandlink action. So how to postpone the js function? Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…