Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 有条件地呈现图标_Jsf_Primefaces - Fatal编程技术网

Jsf 有条件地呈现图标

Jsf 有条件地呈现图标,jsf,primefaces,Jsf,Primefaces,在Primefaces的Datatable中,我希望有条件地在某个列中插入一个图标 此列有两个值:1或0,如果为1,则使用检查图标;如果为0,则使用关闭图标 我已经尝试过使用“rendered”、“style”和“styleClass”,但它对我不起作用。要么输出读取值,要么不呈现任何内容(列为空) 有没有办法做到这一点 我传递了一部分代码: <p:column headerText="Vota" width="30" filterBy="#{vot.estado}"> &l

在Primefaces的Datatable中,我希望有条件地在某个列中插入一个图标

此列有两个值:1或0,如果为1,则使用检查图标;如果为0,则使用关闭图标

我已经尝试过使用“rendered”、“style”和“styleClass”,但它对我不起作用。要么输出读取值,要么不呈现任何内容(列为空)

有没有办法做到这一点

我传递了一部分代码:

<p:column headerText="Vota" width="30" filterBy="#{vot.estado}">
    <h:outputText value="#{vot.estado}" style="float:right #{vot.estado == 1 ? 'ui-icon-check' : 'ui-icon-close'}"/>
</p:column>

您可以将
呈现的
属性与输出文本本身一起使用,如下所示:

<p:column headerText="Vota" width="30" filterBy="#{vot.estado}">
     <h:outputText rendered="#{vot.estado == 1}" value="#{vot.estado}" style="float:right" styleClass="ui-icon-check"/>
     <h:outputText rendered="#{vot.estado != 1}" value="#{vot.estado}" style="float:right" styleClass="ui-icon-close"/>
</p:column>

您在“样式”属性中有图标信息,而它应该在“样式类”属性中,并且您还需要通用ui图标类。。因此,将您的代码更改为以下代码以使其正常工作

<p:column headerText="Vota" width="30" filterBy="#{vot.estado}">
    <h:outputText value="#{vot.estado}" style="float:right" styleClass="ui-icon #{vot.estado == 1 ? 'ui-icon-check' : 'ui-icon-close'}"/>
</p:column>


ui图标检查
ui图标关闭
是样式类。像您这样将其添加到style属性中是不起作用的,请将其添加到styleClass中(您可能需要添加一些其他类,在browser developer工具中使用这些类)为什么如此冗长?极大的改进。尝试直接在
h:outputText
上添加样式类?可能吧,但这样做不是更可读吗?将文本和图标分开?您甚至可以将其放入一个
h:outputText
中,就像在问题中已经尝试过的那样,但使用样式类而不是样式。。。
<p:column headerText="Vota" width="30" filterBy="#{vot.estado}">
    <h:outputText value="#{vot.estado}" style="float:right" styleClass="ui-icon #{vot.estado == 1 ? 'ui-icon-check' : 'ui-icon-close'}"/>
</p:column>