3

PrimeFaces provides a lot of icons from jQuery themeroller. They're useful but I need to have some customized icons for my app. Suppose I have a <p:commandButton>:

<p:commandButton icon="ui-icon ui-icon-check" />

Since my CSS knowledge is very limited, I'd be very grateful if you could show me how I can put some customized icon into the label of the above button.

Best regards,

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Mr.J4mes
  • 9,168
  • 9
  • 48
  • 90

2 Answers2

6

You need to define your own css class:

.img-button-help { background-image: url('../images/help.png') !important; }

and then use this class in your p:commandButton:

<p:commandButton icon="img-button-help" />
Matt Handy
  • 29,855
  • 2
  • 89
  • 112
1

to create your own (user defined/customized) ui-icon in jsf primefaces follow these steps:

  1. My image name is "pencilfour.png", put it inside resources folder in webapp.
  2. Define your own icon with a new name inside "style" tag in your xhtml page:

    .uipencil-icon {

    width: 16px; 
    
        height: 16px;
    
        align:up;
    
        background-image: url(#{resource['img:pencilfour.png']})!important ; 
    }
    

you can modify with and height as per your requirement.

  1. Then you can use the defined icon with the command button
<p:commandButton 

icon="uipencil-icon"

    style="   vertical-align:middle;

    margin-right:10px;

  height:19px;

  width:19px;"

  </p:commandButton>

this will work, the only thing to take care about is providing the correct url: url(#{resource['img:pencilfour.png']})!important ; the syntax for url is imp to fetch the image on the command button :)

Olaia
  • 2,172
  • 25
  • 27