【问题标题】:JSTL choose not runJSTL 选择不运行
【发布时间】:2014-03-21 15:05:50
【问题描述】:

我会打印第一个链接。但是程序总是打印第二个。 我尝试将!= null 更改为not empty 等,但没有任何变化。

我打印我的对象abstractAttrezzatura.insieme,并且它不为null也不为空,那么为什么这段代码不起作用??

    <c:choose>
    <c:when test="${abstractAttrezzatura.insieme != null} ">    
    <a href="${urlInsieme}">${labelInsieme}  <img src="${urlTorna}" align="top" height="30" width="30"/></a>
</c:when>
<c:otherwise>
    <a href="${urlFoglioLavoro}">${labelFoglioLavoro}  <img src="${urlTorna}" align="top" height="30" width="30"/></a>
</c:otherwise>
</c:choose>

控制器:

@RequestMapping(value = "{id}", method = RequestMethod.GET)
public String show(@PathVariable("id") final Long id, final Model uiModel, final Locale locale, 
        @ModelAttribute("idFoglioLavoro") Long idFoglioLavoro) {
    AbstractVerbale  verbale = verbaleService.findById(id);
    uiModel.addAttribute("verbale", verbale);
    uiModel.addAttribute("abstractAttrezzatura", verbale.getAttrezzatura());
    uiModel.addAttribute("itemId", verbale.getId());
    uiModel.addAttribute("idFoglioLavoro", idFoglioLavoro);

    return "verbale/show";
}

【问题讨论】:

  • 向我们展示您在请求/会话/servlet/页面上下文中放置和属性名为abstractAttrezzatura 的位置。
  • 我不用那个,但我用的是模型
  • 向我们展示您如何使用Model
  • 你能输入什么 .getAttrezzatura() 对象吗?
  • 是一个 AbstractAttrezzatura 对象,是我的对象的一个​​抽象类。

标签: java spring jsp jstl el


【解决方案1】:

您可能想尝试“不为空”,例如:

<c:when test="${not empty abstractAttrezzatura.insieme} ">  

【讨论】:

  • 试一试,没有任何改变。
  • 我认为你最好尝试打印出价值,以确保你得到你所期望的。 或只是 ${abstractAttrezzatura.insieme} 看看这个值是否真的是你所期望的。
  • 是的,显示正确的值。我已经解决了,检查控制器并在视图中传递一个布尔值。我不喜欢它,但这是我找到的唯一解决方案。
猜你喜欢
  • 2012-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
  • 2011-02-10
  • 2016-10-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多