0

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.

Persilos
  • 72
  • 1
  • 15
  • Hey, can you also share your details page? What does program ignore PostConstruct method mean? Other methods from that class are called but not the post construct? Did you place some debug points there to make sure of this? – spauny Aug 22 '15 at 14:02
  • How exactly do you verify this phenomenon? – Tiny Aug 23 '15 at 02:22
  • why not just use a parameter on the url you're going to be redirected? like /details.xhtml?bookToView=selected_book_id? also, check this link as it might be related to your question (http://stackoverflow.com/questions/25694423/pass-an-object-between-viewscoped-beans-without-using-get-params) – Fritz Aug 24 '15 at 07:43

0 Answers0