Using JSF with multiple tabs in one browser [duplicate]
Asked Answered
D

4

9

By default JSF appears to be very 'stateful'. I need to allow people to use our application with multiple tabs doing many things in different parts of the application.

I can't seem to find decent instruction on making this happen without a whole lot of re-engineering.

We do not currently use ICEfaces, but I just found this in the ICEfaces docs:

6.5.7. ICEfaces Portlets and Concurrent DOM Views

ICEfaces provides a feature called Concurrent DOM Views that controls whether or not the ICEfaces framework supports multiple views of a single application from the same browser. When running in a portlet container, ICEfaces needs to treat the separate portlets on a single portal page as distinct views so it is almost always necessary (and therefore safest) to have this parameter set to true.

Example 6.19. Enabling the ICEfaces Concurrent DOM Views feature in the WEB-INF/web.xml configuration file so that separate portlets on the same portal page are treated as distinct views

com.icesoft.faces.concurrentDOMViews true

So, I want to know whether this fabulous sounding functionality would possibly apply to my existing h:forms or whether it only works with ICEface components?

Can anyone offer any good advice to get a JSF app working in multiple tabs?

Directorial answered 8/7, 2010 at 10:19 Comment(1)
Update: I have just tried including icefaces.jar in my project and doctoring the web.xml as instructed above. No noticeable positive impact. Although it seems to indicate here that it should just work if I'm using h:head and h:body: wiki.icefaces.org/display/ICE/Getting+Started and icefaces.org/docs/v1_8_2/htmlguide/devguide/…Directorial
A
9

In JSF 2.0 you can use the view scope for this, annotable using @ViewScoped. You can even define custom scopes.

See also:

Amerce answered 8/7, 2010 at 12:45 Comment(7)
Thanks BalusC. It was a lot of re-engineering as I feared, but using ViewScoped beans instead of session scoped is now a LOT better.Directorial
but does view scope work accross views navigation?? cuz i've been trying to make it work and it just rebuild the bean in the next view!!Spitsbergen
No, it doesn't. The view scope lives as long as you're interacting with/navigating back to the same view. You need to either use a session scoped bean or to redesign your views to use conditionally rendered/included content.Amerce
@BalusC: A small question, while working through multiple tabs when you leave a view in some tab and work with same part of the application in another tab & then come back to old tab, will the view scoped bean(serving the old tab) survive ? In other words, can a user session have multiple instances of the same view scoped bean that would be created according to the no. of tabs he is working through with that part of app?Viddah
Each tab has its own view scoped bean. It's always created on a GET request and tabs can only be opened by GET requests.Amerce
meaning the data will survive until the tab is closed or view is changed through that tab, right ?Viddah
I think it's the most unknown/misunderstood/underrated feature of JSF ! Thank you.Insufficient
C
5

I don't think View Scope will work here. The question is specifically about a multi-browser tab scenario and my understanding with View Scope is that there is still one separate state per view (not per tab). In other words if you have the same page open in multiple browser tabs then you are at risk for sharing state.

This is mentioned here: http://www.java.net/node/692109

It seems like there are only two solutions to this problem: 1. CDI/Seam conversation scope (or something like it where an extra id is added to requests) or 2. Just stick to request scope / stateless app.

Comstock answered 15/8, 2011 at 20:14 Comment(1)
OK, I created a test application with Mojarra 2.1.3 (GlassFish 3.1.1) and discovered that the javax.faces.bean.ViewScoped does actually create a separate view per tab. Maybe this wasn't the case in the past or with other implementations like MyFaces? Anyways, sounds like using ViewScoped for multiple tabs is great! Too bad CDI doesn't support a ViewScoped out-of-the-box and you've gotta create your own or use Seam!Comstock
E
4

MyFaces orchestra has a way of dealing with multiple tabs/windows (using the conversationContext get parameter).

Eclair answered 8/7, 2010 at 10:57 Comment(0)
I
4

Use Seam with the JSF framework you want.

The conversation context is perfect for using different tab. Just start a new conversation on each tab. :)

Take a look at the Booking demo

Please don't use Seam, it's not supported. Use JSF 2.0 as stated in this answer https://mcmap.net/q/1133968/-using-jsf-with-multiple-tabs-in-one-browser-duplicate

Instil answered 8/7, 2010 at 12:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.