JSF preload list for datatable in page [duplicate]
I'm using EJB and JSF. I made a jsp simple page with a button "get list". When it's clicked, a managed bean method is called that sets the list, which is then displayed in the jsp with the dataTable tag.
The question is, how can I pre load this list/dataTable on page load without having to click the button?
This is the method that's called through the button action on the jsp:
public String retrieveList() {
items = facade.getAllItem();
return "";
}
this is the part of the jsp:
<h:dataTable value="#{mybean.items}" var="sup"
binding="#{mybean.dataTable}"
rowClasses="oddRow, evenRow"
styleClass="tableStyle"
headerClass="tableHeader"
columnClasses="column1, c开发者_开发问答olumn2, column1, column1, column1, column1">
You can add a method init with @postConstruct
@PostConstruct
public void init(){
items = facade.getAllItem();
}
This will return the items only on bean creation ,
Annotate the method with @PostConstruct
and get rid of return value.
@PostConstruct
public void retrieveList() {
items = facade.getAllItem();
}
This way the method will be executed immediately after construction of the bean and injection of all @EJB
dependencies. In the JSF page you just have to bind to #{bean.items}
the usual way.
精彩评论