Reputation: 13910
I have a selectOneMenu like this:
<h:selectOneMenu class="form-control" value="#{beanBacking.pickedLongy}" id="foo" >
<f:selectItems value="#{beanBacking.thisTakesAwhile}"/>
</selectOneMenu>
to populate the items in the select one menu it takes a long time, and my page just hangs there while it is doing this.
I have tried:
<h:selectOneMenu class="form-control" value="#{beanBacking.pickedLongy}" id="foo" >
<f:ajax execute="@form" render="@none" />
<f:selectItems value="#{beanBacking.thisTakesAwhile}"/>
</selectOneMenu>
and it does not work either. Is there any way to load everything on the page and the items to load with ajax ?
Upvotes: 0
Views: 851
Reputation: 13910
I ended up pre-loading the data by creating an init() method annotated with @PostConstruct and performing the loading there. This way the data gets loaded when the bean is created and doesn't have to wait for a call from the page to be loaded.
private String longData;
public String getThisTakesAwhile(){
return someClass.getLongData();
}
private String longData;
public String getThisTakesAwhile(){
return longData;
}
@PostConstruct
private void init(){
longData = someClass.getLongData();
}
Upvotes: 1
Reputation: 582
You can have a deferred loading of your component. And then cache the component.
<p:outputPanel deferred="true">
<p:cache key="selectOneMenu">
<h:selectOneMenu class="form-control" value="#{beanBacking.pickedLongy}" id="foo" >
<f:selectItems value="#{beanBacking.thisTakesAwhile}"/>
</selectOneMenu>
</p:cache>
</p:outputPanel>
Deferred loading will ensure that the page is loaded and the processing of the
<f:selectItems value="#{beanBacking.thisTakesAwhile}"/>
will continue in the background and it will render up once the processing is completed.
For cacheing the component your can use
Upvotes: 0