This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes JSF context problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF context problem" Watch "JSF context problem" New topic
Author

JSF context problem

S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Hi every body ,

I have a problem in backing bean .I want to take the context path in my backing bean .Let suppose I want to take one JSF files info like this way -> http://myTest/test.jsf.
I dont want to hard code it. I want all information from the JSF context .Is it possible ?


regards,
S
Smitha H Rao
Ranch Hand

Joined: Oct 20, 2007
Posts: 50
In jsp file you can get contextpath using:
#{facesContext.externalContext.requestContextPath}

and in bean you can get context path using:
FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath()

Hope this helps.

Free Mock tests Interview questions
S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Thanks Smitha H Rao , for your reply .

I can get the FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() , it's fine , but at the same time I want remote address and the port number like this way :

http://127.0.0.1:8080/myApp/myJSF.jsf


regards,
S
Smitha H Rao
Ranch Hand

Joined: Oct 20, 2007
Posts: 50
You can get remote address and port if you have HttpServletRequest object something like below:
((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRemoteAddr()
((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRemoteHost()
((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRemotePort()
 
jQuery in Action, 2nd edition
 
subject: JSF context problem
 
Similar Threads
JSF 2.0 cannot rech out-come page
<h:commandLink> is not able to invoke backing bean method
Rendering a List in a JSF page
JSF Backing Bean in Java EE 6
How to call JSF backing bean method from the Applet