需要帮助在命令按钮中显示图标图像
只是基本需求,但无法使其发挥作用。 我想要一个 primefaces 按钮来显示我的图像,而不需要任何文本。
但我得到的是一个仅包含 ^
字符的按钮,并且不显示图像,该图像的大小仅为 16x16。
所以,这是 primefaces 按钮:
<p:commandButton image="ui-icon-csv" title="CSV Document" ajax="false">
<p:dataExporter type="csv" target="gridRPBDetails"
fileName="#{tInputBean.exportFilename}" />
</p:commandButton>
这是 css 文件:
.ui-icon-csv {
background-image: url(images/csv_small.png);
}
这是为按钮生成的 html:
<button type="submit" onclick=";"
name="gridRPBDetails:j_idt82" id="gridRPBDetails:j_idt82"
class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
role="button" aria-disabled="false">
<span class="ui-button-icon-primary ui-icon ui-icon-csv"></span><span class="ui-button-text">CSV Document</span>
</button>
为了证明图像可访问,我尝试了这个 URL,确实它显示了图片:
http://albert:8080/mywebapp/faces/javax.faces.resource/images/csv_small.png
我使用 tomcat 7,这些我的依赖是什么:
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
知道哪里出了问题吗?
谢谢 !
Just a basic need but cannot get it to work.
I would like to have a primefaces button to display my image, without any text.
But what i get is a button that contains only a ^
character and does NOT displaying the image, which only has a size of 16x16.
So, this is the primefaces button :
<p:commandButton image="ui-icon-csv" title="CSV Document" ajax="false">
<p:dataExporter type="csv" target="gridRPBDetails"
fileName="#{tInputBean.exportFilename}" />
</p:commandButton>
This is the css file :
.ui-icon-csv {
background-image: url(images/csv_small.png);
}
And this is the generated html for the button :
<button type="submit" onclick=";"
name="gridRPBDetails:j_idt82" id="gridRPBDetails:j_idt82"
class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
role="button" aria-disabled="false">
<span class="ui-button-icon-primary ui-icon ui-icon-csv"></span><span class="ui-button-text">CSV Document</span>
</button>
And to prove the image accessible, i try this URL, and indeed it shows the picture :
http://albert:8080/mywebapp/faces/javax.faces.resource/images/csv_small.png
Im using tomcat 7, and these are my dependencies :
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
Any ideas what went wrong ?
Thank you !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
经过使用 firebug 的一些调查后,我发现罪魁祸首来自我定义的 CSS 内容。
这些是我为使这项工作顺利进行而做出的改变。
JSF 按钮:
CSS:
这是生成的 html:
谢谢!
After some investigation using firebug, i found out that the culprit is from the CSS stuff i defined.
So these are the changes i made to make this work.
The JSF button :
The CSS :
And here is the generated html :
Thank you !
在图标类名称之前写入
ui-widget
,.ui-state-default
不会使其在其他组件中可见,例如;
和write
ui-widget
before the icon class namethe
.ui-state-default
will not make it visible in other components like<p:menuitem/>
and<p:menuButton/>
Primefaces 提供
graphicImage
,如其 showcase-labs (损坏的链接):它在某种程度上对某人有用。
* 对于 PrimeFaces 5.2,请访问此展示实验室链接 。
请注意,在这种情况下,上述代码将不起作用。
Primefaces provide the
graphicImage
as shown in their showcase-labs (broken link):It can be useful in someway to someone.
* For PrimeFaces 5.2, follow to this showcase-labs link.
Note that, in that case, the above code wouldn't work.
使用
commandButton
时,png 文件大小必须为 16 x 16,这一点很重要,因为较大的图像可能无法正确显示,或根本不显示。When
commandButton
is used, is important that the png file size be 16 x 16, because a bigger image might no be displayed correctly, or not displayed at all.