[ajug-members] JSF question - Additional info
David Chandler
david.chandler at learnjsf.com
Fri Mar 6 21:12:37 EST 2009
JSF's externalContext is a wrapper for either the ServletContext or
PortletContext in which JSF runs so that your beans do not have to
know in which of these environments they are running. In your case,
the ExternalContext is simply wrapping the ServletContext and passing
through the requestURL as it arrived at the servlet. It appears that
the JSP pageContext object incorrectly assumes that the requestURL is
for a JSP page, or perhaps this is an artifact of the way in which JSF
calls the JSP. If you want the URL as it was requested of the servlet,
then getExternalContext() is in fact correct.
Hope that helps,
/dmc
On Fri, Mar 6, 2009 at 6:14 PM, J. Talafous <jtalafous at gmail.com> wrote:
> Thanks Ramesh,
>
> I am seeing something, maybe you can explain this. I think it has
> something to do with "external" context..
>
> When I enter my JSF web app, the browser address bar says
> "http://myserver.com/jsfapp/index.jsf" for example. I click around in
> it, and the address bar doesn't change, even though I am on a
> different page, say http://myserver.com/jsfapp/newpage.jsp. (like in
> servlet forwarding)
>
> When I am at this newpage.jsp, it has a header tag, and inside the
> header tag java class I do this:
>
> String s=((HttpServletRequest)
> FacesContext.getCurrentInstance() .getExternalContext().getRequest()).getRequestURL()
> ;
>
> then s is "http://myserver.com/jsfapp/index.jsf"
>
> If I do this:
>
> String s=((HttpServletRequest)pageContext.getRequest()).getRequestURL();
>
> then s is http://myserver.com/jsfapp/newpage.jsp
>
> but I want s to be http://myserver.com/jsfapp/newpage.jsf
>
> I think "external context" refers to this address bar behavior, so
> maybe I don't want to use getExternalContext(). Is there a way to get
> JSF to "externalize" an internal context and tell me about it?
>
> Thanks,
> Joe
>
>
>
>
> On 3/6/09, Ramesh Rajamani <rameshrajamani at hotmail.com> wrote:
>>
>> Hi,
>>
>> I guess you got your relative path when you use
>> FacesContext.getCurrentInstance().getExternalContext().getRequest() and
>> absolute path when you use request.getRequestURL(). For the former we have
>> to import the FacesContext in the bean and for request.getRequestURL() we
>> have to import the servletcontext in the bean.
>>
>>
>>
>> Regards,
>>
>> Ramesh
>>
>>> Date: Fri, 6 Mar 2009 13:12:15 -0600
>>> From: jtalafous at gmail.com
>>> To: ajug-members at ajug.org
>>> Subject: Re: [ajug-members] JSF question
>>>
>>> That solved the problem perfectly, thank you very much.
>>>
>>> On 3/6/09, David Chandler <david.chandler at learnjsf.com> wrote:
>>> > Are you getting the request object from
>>> > FacesContext.getCurrentInstance().getExternalContext().getRequest()?
>>> >
>>> > /dmc
>>> >
>>> > On Fri, Mar 6, 2009 at 11:55 AM, J. Talafous <jtalafous at gmail.com>
>>> > wrote:
>>> >> I am inside a JSP tag java file and I want to know the URL of the
>>> >> request, so I use request.getRequestURL(). But it returns
>>> >> http://myserver.com/myfile.jsp instead of
>>> >> http://myserver.com/myfile.faces or http://myserver.com/myfile.jsf.
>>> >> In other words, I want the request entered by the user, not the one
>>> >> mapped by JSF. Is there a way to do that? Thanks for the help.
>>> >>
>>> >> _______________________________________________
>>> >> ajug-members mailing list
>>> >> ajug-members at ajug.org
>>> >> http://www.ajug.org/mailman/listinfo/ajug-members
>>> >>
>>> >
>>> > _______________________________________________
>>> > ajug-members mailing list
>>> > ajug-members at ajug.org
>>> > http://www.ajug.org/mailman/listinfo/ajug-members
>>> >
>>>
>>> _______________________________________________
>>> ajug-members mailing list
>>> ajug-members at ajug.org
>>> http://www.ajug.org/mailman/listinfo/ajug-members
>>
>> _________________________________________________________________
>> The new Windows Live Messenger. You don’t want to miss this.
>> http://www.microsoft.com/india/windows/windowslive/messenger.aspx
>
> _______________________________________________
> ajug-members mailing list
> ajug-members at ajug.org
> http://www.ajug.org/mailman/listinfo/ajug-members
>
More information about the ajug-members
mailing list