My own primefaces p:commanButton icon

元气小坏坏 提交于 2019-11-29 04:25:10

Zbyszek, these are the steps I took to get the output below. Based on your comment, I'm assuming that's what you're after.

Note: My picture's name was test.jpg and it was in the following directory resources/images/test.jpg. Also the style rule you provided was placed in resources/css/style.css. The size of my image was 25 x 17 (but I doubt that's important. I'm just saying this in case you're thinking the icon is too small).

In <h:head> make sure you have (Maybe you forgot to add this and the styles weren't being applied ?)

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

My <p:commandButton> (change as needed, it was just a quick mock up)

<p:commandButton value="Cancel" icon="ui-icon-myCancel" /> 

and your rule

.ui-icon-myCancel{
    background-image: url("#{resource['images/test.jpg']}") !important;
}

This simple url() version also works on Primefaces 6.1:
.ui-icon-myCancel{background-image: url(img/cancel.gif)!important;}
(if you put the icon file to web/img folder and the css file is in web folder)

But it rounds the corners of icon therefore I use this solution:

.ui-icon-myCancel{background-image: url(img/cancel.gif)!important;  
                  border-radius: 0px!important;}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!