dev@jsftemplating.java.net

Re: JSFTemplating: How to get the page url?

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Thu, 17 Jan 2008 09:54:39 -0800

Hi Karam,

I did the test as you described below and it worked fine. However, what
I *didn't* do was enable security... so here's what may be happening.
You are visiting a page that is protected by a security constraint in
your web application and it is redirecting to your login.jsf page. I
don't think the FacesServlet is even being invoked for the page you
attempted to visit, let alone the initPage(). You can try to execute a
"println()" in the initPage to see if you can get it to execute to test
this.

How to get around this problem. Disable security (I don't think that's
the way you want to go). Find a way to get the original request URI
information from w/i the login.jsf page (not sure if this is available
or not... although I think it is). If the page IS executing before the
redirect, try storing it in session instead of as a QUERY_STRING
parameter (I don't think this is an option, though, b/c I don't think
the FacesServlet let alone the initPage is executing). Last, try
emailing the GF dev alias (dev_at_glassfish.dev.java.net) and see if anyone
(like Jan Luehe) has a better suggestion.

Ken

Karam Singh wrote:
> Ken,
> I have the following code in initPage
>
> <!initPage
> redirect(page="login.jsf?dest=#{request.requestURL}");
> />
>
> Strangely it gets redirected to login.jsf without the "dest=<url of
> the page where its coming from>". Am I doing something wrong in the
> above code?
>
> thanks
> Karam
>
> Ken Paulsen wrote:
>>
>> Hi Karam,
>>
>> I added the following to the top of the test page that I wrote below:
>>
>> <!initPage
>> println("hi! '#{request.requestURL}'");
>> />
>>
>> println() writes a log message to the server.log... I checked and the
>> correct value for the requestURL was written in the log:
>>
>> [#|2008-01-16T23:52:46.067+0000|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=19;_ThreadName=httpSSLWorkerThread-8080-3;|
>>
>> hi! 'http://localhost:8080/demo/j.jsf'|#]
>>
>> Make sure your initPage event is at the top of your file.
>>
>> I hope this helps,
>>
>> Ken
>>
>> Karam Singh Badesha wrote:
>>> Ken,
>>> If I try to use #{request.requestURL} inside a initPage event, it
>>> doesn't work. Is that how its supposed to work?
>>>
>>> thanks
>>> Karam
>>>
>>> Ken Paulsen wrote:
>>>>
>>>> Hi Karam,
>>>>
>>>> You can get this information from the request object. If you want
>>>> to do this from w/i a JSFT .jsf page, you can do this via an EL
>>>> expression. If you cut/paste the following into a .jsf page in
>>>> your application you can see what these do:
>>>>
>>>> "ContextPath: #{request.contextPath}<br />
>>>> "QueryString: #{request.queryString}<br />
>>>> "RequestURI: #{request.requestURI}<br />
>>>> "RequestURL: #{request.requestURL}<br />
>>>> "ServletPath: #{request.servletPath}<br />
>>>>
>>>> For JSF w/ a *.jsf servlet mapping, the last one will give you want
>>>> you want.
>>>>
>>>> If you want to do this via Java, then you can get some of this
>>>> information from the ExternalContext. The rest can be obtained
>>>> directly from the request object (although you'll have to cast to
>>>> ServletRequest or HttpServletRequest... meaning your code won't
>>>> work in a Portlet environment). You can get the ExternalContext &
>>>> request object by doing:
>>>>
>>>> FacesContext.getCurrentInstance().getExternalContext()
>>>>
>>>> externalContext.getRequest()
>>>>
>>>> I hope this helps!
>>>>
>>>> Ken
>>>>
>>>> Karam Singh Badesha wrote:
>>>>> Hi,
>>>>> e.g. One of the page in my app is http://host/CADRe/test.jsf
>>>>>
>>>>> Is there a way to get the url after the "http://host/CADRe/" in
>>>>> this case "test.jsf" in jsftemplating?
>>>>>
>>>>> thanks
>>>>> -Karam