0

I am having a problem with JSF 2.2, I have this struct:

Problem: I can not set variables (by sessionScope - MainBean) since catalog.xhtml (by requestScope/ViewScope - CatalogBean).

LoginBean: SessionScope

@ManagedBean(name="loginBean")
@SessionScoped
public class LoginBean {

    private Session userLog;

MainBean: SessionScope

@ManagedBean
@SessionScoped
public class MainBean {


    @ManagedProperty(value="#{loginBean}")
    private LoginBean userLogin;

CatalogBean: ViewScope/RequestScope

@ManagedBean
@ViewScoped
public class CatalogBean {

    @ManagedProperty(value="#{mainBean}")
    private MainBean userManagerCatalog;

ItemBean: ViewScope/RequestScope

@ManagedBean
@ViewScoped
public class ItemBean { 

    @ManagedProperty(value="#{mainBean}")
    private MainBean userManagerItem;

The problem is when I enter in item.xhtml (ItemBean) , (since catalog.xhtml) I am saving a variable in MainBean (SessionScope), with:

<p:commandLink action="item.xhtml?faces-redirect=true" actionListener="#{mainBean.setSelectedItem(it)}">
   <p:graphicImage library="resources" name="images/folderNormal.png" style="width: 100; height: 100"/> 
   <f:setPropertyActionListener value="#{it}" target="#{mainBean.selectedItem}" />
</p:commandLink>

Data of Interest

*I had been to using two diferent forms (actionListener and setPropertyActionListener)

**I have to enter catalog to enter the item

*** I am bugging, this makes the change but the next, I see that the program lost this data

**** I had used in Catalog the property SessionScope (fuction well) but I can not change of catalog because the variable does not change its value.

Any help is welcome, thanks in advance

  • I am returning "ítem. Xhtml" in action and I am setting in actionListener – Pablo García Tamarit Sep 08 '16 at 17:49
  • Normally, also for bookmarkability, I prefer to have item related urls accessible by their item id. This way you could use a plain link to reach it like `item.xhtml?itemId=1`. It's not a good idea to store the value yourself in the session because you have to take care of removing it yourself. If not, when you have more than one browser tab sharing the same session, their behaviour could turn unpredictable. I would implement it using url params, or, if you still want to keep it hidden, use the [JSF flash scope](http://stackoverflow.com/a/21277621/1199132), which does exactly what you want. – Aritz Sep 08 '16 at 17:56
  • I have done what you have .told me before but this did not give good results. -catalog.xhtml- -MainBean- public String goItem(Item item){ this.setSelectedItem(item); return "item.xhtml?faces-redirect=true"; } – Pablo García Tamarit Sep 08 '16 at 18:06
  • Better try using any of the two methods from my second comment. – Aritz Sep 08 '16 at 18:13
  • I had been to work wiht code, I have discovered that I can not set variables (by sessionScope - MainBean) since catalog.xhtml (by requestScope/ViewScope - CatalogBean). – Pablo García Tamarit Sep 09 '16 at 03:10

0 Answers0