0

I'm working on a JSF 1.2 + RichFaces system. This system is a kind of blog. Users can create their blogs and manage them. Blogs are accessible by a url type this:

www.meublog.com/NameOfBlog

I used a single Managed Bean with session scope to make all controls. When the user accesses the blog, I use a filter that through the URL, which identified the blog being accessed, put the ID of the blog in the session and gave foward to the blog index. I used this session ManagedBean to control everything in the view of the blog. The problem is that the browser shares the same session between multiple tabs. When a user accesses the blog like this www.meublog.com/julio on one tab and www.meublog.com/fulano in another tab, I can not identify the two blogs because I have only one session established.

I wonder to know if anyone knows the correct path to follow here ...

Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
  • I know nothing about jsf, but if the session contains the blog id then surely you know which blog is which? I think I must be missing something. Can you be a little clearer? – Sachin Kainth May 24 '12 at 21:45
  • @SachinKainth: the HTTP session accounts for a single browser instance and is thus been shared among multiple browser tabs within the same browser instance. – BalusC May 24 '12 at 22:06

1 Answers1

1

You should not store request scoped information in the session scope for exactly the reasons you're facing. Use a request scoped managed bean instead which get initialized based on the request URI. You can get most of the request details by ExternalContext and/or HttpServletRequest.

E.g., inside bean's constructor or @PostConstruct method:

ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();

// If you use suffix mapping like *.jsf
String servletPath = ec.getRequestServletPath(); 

// Or if you use prefix mapping like /faces/*
String pathInfo = ec.getRequestPathInfo();

// Now initialize based on the value of either servletPath or pathInfo.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555