How can I make use of customized icons in PrimeFaces?

不问归期 提交于 2019-12-19 09:56:16

问题


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,


回答1:


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" />



回答2:


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 :)



来源:https://stackoverflow.com/questions/11120311/how-can-i-make-use-of-customized-icons-in-primefaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!