tags:

views:

39

answers:

2

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, column2, column1, column1, column1, column1">
+1  A: 

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.

BalusC
thankyou awesome!
Jojje
You're welcome. Don't forget to mark the most helpful answer to accepted. See also http://stackoverflow.com/faq.
BalusC
+3  A: 

You can add a method init with @postConstruct

@PostConstruct
public void init(){
  items = facade.getAllItem();
}

This will return the items only on bean creation ,

Odelya