Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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
Jsp 避免在JSTL中计算c:if标记内的代码_Jsp_Jsf_Jstl - Fatal编程技术网

Jsp 避免在JSTL中计算c:if标记内的代码

Jsp 避免在JSTL中计算c:if标记内的代码,jsp,jsf,jstl,Jsp,Jsf,Jstl,我需要为各种类使用一个模板,并且我试图避免对c:if中的代码求值,因为bean类只有在扩展特定类时才具有getPrintResource() 我正在努力 <c:if test="${bean instanceOf PrintableClass}">... <c:if test="${! empty bean.printResource}">... 。。。 ... 避免对该元素进行评估 <c:if test="${...}"> <tag:pri

我需要为各种类使用一个模板,并且我试图避免对c:if中的代码求值,因为bean类只有在扩展特定类时才具有
getPrintResource()

我正在努力

<c:if test="${bean instanceOf PrintableClass}">...

<c:if test="${! empty bean.printResource}">...
。。。
...
避免对该元素进行评估

<c:if test="${...}">
   <tag:printResource id="printBtn"
    rendered="#{bean.printable}"
    resource="#{bean.printResource}" 
       label="#{msg.print}">
   </tag:printResource>
</c:if>

唯一的结果是在*bean*


编辑 即使我能够为c:if构建有效的测试,属性
resource
仍将被评估为
属性“printResource”未找到。
我的问题是,如果测试是错误的,则避免对代码块求值


也许我的设计是错误的,或者这是不可能的…

谢谢

创建一个自定义EL函数来检查它。差不多

<c:if test="${myFn:isPrintResourcePossible(bean)}">

EL函数只是某个类中的静态方法,在标记库描述符中声明


有关教程,请参阅。

您可以检查bean是否是预期类的实例:

<c:if test="${bean.getClass().name =='my.package.PrintableClass'}">

或其他同等条件:

<c:if test="${bean['class'].simpleName eq 'PrintableClass'}">

关于您的编辑:如果测试为false,则不会对if中的块进行评估,应该不会有任何问题。