kark
kark

Reputation: 4853

Can't loading CSS images in JSF

Description : In my JSF application, I am setting the menu background images through CSS property.

I configured the file structure as follows

Style.css

  #menu 
  {
   height:35px;
   width:950px;
   background:url(images/default.gif);
   /*background:url(#{resource['images:default.gif']}); 
   background:url(#{resource['images/default.gif']});
   */
  }

and this CSS file is under /resources/css directory, and I am importing the css file in Facelets page using

<h:head>
<h:outputStylesheet library="css" name="style.css"></h:outputStylesheet>
</h:head>

There is no problem in importing CSS file

Problem description

i have tried

I have tried the following methods in css file to load an image

  1. background:url(images/default.gif);
  2. background:url(#{resource['images:default.gif']});
  3. background:url(#{resource['images/default.gif']});

But I couldn't find the solution yet.

Updated Solution

Upvotes: 4

Views: 4469

Answers (1)

Daniel
Daniel

Reputation: 37051

You can use the UnmappedResourceHandler by OmniFaces to solve that

This resource handler will produce unmapped URLs like /javax.faces.resource/css/style.css. This has the major advantage that the developer don't need the #{resource} EL expression anymore in order to properly reference relative URLs to images in CSS files.

Or take a look at the similar question/answer over here: Prevent suffix from being added to resources when page loads

Upvotes: 6

Related Questions