0

I have a commandLink primefaces with an internal graphicImage (JSF 2 with Primefaces 5).

Following code works fine:

<p:commandLink action="#{mybean.mymethod()}" process="@this">

   <h:graphicImage name="images/one.jpg" 
   rendered="#{myBean.test.size() == 0" />

</p:commandLink>

Unfortunately, I have any graphicImage in my application so I would like set image in a css class.

I think about something:

<p:commandLink action="#{mybean.mymethod()}" process="@this">

   <h:graphicImage styleClass="myClass" 
   rendered="#{myBean.test.size() == 0" />

</p:commandLink>

where my css file is following:

.myClass {
     background-image: url('/myApplication/resources/images/one.jpg');
}

but doesn't work.

Is it possible? Otherwise, how can I replace graphicImage component? I try with img tag or adding a class in commandLink component with a background-image but doesn't work.

Any idea?

Thanks.

Diaboliko
  • 231
  • 1
  • 5
  • 21

1 Answers1

1

You can do it with

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

And you can just use the styleClass directly on the p:commandLink (no need for the h:graphicImage).

More reading on the matter.

Community
  • 1
  • 1
Jaqen H'ghar
  • 4,305
  • 2
  • 14
  • 26
  • I had already seen your post. I try so this but doesn't work: ... where my css class is following: .myClass { background-image: url("#{resource['images/one.jpg']}") !important; } Using inspect from browser, I see myClass with background image correctly, but I don't see image... – Diaboliko May 09 '16 at 08:31
  • Perhaps because my commandLink is inside a datagrid? My structure complete is following: ... ... – Diaboliko May 09 '16 at 08:39
  • Do you include css with h:outputStylesheet? You must... if not what is the complete folder structure? – Jaqen H'ghar May 09 '16 at 16:44
  • I had done already. Using inspect from browser, I see myClass with background image correctly, but I don't see image on browser.. – Diaboliko May 10 '16 at 15:00
  • If I replace commandLink with commandButton works... probably commandLink doesn't load correctly images from resources... This questions is not never done... – Diaboliko May 12 '16 at 13:45
  • SOLVED also for commandLink. It's enough add width and height to class css because image probably is load with 0px – Diaboliko May 12 '16 at 13:56