Eddie Martinez
Eddie Martinez

Reputation: 13910

AJAX JSF selectItems in selectOneMenu

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

Answers (2)

Eddie Martinez
Eddie Martinez

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.

BEFORE:


private String longData;   


    public String getThisTakesAwhile(){

        return someClass.getLongData();

  }


NOW:

private String longData; 


    public String getThisTakesAwhile(){

    return longData;
    }


    @PostConstruct
    private void init(){

    longData = someClass.getLongData();
    }

Upvotes: 1

BholaVishwakarma
BholaVishwakarma

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

  1. Primefaces Cache
  2. Omnifaces Cache

Upvotes: 0

Related Questions