• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSF - Request / Session attributes

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a JBoss portal server and I have two applications (different EAR files) deployed in it.
I use JSF framework for both the applications.

I provide a link in my first application which takes the user to a page in the second application.
Now, how can I set and then pass parameters / attributes from the first application to second application?

I tried to get the backing bean of the first application, in the second application but I guess it wont work.
Every FacesContext is unique for each application. Isnt it?

And then I tried this, again I get only "null" as value:

To set the attribute in portlet session

FacesContext fcRequest = FacesContext.getCurrentInstance();
PortletSession objPortletSess = (PortletSession) fcRequest.getExternalContext().getSession(false);
objPortletSess.setAttribute("ATTRIBUTE_NAME", "VALUE", PortletSession.APPLICATION_SCOPE);


To get the attribute from portlet session

PortletSession objPortletSess = (PortletSession) fcRequest .getExternalContext().getSession(false);
String strSelFileId = (String) objPortletSess.getAttribute("ATTRIBUTE_NAME", PortletSession.APPLICATION_SCOPE);

Any help is much appreciated.

Thanks!!
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, every FacesContext is not unique to each application.

FacesContext is unique to each request. Not only is it not unique to an application, it's not unique to the user session. The FacesServlet builds it when a JSF request comes in, uses it to manage the JSF request/response process, then tosses it away once the reponse has been sent back. It builds a whole new FacesContext on the next JSF request that comes in. That's why generic servlets and JSPs get NullPointerExceptions. They don't build FacesContext's. Only the FacesServlet does.

There are several ways to share data between webapps and they're not JSF-specific. One way is to share session data. That tends to be fairly low overhead, but it only works in limited configurations. And you have to specially configure the server(s) that do the session sharing.

A more robust way is to simply keep the info in persistent storage. This is more flexible, but may be more overhead. The overall penalty can be reduced, though, if you use a shared cache mechanism.
 
dwarakanathan thiru
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, In that case, can you please tell me why request attributes are not passed over to the other JSP / JSF file?
It should be the same request right?

FacesContext is unique to each request. Not only is it not unique to an application, it's not unique to the user session. The FacesServlet builds it when a JSF request comes in, uses it to manage the JSF request/response process, then tosses it away once the reponse has been sent back. It builds a whole new FacesContext on the next JSF request that comes in. That's why generic servlets and JSPs get NullPointerExceptions. They don't build FacesContext's. Only the FacesServlet does.



I prefer to use the session / request to pass on the values from one portal application to another portal application.
Can you please tell me how to do that? I tried with PortletSession and it does not work.

There are several ways to share data between webapps and they're not JSF-specific. One way is to share session data. That tends to be fairly low overhead, but it only works in limited configurations. And you have to specially configure the server(s) that do the session sharing.
A more robust way is to simply keep the info in persistent storage. This is more flexible, but may be more overhead. The overall penalty can be reduced, though, if you use a shared cache mechanism.

 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your first application presents a link to the second application, then clicking the link will go directly to the second application and the first application won't even factor into it. Once the first application has built the page with the link on it, you could drop a nuclear bomb on the first application's webserver for all the difference it would make. There's no mechanism passing the request from app1 to app2. So request parameters wouldn't factor.

The request parameters are coming from the URL (GET) or the form (POST) on the page (or page fragment, for portlets). Because the page is a text object it has no way to hold binary java object instances in it. Thus, the only way to pass binary objects from one server to another via HTTP is to pass a text "handle" that can be used by the backend of the target server to locate the actual binary object. However, if the binary object is residing in a different Java VM - or even in a different webapp classpath on the same VM, it won't be directly accessible by the receiving application.

That's why you usually need some sort of serializing mechanism to allow resources to be shared between webapps.
 
dwarakanathan thiru
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally I got a way that works.
I tried passing request parameters from the 1st application to the 2nd application using a servlet in the 2nd app.
And from there I will set the parameter back to a session & use a redirect to my portal page, which will use up the parameter.

I shall post the code soon.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

dwarakanathan thiru wrote:Finally I got a way that works.
I tried passing request parameters from the 1st application to the 2nd application using a servlet in the 2nd app.
And from there I will set the parameter back to a session & use a redirect to my portal page, which will use up the parameter.

I shall post the code soon.



Thiru, could you please post the code. I'm trying to do exactly the samething.

 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a good idea to check the date when responding to an old message. This thread was last posted to about 2-1/2 years ago. These days, that means that some or all of the participants may not even be working for the same employer any more, much less working on the same project.
 
reply
    Bookmark Topic Watch Topic
  • New Topic