如何将2个字符串与< c:if>?进行比较 [英] How to compare 2 strings with <c:if>?

查看:162
本文介绍了如何将2个字符串与< c:if>?进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试相应地显示< h:outputText> < h:commandLink> 支持bean返回的String属性。
我在比较字符串时遇到问题..
这是插图:

I am trying to display a <h:outputText> or <h:commandLink> accordingly to a String property returned by a backing bean. I am having problems when comparing the strings.. Here is the illustration:

<c:if test='#{column.header ne "Details"}'>
     <h:outputText value="#{recordTable[column.property]}"/><br/>
</c:if>
<c:if test='#{column.header eq "Details"}'>
     <h:commandLink value="#{column.header}"
                    action="#{searchBean.goToWarehouse}"/><br/>
</c:if>

但是比较不起作用。这是正确的方法吗?
可以在没有< jsp:useBean ....> 的情况下完成,如下所示: JSP示例

However the comparisons are not working. Is this the correct way to do it?? Can it be done without the <jsp:useBean....> as done in: JSP sample

感谢您的帮助

推荐答案

您似乎在< h:dataTable> 中使用此功能。仅在视图构建时间内评估JSTL标记,而不是在视图渲染时间期间评估。归结为:JSTL首先从上到下运行,然后将生成的结果交给JSF再次从上到下运行。目前,在JSF数据表中评估JSTL标记,JSTL无法使用数据表的迭代项( var 属性中的项)。因此测试结果总是 false

You seem to be using this in a <h:dataTable>. The JSTL tags are evaluated during view build time only, not during view render time. It boils down to this: JSTL runs from top to bottom first and then hands the produced result over to JSF to run from top to bottom again. At the moment the JSTL tags are evaluated inside a JSF datatable, the datatable's iterated item (the one in var attribute) isn't available to JSTL. Hence the test result is always false.

只需使用JSF组件的呈现属性。

Just use JSF component's rendered attribute instead.

<h:outputText value="#{recordTable[column.property]}" rendered="#{column.header ne 'Details'}"/>
<h:commandLink value="#{column.header}" rendered="#{column.header eq 'Details'}" action="#{searchBean.goToWarehouse}"/>
<br/>

以下是一些如何利用呈现属性:

Here are some more examples how you could utilize the rendered attribute:

<h:someComponent rendered="#{bean.booleanValue}" />
<h:someComponent rendered="#{bean.intValue gt 10}" />
<h:someComponent rendered="#{bean.objectValue == null}" />
<h:someComponent rendered="#{bean.stringValue != 'someValue'}" />
<h:someComponent rendered="#{!empty bean.collectionValue}" />
<h:someComponent rendered="#{!bean.booleanValue and bean.intValue != 0}" />
<h:someComponent rendered="#{bean.enumValue == 'ONE' or bean.enumValue == 'TWO'}" />






与具体问题无关,Roseindia是不是最好的JSF学习资源。我建议去其他资源。


Unrelated to the concrete problem, Roseindia is not the best JSF learning resource. I'd recommend to head to other resources.

这篇关于如何将2个字符串与&lt; c:if&gt;?进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