You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Matthias Kahlau <mk...@web.de> on 2005/11/26 18:55:25 UTC

Problem with Stylesheet loading after returning to the site by pressing the cancel button

Hi!


I have a JSF page with stylesheets used by <link rel ...>, and the
stylesheets are correctly applied. The page links to another JSF page. When
I navigate to the other JSF page, and then return to the first page by
pressing the cancel button, the first page is shown, but without any
stylesheets applied. Does anybody know what might be the cause of the
problem? I have other pages with stylesheets and cancel buttons, but the
problem occurs only in one example.


Regards,
Matthias


RE: Problem with Stylesheet loading after returning to the site by pressing the cancel button

Posted by Yee CN <ye...@streamyx.com>.
MyEclipse generates the following on every jsp page, and I have been keeping
it without knowing exactly why, that is until now :-)

 

<%String path = request.getContextPath();

      String basePath = request.getScheme() + "://"

                  + request.getServerName() + ":" + request.getServerPort()
+ path + "/";

%>

<html>

<head>

      <base href="<%=basePath%>">

 

 

Yes - it would be much cleaner to have a JSF component for this.

 

Regards,

Yee

 

 

  _____  

From: craigmcc@gmail.com [mailto:craigmcc@gmail.com] On Behalf Of Craig
McClanahan
Sent: Monday, 28 November 2005 12:41 PM
To: MyFaces Discussion
Subject: Re: Problem with Stylesheet loading after returning to the site by
pressing the cancel button

 

 

On 11/27/05, Simon Kitching <sk...@obsidium.com> wrote:

Wayne Fay wrote:
>> Maybe your page is in a subfolder, so on the next page the path to the
>> stylesheet  has  a  wrong base. Try to change the path to the css file
>> to an absolute path instead of a relative one. 
>
> I have had numerous problems with stylesheets in JSF.
>
> The only way I could get things to work consistently was with absolute
> paths, as Steffen has already suggested.

Remember that the *browser* fetches the stylesheet by passing an 
*absolute* URL to the remote server.

When the stylesheet URL is relative, the *browser* forms an absolute URL
for it by taking the URL it used *to fetch the current html page*, and
appending the relative stylesheet path. 

Any server-side framework that uses forwards internally is going to have
problems with this, because the browser doesn't know the actual *file
path* for the jsp (or whatever) that was forwarded to in order to 
generate the response page, it only knows the original URL it sent.


There is actually an additional gotcha to be aware of with JSF (as well as
other frameworks, like Struts, that do RequestDispatcher.forward() calls on
the server side).

You'll note that the location bar of your browser shows the URL to which the
last form submit was performed, *not* the page you navigated to that caused
the most recent rendering.  If you try to use relative URLs, *this* is the
URL that the browser will resolve against ... which will cause problems if
the new page is at a different subdirectory level than the previous page
was.

 

For just about any dynamic server stuff you therefore *must* ensure the
page returned to the browser contains *absolute* URLs in it. There are 
special Struts JSP tags to help with this; I'm sure PHP and similar also
have helpers to turn relative paths into absolute paths.

It looks to me like the tomahawk t:stylesheet tag currently just adds
the webapp context to the path, but doesn't handle paths relative to the 
current JSP.


Struts has a tag to emit a <base> element (which goes in the <head> section)
that tells the browser "use this page's URL as the base for resolving
relative paths).  It would be handy to have a JSF component that did the
same -- indeed, there's such a component available in the struts-faces
integration library that oculd be copied into Tomahawk.

 

Regards,

Simon


Craig
 

 

 


Re: Problem with Stylesheet loading after returning to the site by pressing the cancel button

