JSF show icon without Button

送分小仙女□ 提交于 2019-12-30 04:51:08

问题


Hi guys I want to show the icons without buttons but it doesn't work. I get the following message: no Mime-Type was Found. The two icons are default icons from Primefaces.

I use JSF 2.1 and primefaces 3.5

<h:graphicImage rendered="#{!task.IS_SEEN}" name="ui-icon-mail-closed"/>
<h:graphicImage rendered="#{task.IS_SEEN}" name="ui-icon-mail-closed"/>

If i use buttons it would work or can I set that the button can not be pressed

<p:commandButton rendered="#{!task.IS_SEEN}" icon="ui-icon-mail-closed" />
<p:commandButton rendered="#{task.IS_SEEN}" icon="ui-icon-mail-open" />

回答1:


If you want just a clickable image that trigger an action in the backing bean I suggest wrapping a graphic image in a h:commandLink.

<h:commandLink rendered="#{!task.IS_SEEN}" value="" action="#{YourBean.myAction}">
    <h:graphicImage  value="your-image-here"/>
</h:commandLink>

If you want easy to use, nice, vectorial icons I suggest you to check Font Awesome http://fontawesome.io/icons/ as well.

To use Font Awesome just include the following line in your <h:head>:

<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"></link>

Then you can easily put the icons inside commandLinks in this simple way:

<h:commandLink rendered="#{!task.IS_SEEN}" value="" action="#{YourBean.myAction}">
    <i class="fa fa-envelope"></i>
</h:commandLink>



回答2:


Also you need specify css class ui-icon like this:

<h:panelGroup styleClass="ui-icon ui-icon-mail-closed" />



回答3:


those are in fact CSS classes that point to a sprite file, so technically they are not icons.

try using:

<h:panelGroup styleClass="ui-icon-mail-closed" rendered="#{!task.IS_SEEN}" />

and if there's a need style it accordingly with padding.



来源:https://stackoverflow.com/questions/21054979/jsf-show-icon-without-button

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