【问题标题】:ExpressionLanguage (EL) Not Working as expectedExpressionLanguage (EL) 未按预期工作
【发布时间】:2012-08-20 15:21:47
【问题描述】:

我正在创建具有以下代码的 Web 应用程序。

<p:commandButton ajax="false" 
 style="#{patentInfo.photoType.contains('application')?
 'visibility:visible;width:200px;height:200px;
  background-image: url(DisplayImage?mainID=tempo1&amp;id=#{patentInfo.photoType});
  background-repeat: no-repeat;background-size: 100% 100%;'
 :
 'visibility:hidden;width:2px;height:2px;'}">

我正在将使用 Java 类的背景图像设置为DisplayImage,并将参数传递给mainID=tempo1&amp;amp;id=#{patentInfo.photoType}。在 java 中,我打印 mainID & id 用于测试目的。

DipalyImage.java

String mainID = request.getParameter("mainID");
String id = request.getParameter("id");
System.out.println("mainID=="+mainID+", id=="+id);

patentInfo.photoType 将保存数据为application/pdf

问题出在我传递的背景图像参数上。

  1. 当我使用background-image: url(DisplayImage?mainID=tempo1&amp;amp;id=#{patentInfo.photoType}); & print mainID & id 时,我得到的值如下。

    mainID=temp1 & id=

    我没有得到任何身份证件.....

  2. 当我使用background-image: url(DisplayImage?mainID=tempo1&amp;amp;id=patentInfo.photoType); & print mainID & id 时,我得到的值如下。

    mainID=temp1 & id=patentInfo.photoType

我在这里做错了什么?

我期望输出为mainID=temp1 & id=application/pdf

【问题讨论】:

    标签: java jsf jsf-2 el


    【解决方案1】:

    问题是你的 el 中有 #{ ... #{} ...}

    试试这样的:

    &lt;p:commandButton ajax="false" style="#{patentInfo.photoType.contains('application')?'visibility:visible;width:200px;height:200px;background-image: url(DisplayImage?mainID=tempo1&amp;amp;id='.concat(patentInfo.photoType).concat(';background-repeat: no-repeat;background-size: 100% 100%;'):'visibility:hidden;width:2px;height:2px;'}"&gt;

    【讨论】:

    • 不工作...错误是javax.faces.view.facelets.TagAttributeException: /showThumbnailss.xhtml @51,378
    • 哦。我忽略了:更新了答案。
    • 是的,我后来也发现了。但是,现在图像没有出现,Java 部分没有被调用......不知道为什么:(
    • 我遇到了问题...您在;background-repeat 之前缺少)(您没有关闭网址
    • 感谢一个 TON 人...你救了我!!!并在这里学习了如何使用 concat ......我曾经在 EXCEL 中使用 concat 但这里没有......再次感谢......
    猜你喜欢
    • 2021-06-04
    • 2022-01-24
    • 2015-05-11
    • 2020-05-15
    • 2014-10-31
    • 2018-02-12
    • 2014-01-20
    • 2015-01-13
    • 2013-08-01
    相关资源
    最近更新 更多