Posted by Craig McClanahan <cr...@apache.org>.
On 11/27/05, Simon Kitching <sk...@obsidium.com> wrote:
>
> Wayne Fay wrote:
> >> Maybe your page is in a subfolder, so on the next page the path to the
> >> stylesheet  has  a  wrong base. Try to change the path to the css file
> >> to an absolute path instead of a relative one.
> >
> > I have had numerous problems with stylesheets in JSF.
> >
> > The only way I could get things to work consistently was with absolute
> > paths, as Steffen has already suggested.
>
> Remember that the *browser* fetches the stylesheet by passing an
> *absolute* URL to the remote server.
>
> When the stylesheet URL is relative, the *browser* forms an absolute URL
> for it by taking the URL it used *to fetch the current html page*, and
> appending the relative stylesheet path.
>
> Any server-side framework that uses forwards internally is going to have
> problems with this, because the browser doesn't know the actual *file
> path* for the jsp (or whatever) that was forwarded to in order to
> generate the response page, it only knows the original URL it sent.


There is actually an additional gotcha to be aware of with JSF (as well as
other frameworks, like Struts, that do RequestDispatcher.forward() calls on
the server side).

You'll note that the location bar of your browser shows the URL to which the
last form submit was performed, *not* the page you navigated to that caused
the most recent rendering.  If you try to use relative URLs, *this* is the
URL that the browser will resolve against ... which will cause problems if
the new page is at a different subdirectory level than the previous page
was.

For just about any dynamic server stuff you therefore *must* ensure the
> page returned to the browser contains *absolute* URLs in it. There are
> special Struts JSP tags to help with this; I'm sure PHP and similar also
> have helpers to turn relative paths into absolute paths.
>
> It looks to me like the tomahawk t:stylesheet tag currently just adds
> the webapp context to the path, but doesn't handle paths relative to the
> current JSP.


Struts has a tag to emit a <base> element (which goes in the <head> section)
that tells the browser "use this page's URL as the base for resolving
relative paths).  It would be handy to have a JSF component that did the
same -- indeed, there's such a component available in the struts-faces
integration library that oculd be copied into Tomahawk.

Regards,
>
> Simon


Craig

Re: Problem with Stylesheet loading after returning to the site by pressing the cancel button

Posted by Simon Kitching <sk...@obsidium.com>.
Wayne Fay wrote:
>> Maybe your page is in a subfolder, so on the next page the path to the
>> stylesheet  has  a  wrong base. Try to change the path to the css file
>> to an absolute path instead of a relative one.
> 
> I have had numerous problems with stylesheets in JSF.
> 
> The only way I could get things to work consistently was with absolute
> paths, as Steffen has already suggested.

Remember that the *browser* fetches the stylesheet by passing an 
*absolute* URL to the remote server.

When the stylesheet URL is relative, the *browser* forms an absolute URL 
for it by taking the URL it used *to fetch the current html page*, and 
appending the relative stylesheet path.

Any server-side framework that uses forwards internally is going to have 
problems with this, because the browser doesn't know the actual *file 
path* for the jsp (or whatever) that was forwarded to in order to 
generate the response page, it only knows the original URL it sent.

For just about any dynamic server stuff you therefore *must* ensure the 
page returned to the browser contains *absolute* URLs in it. There are 
special Struts JSP tags to help with this; I'm sure PHP and similar also 
have helpers to turn relative paths into absolute paths.

It looks to me like the tomahawk t:stylesheet tag currently just adds 
the webapp context to the path, but doesn't handle paths relative to the 
current JSP.

Regards,

Simon

Re: Problem with Stylesheet loading after returning to the site by pressing the cancel button

Posted by Wayne Fay <wa...@gmail.com>.
> Maybe your page is in a subfolder, so on the next page the path to the
> stylesheet  has  a  wrong base. Try to change the path to the css file
> to an absolute path instead of a relative one.

I have had numerous problems with stylesheets in JSF.

The only way I could get things to work consistently was with absolute
paths, as Steffen has already suggested.

Wayne

Re: Problem with Stylesheet loading after returning to the site by pressing the cancel button

Posted by Steffen Hankiewicz <ha...@sub.uni-goettingen.de>.
Hi,

> problem? I have other pages with stylesheets and cancel buttons, but the
> problem occurs only in one example.

Maybe your page is in a subfolder, so on the next page the path to the
stylesheet  has  a  wrong base. Try to change the path to the css file
to an absolute path instead of a relative one.

Greetings,

Steffen Hankiewicz