Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing data between JSP and JSF  RSS feed

 
Abhishek Uppala
Greenhorn
Posts: 10
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I was wondering to know whether there is a way to pass data from a JSP page to a JSF page. I am using JSF for my project and for the authentication purpose i am using JSP. I need to pass the user name set through JSP to the JSF page.

Kindly let me know if there is a way for doing this.


Thanking You
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you've been reading this forum for very long, you'll have noticed that I have very strong opinions about ANY sort of do-it-yourself Authentication and Authorization solution in J2EE, and if you're interest, I can point you to a long list of reasons why - starting with the fact that they all seem to have blatant holes in them.

However, I'm a tiny voice crying out in the middle of the desert, so I offer help and hope that none of these systems is ever implemented in a place where my money and/or private data is at risk.

So much for ranting. If you'd used the container-managed security, you'd have the user ID on the request (getUserPrincipal). Since you're DIY, I expect that you've got it squirreled away in a Session-scope JavaBean.

Fear not. If you define a JSF Managed Bean as Session Scope, it will be the exact same bean as you're seeing from JSPs. The only thing to worry about is that since Managed Beans are created by the JSF framework if needed, you might end up having JSF construct something that you'd normally have the login code build. That's usually easy to work around, though.
 
prash patil
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
The quick and may be dirty way is use session


regards,
PP
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember, JSF isn't some mysterious monster that replaces normal Java based wed development. All of the normal Servlet and JSP constructs are available to you. JSF builds upon Servlets and JSPs, as opposed to throwing the baby out with the bath water. All of those neat tools, such as the Session scope and Request scope are still available to you. So, if you want to shove something into the Session in a JSP, and pull it out with a JSF component, you're more than entitled!

Heed Tim's advice though.

-Cameron McKenzie
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there are 2 very common misconceptions about JSF. JSF is not some sort of Master (Monster?) Control Program that has to be in total control for the life of the webapp.

Firstly, like all webapp systems, there's no conversational client/server relationship the way you have with things like RMI and CORBA. JSF is based on HTTP and HTTP is strictly request/response. It's not possible for the server to send unsolicited data to the client, nor is there a permanent connection between the client and server. In fact, if it weren't for cookies and sessions, each request/response would be totally ignorant of every other.

Secondly, there's no permanent infrastructure to damage if you make non-JSF requests in an app. If an incoming URL targets JSF (as defined by web.xml), the URL and its associated data (headers, POST content) are routed to the FacesServlet, which builds up a FacesContext, runs through the lifecycle steps, culminating with the final transmission of the Render Response phase, and discards the FacesContext. A new FacesContext is build for each request.

So, in short, you can design a webapp that uses straight servlets and JSPs, Struts, and JSF all in the same app, since each architecture works independently of the others. Since they all build on the same basic blocks (session objects and so forth), they can trade information with each other as needed.

JSF does its best work at creating and conversing with forms. I've got apps that construct PDFs and output XML files. JSF doesn't do that very well, so I use JSPs and servlets to handle that part of the webapp.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:I think there are 2 very common misconceptions about JSF.....


FAQ worthy if you ask me. Is there a JSF Faq page? Many JSF compilcations could be solved if people really understood that.

-Cameron McKenzie


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!