Paweł Wójcik
Paweł Wójcik

Reputation: 133

reload data in p:dataTable at page reload

I have the simpliest version of primefaces' DataTable (without sorting, pagination etc.) and controller class which is responsible for providing data to html page. 'cars' is collection passed to p:datatable as value attribute:

<p:dataTable id="dtid" var="car" value="#{someController.cars}" />


@Named
@SessionScoped
public class SomeController {

  @Inject
  SomeService dataProvider;

  private Collection<Car> cars;

  @PostConstruct
  public void init() {
    cars = dataProvider.getCars();
  }

  public Collection<Car> getCars() { 
    return cars;
  }

I want to ensure that collection of cars in reloaded every time i hit "refresh" button on my webpage. init() method is invoked only once, while the page is being loaded for the first time. How to achieve this in the simpliest way? To make things clear: I do not want to change scope to @RequestScope or anything else.

Thanks in advance,

P.

Upvotes: 0

Views: 1252

Answers (1)

Nikola
Nikola

Reputation: 623

If you mean "F5", you could add preRenderViewEvent in f:event tag and set init method as listener? Altough i also don't understand why you use session scoped bean in first place and this is kinda hacky.

Upvotes: 1

Related Questions