0

I am using SessionScoped Managed Beans in my application:

@ManagedBean
@SessionScoped
public class SampleBean{

private String value;

//getters and setters

}

I have my controller:

@ManagedBean
@SessionScoped
public class SampleController{

@ManagedProperty(value = "#{sampleBean}")
private SampleBean sampleBean;

public String showConfirm() {

return "confirm";

}

public String showComplete() {

return "complete";

}

//getters and setters
}

The logic is that, I have a startup page where I enter the values.Then it goes to the confirm page and then finally to the Complete page. I have to show the data entered in startup page in the remaining pages.

The startup page is as follows:

startup.xhtml

<h:inputText value="#{sampleBean.value}">
<h:commandLink value="Confirm"  action="#{sampleController.showConfirm()}">

In the confirm page, I want to show this data.

confirm.xhtml

<h:outputFormat value="#{sampleBean.value}">

However, i don't get any value displayed here. I tried putting these values into the sessionMap in the showConfirm() method.

public String showConfirm() {

FacesContext context = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("sampleBean", sampleBean);

return "confirm";

}

But then also, I am not able to view these values in confirm.xhtml.

Only if I use <h:outputFormat value="#{sessionScope.sampleBean.value}"> , the values get displayed. Also, I would like to do this using SessionScope only since all this is part of a bigger application with sessions. Is there an alternatve to do it?

Jini Samuel
  • 124
  • 1
  • 3
  • 13

2 Answers2

0

You can access sessionScoped beans from views through the controller bean by :

<h:inputText value="#{sampleController.sampleBean.value}">

With adding getter/setter of this Managed-Property in the controller bean.

Omar
  • 1,430
  • 1
  • 14
  • 31
  • I tried giving `` in `confirm` page but its still not displaying any value. – Jini Samuel Sep 20 '13 at 14:08
  • Maybe there miss you something in the view.. can you post the view's code ? – Omar Sep 20 '13 at 17:33
  • I tried printing the sessionScope using `` My `SampleController` is not displayed in the sessionscope. I believe I am doing doing something wrong in my SampleController. – Jini Samuel Sep 23 '13 at 06:19
  • Can it the managed-bean constructor ? I tried your precise example and it runs fine, can you put the whole code of your two managed-beans + the views ? – Omar Sep 23 '13 at 07:35
0

your session scoped bean should implement Serializable interface to work properly see this

Community
  • 1
  • 1
hanan Ahmed
  • 442
  • 3
  • 5
  • The question's owner doesn't indicate to any exception detected; morever, the example runs fine with me without any `Serializable`'s implementation. – Omar Sep 21 '13 at 14:06
  • I tried implementing using `Serializable` interface, but yet its not working. – Jini Samuel Sep 23 '13 at 06:22