I'm using JSF 2.2 with primefaces. I have a primefaces datatables, i have program a method who's call when i click on a row, and this redirect me on a page with the data of the row.
The problem is: when i click on the row, i'm redirect to the good page, but if it's the first time i'm redirect, the program just ignore my @PostConstruct. But it's work for next time...
My datatable:
<p:contextMenu for="books">
<p:menuitem value="Détails" icon="ui-icon-search" actionListener="#{indexCtrl.showDetails()}"/>
</p:contextMenu>
<h2>Liste des bouquins de l'application <span style="font-weight:bold; color:#4592BE;">BookLib</span></h2>
<p:dataTable id="books" var="book" value="#{indexCtrl.books}" rowKey="#{book.ISBN}" selection="#{indexCtrl.selectedBook}" selectionMode="single">
<p:ajax event="rowSelect" listener="#{indexCtrl.showDetails}"/>
<p:column headerText="Title">
<h:outputText value="#{book.title}" />
</p:column>
<p:column headerText="Publish Date">
<h:outputText value="#{book.publish_date}" />
</p:column>
<p:column headerText="Pagination">
<h:outputText value="#{book.pagination}" />
</p:column>
<p:column headerText="image">
<p:graphicImage url="#{book.cover.small}" />
</p:column>
</p:dataTable>
My ShowDetail method:
public void showDetails() throws IOException{
Faces.setFlashAttribute("bookToView", selectedBook);
String url = "details.xhtml";
FacesContext.getCurrentInstance().getExternalContext().redirect(url);
}
My PostConstruct for detailsCtrl:
@PostConstruct
public void init(){
setBookToView((Book)Faces.getFlashAttribute("bookToView"));
this.constructAuthorsString();
}
ALl my beans are in ViewScoped.