需要帮助在命令按钮中显示图标图像

发布于 2024-11-06 08:23:00 字数 1847 浏览 1 评论 0原文

只是基本需求,但无法使其发挥作用。 我想要一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

世界等同你 2024-11-13 08:23:00

经过使用 firebug 的一些调查后,我发现罪魁祸首来自我定义的 CSS 内容。

这些是我为使这项工作顺利进行而做出的改变。


JSF 按钮:

<p:commandButton image="ui-icon-xls" title="Excel Document" ajax="false">
    <p:dataExporter type="xls" target="gridRPBDetails" 
        fileName="#{tInputBean.exportFilename}" />
</p:commandButton>

CSS:

.ui-state-default .ui-icon-xls {
    background-image: url(images/excel_small.png);
}

这是生成的 html:

<button type="submit" title="Excel Document" onclick=";" 
  name="gridRPBDetails:j_idt81" id="gridRPBDetails:j_idt81" 
  class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" 
  role="button" aria-disabled="false">
    <span class="ui-button-icon-primary ui-icon ui-icon-xls"></span>
    <span class="ui-button-text">ui-button</span>
</button>

谢谢!

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 :

<p:commandButton image="ui-icon-xls" title="Excel Document" ajax="false">
    <p:dataExporter type="xls" target="gridRPBDetails" 
        fileName="#{tInputBean.exportFilename}" />
</p:commandButton>

The CSS :

.ui-state-default .ui-icon-xls {
    background-image: url(images/excel_small.png);
}

And here is the generated html :

<button type="submit" title="Excel Document" onclick=";" 
  name="gridRPBDetails:j_idt81" id="gridRPBDetails:j_idt81" 
  class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" 
  role="button" aria-disabled="false">
    <span class="ui-button-icon-primary ui-icon ui-icon-xls"></span>
    <span class="ui-button-text">ui-button</span>
</button>

Thank you !

雅心素梦 2024-11-13 08:23:00

在图标类名称之前写入 ui-widget

.ui-widget .ui-icon-xls {
    background-image: url(images/excel_small.png);
}

.ui-state-default 不会使其在其他组件中可见,例如 ;

write ui-widget before the icon class name

.ui-widget .ui-icon-xls {
    background-image: url(images/excel_small.png);
}

the .ui-state-default will not make it visible in other components like <p:menuitem/> and <p:menuButton/>

零時差 2024-11-13 08:23:00

Primefaces 提供 graphicImage,如其 showcase-labs (损坏的链接)

<p:commandLink ajax="false">  
    <p:graphicImage value="/images/excel.png" />  
    <p:dataExporter type="xls" target="tbl" fileName="cars" />  
</p:commandLink>  

它在某种程度上对某人有用。


* 对于 PrimeFaces 5.2,请访问此展示实验室链接
请注意,在这种情况下,上述代码将不起作用。

Primefaces provide the graphicImage as shown in their showcase-labs (broken link):

<p:commandLink ajax="false">  
    <p:graphicImage value="/images/excel.png" />  
    <p:dataExporter type="xls" target="tbl" fileName="cars" />  
</p:commandLink>  

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.

枫林﹌晚霞¤ 2024-11-13 08:23:00

使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文