0

I would like to know if there is a way to remove www (or add) when happens a request.

Here's my problem:

I'm inserting CSS this way: "//domain.com.br/resources/cssname.css"

if I access a page http, everything works perfectly, but when I access a page https USING "www.domain.com.br" the page doesn't load CSS files

if I insert CSS like this: "//WWW.domain.com.br/resources/cssname.css" the oposite happens, and when i access a page using "domain.com.br" there is no css.

Could I change all requests when using remove wwww or all request add www?

I saw that prettyfaces has could that be done using this?

Also, I'm using glassfish, I don't know if this can be done by there or by provider.

Thanks.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Victor Bello
  • 493
  • 1
  • 8
  • 23

2 Answers2

2

You should not be worrying about the domain name nor the context path in all your CSS/JS/image resources at all.

Instead of

<link rel="stylesheet" href="//domain.com/context/resources/style/some.css" />
<script src="//domain.com/context/resources/script/some.js"></script>
<img src="//domain.com/context/resources/images/some.png" />

or even

<link rel="stylesheet" href="#{request.contextPath}/resources/style/some.css" />
<script src="#{request.contextPath}/resources/script/some.js"></script>
<img src="#{request.contextPath}/resources/images/some.png" />

or even the clumsily longer as suggested by other answer

<link rel="stylesheet" href="#{facesContext.externalContext.requestContextPath}/resources/style/some.css" />
<script src="#{facesContext.externalContext.requestContextPath}/resources/script/some.js"></script>
<img src="#{facesContext.externalContext.requestContextPath}/resources/images/some.png" />

you should actually be using

<h:outputStylesheet name="style/some.css" />
<h:outputScript name="script/some.js" />
<h:graphicImage name="images/some.png" />

And, for CSS background images, instead of

.some {
    background-image: url("../images/some.png");
}

you should actually be using

.some {
    background-image: url("#{resource['images/some.png']}");
}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks @Balusc, I've made this. I have some doubts: url("#{resource['images/some.png']}"); About this resource, it's the folder 'resource' in the project? Which has js, cs, img, etc? Also, is it possible to do in jquery, for example? Another thing is: Instead of isn't it? Thanks again, I've learned a lot with your answers here. – Victor Bello Mar 14 '13 at 23:50
1

Personally, I always use:

#{facesContext.externalContext.requestContextPath}/resources/cssname.css

As the path to any of my resources. This way, I am sure that I am always getting the right path to my resource.

Hope this helps Cheers

Laabidi Raissi
  • 3,263
  • 1
  • 22
  • 28
  • It worked man. Thanks. Actually, I've changed the to But in some places I need to use #facesContex.externalContext.requestContextPath}/images Thanks. – Victor Bello Mar 08 '13 at 19:17