1

how to set background image in jsf.i want to set (imag.jpg)as background. the images

are placed at resouces/images/imag.jpg

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> <h:head> <title>JSF Example</title> <style> .Bimage{background-image:url("resources/images/imag.jpg"); } </style> </h:head> <h:body styleClass="Bimage"> <h:graphicImage library="images" name="download.jpg"> </h:graphicImage> <h3>JSF 2 Example</h3> <h:form> <h:inputText value="#{hello.name}"></h:inputText> </h:form> </h:body> </html> 
5
  • appropriate answer: stackoverflow.com/a/2033828/2459449 Commented Jun 2, 2014 at 9:30
  • thanks for tour reply..i changed like this <style> .Bimage{background-image:url("#{resources['images:image1.jpg']}"); } </style> but not getting Commented Jun 2, 2014 at 10:28
  • resource without s. And depending on what you have inside <style> tag, the definition CSS code should looke like: .Bimage{background-image:url("#{resource['images:image1.jpg']}");}. Better to copy-paste it. Commented Jun 2, 2014 at 10:40
  • <style> .Bimage{background-image:url("#{resource['images:image1.jpg']}");} </style> chaged like that also but not getting Commented Jun 2, 2014 at 11:23
  • The image name is "image1" or "imag" ? Commented Jun 2, 2014 at 13:47

1 Answer 1

4

Change the css .Bimage by the following code

.Bimage{ background-image:url(#{request.contextPath}/resources/images/imag.jpg); } 

or

.Bimage{ background-image:url(/Project_Name/resources/images/imag.jpg); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.