2012-04-19 76 views
2

我有<p:commandLink>的问题。我想让悬停效果,但我不能通过CSS加载图像到<p:graphicImage>带有图像的JSF commandLink

CSS:

.accountEditBtn { 
    background-image: 
    url('#{request.contextPath}/resources/image/pencil_black.png'); 
} 

JSF:

<p:commandLink 
    update="@form" 
    actionListener="#{someBean.someListener}"> 
    <h:graphicImage styleClass="accountEditBtn" /> 
</p:commandLink> 

我看到边境空矩形。

但是当我添加Alt键graphicImage的,我得到了像从替代文本...

凡我错了吗? 谢谢。 p.s.打字错误 - classType所 - >的styleClass

+0

刚一说明,但代替'背景图像:网址( '#{} request.contextPath /resources/image/pencil_black.png');'在CSS,你可以写'背景:网址(” #{resource ['image/pencil_black.png']}“);' – 2012-04-19 08:42:14

回答

6

尝试使用,而不是<h:graphicImage

<p:commandLink 
    styleClass="accountEditBtn" 
    update="@form" 
    actionListener="#{someBean.someListener}" 
</p:commandLink> 

的styleClass尝试此类

.accountEditBtn { background-image: url('../resources/image/pencil_black.png'); } 

B.T.W

不也是应该的图像?或者它是图像(文件夹名)

看看这个以及..如果你想用的commandButton图片:PrimeFaces icons

+0

工作...但只有当设置值=“”+白色空间:前;在CSS中。 primefaces 2.2.1 ..是错误还是我的错误? – MaximG 2012-04-19 11:15:14

+0

奇怪...不知道,它在3.0 + – Daniel 2012-04-19 11:24:34

2

你为什么不使用

<p:commandButton ... icon="yourbuttonstyleclass"/> 

,并在CSS

.yourbuttonstyleclass { 
background-image: url('../images/yourimage.png') !important; 
} 
+1

的工作方式你应该避免使用!重要的。 – waste 2013-08-23 08:39:53