0

I have a data table with 5 columns. The first column contains:

<p:column headerText="Ordine" filterBy="#{item.numeroOrdineLavoro}"
          sortBy="#{item.numeroOrdineLavoro}">

    <p:commandLink value="#{item.numeroOrdineLavoro}"
                   process="@this"
                   action="#{Bean_OrdiniLavoro.cmdSeleziona_Ordine}">

        <f:setPropertyActionListener target="#{Bean_OrdiniLavoro.sel_OrdineLavoro}" 
                                     value="#{item}" />
    </p:commandLink>
</p:column>

Bean_OrdiniLavoro is ViewScoped. Bean_OrdiniLavoro.cmdSeleziona_Ordine redirects in a new page.

Every times i click on the commandlink Bean_OrdiniLavoro is ReCreated. This is the problem.

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
    <param-value>false</param-value>
</context-param>

Primefaces 3.5 and JSF 2.1.22.

I have read many post saying that PARTIAL_STATE_SAVING = false is enough But in this case it doesn't work.

If I use a instead of it works.

thanks a lot. Davide

1 Answers1

0

When using action property of p:commandButton, the return value is where you want to navigate. If you are returning a non-null value, your current view will terminate in favor of the new one.

If you want to stay in the same view, you must return a null value or void.

public String cmdSeleziona_Ordine()
{
    return null;
}

or

public void cmdSeleziona_Ordine()
{

}
Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72
  • I want to redirect toward another page. if action return "Page_EditOrdine.xhtml?faces-redirect=true" the viewScoped bean is recreated. only for test, I returned null and I used FacesContext.getCurrentInstance().getExternalContext().redirect("Page_EditOrdi‌​ne.xhtml");. So it works..it's strange for me! – Davide Lo Giudice May 21 '13 at 09:22
  • If I understand, you have two views using the same bean? – Alexandre Lavoie May 21 '13 at 09:30
  • I wish it was terminated in favor of the new one, but before to change page it ReCreates the ViewScoped bean (Bean_OrdiniLavoro) and then changes page. sorry for my english – Davide Lo Giudice May 21 '13 at 09:31
  • no i have 2 views and two beans. When i select an item in a table of the first view i would go to the other view. it is a simple CRUD, list and edit. Both bean are ViewScoped. – Davide Lo Giudice May 21 '13 at 09:33
  • Ok I understand, I think this is a _normal_ behavior of JSF, never investigated by myself for the moment. – Alexandre Lavoie May 21 '13 at 09:36
  • I have read many post saying that PARTIAL_STATE_SAVING = false is enough But in this case it doesn't work. – Davide Lo Giudice May 21 '13 at 09:37
  • (which is the best practise for managing crud. What do you use to select and edit an item in another page?) I thought this was the best solution but...if the first bean is ReCreated every time i can't use it. – Davide Lo Giudice May 21 '13 at 09:42
  • The best is only to keep nothing you don't need in memory, the shorted possible scope. The ViewScoped scope is a good improvement since JSF 2.0 because in JSF 1.2 the SessionScoped was missused to simplify applications. – Alexandre Lavoie May 21 '13 at 09:45
  • obviously with sessionScope it works, but i would like to use ViewScoped bean.. i hope thay you can halp me. thanks – Davide Lo Giudice May 21 '13 at 09:50
  • Well you get a new ViewScoped for editing the object, and after you get another new ViewScoped (other bean) to view your objects list. Is that what you are experiencing? Is there something wrong with that? You can pass the id of the object you want to edit directly in URL as I often to with simple ` – Alexandre Lavoie May 21 '13 at 09:56
  • certainly it's a good solution like (i think so) FacesContext.getCurrentInstance().getExternalContext().redirect("Page_EditOrdi‌​‌​ne.xhtml"); but I would like to figure out why return "page...?faces-redirect=true" doesn't work. maybe I'm doing something wrong – Davide Lo Giudice May 21 '13 at 10:02
  • the first bean contains the list, when I click on an item of the list I go to the second bean for editing. Then i come back. – Davide Lo Giudice May 21 '13 at 10:04
  • for passing the item to the other page I'm using or + . Both ways work with FacesContext.getCurrentInstance().getExternalContext().redirect("Page_EditOrdi‌​ne.xhtml") – Davide Lo Giudice May 21 '13 at 10:09
  • Here you have a good example of a CRUD : http://stackoverflow.com/a/3180885/354831 – Alexandre Lavoie May 21 '13 at 10:11
  • all in a page :-) perfect. – Davide Lo Giudice May 21 '13 at 10:13
  • but why doesn't "RETURN" work? Which are the differences with FacesContext.getCurrentInstance().getExternalContext().redirect("xx") :-( I would to figure out.. – Davide Lo Giudice May 21 '13 at 10:59