1

JSF 2.0, Primefaces

I have a session based bean (Bean1) and the corresponding view that contains ajax calls to modify data on the fly. It's ideal, since it doesn't require page loads on non-ajax button submits.

However - I'm in a situation where they want to have multiple views open in the same browser and allow each to work on it's own (which would be more of a request scope). So one parameter would technically be "request". But - I want that AJAX functionality that the session view gave me. This parameter currently is, obviously because its session, shared across browsers. This is causing usability issues.

Is it possible to have a parameter that "acts" as a request parameter, instead of session? So each window is open to a session view, but the parameter is in "request" mode and is individually assigned to the windows.

Vasil Lukach
  • 3,658
  • 3
  • 31
  • 40
user2124871
  • 803
  • 3
  • 9
  • 25

1 Answers1

3

Just put the bean in the view scope instead of the session scope.

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class Bean1 implements Serializable {
    // ...
}

This way each browser tab/window will automagically get its own instance exactly as you intented, without any necessity for manual request parameter hackery.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Is it at all possible to have AJAX based components update and refresh the page if the backing bean is in View scope? That's the bigggest issue I have at the moment (primefaces, adding components to the page via AJAX) – user2124871 Sep 25 '13 at 19:19
  • Certainly it is. Just make sure that you return `null` or `void` from action methods as long as you'd like to postback to the same view (and thus keep the view scope alive). See also the "See also" link for an elaborate explanation. – BalusC Sep 25 '13 at 19:20
  • Excellent - My biggest fear was that I wouldn't be able to manipulate and update view content in request/view sessions. Much appreciated. – user2124871 Sep 25 '13 at 19:24