spring
  • jsp
  • spring-mvc
  • jstl
  • 2013-07-30 57 views 4 likes 
    4

    根据此post from 3 years ago在jstl标记中显示弹簧消息的唯一方法是将其包装在一个“工作”的<c:set var="someVar">中,但它看起来非常不理想。JSTL中的Spring消息标记

    快进3年,这仍然是处理这个问题的唯一方法吗?

    这里是我的代码

    作品,而不是 “理想”

    <c:set var="closeMessage"> 
        <spring:message code='lman.ilr.closeItemDetail'/> 
    </c:set> 
    <dsg:sidePanelContent closePanelText="${closeMessage}"> 
    

    不工作,返回<spring:message code='lman.ilr.closeItemDetail'/>

    <dsg:sidePanelContent closePanelText="<spring:message code='lman.ilr.closeItemDetail'/>"> 
    
    +0

    由于我不使用它,我不知道Spring MVC中取得了这3个来的进展。一种方法可以尝试检查“ResourceBundle”实例是否因某些请求属性不可用。如果是这样,那么你可以像使用'$ {bundleAttributeName ['lman.ilr.closeItemDetail']}''一样使用简单的EL。至少,JSF是这样工作的。 – BalusC

    +0

    呃,它只是标准Java SE的一部分,自年龄以后被封面下面的使用。如果没有这样的属性,你是否打算探索可用的请求属性? – BalusC

    回答

    7

    字符串春天消息的标签,就像fmt:message,具有可用于存储消息而不是显示消息的var属性。

    它总是有助于阅读the documentation。另外,你的错误信息可能来自于你忘记在JSP的顶部声明spring taglib。

    +0

    JB,错误的消息和工作/不理想在同一个JSP上,并声明了spring。 – zmanc

    +1

    @JBNizet感谢与的技巧,这对我很好! –

    2

    如果作参考,

    <c:choose> 
        <c:when test="${serviceVO.id eq 0}"> 
        <spring:message code="label.service.createservice" var="buttonName"/> 
        </c:when> 
        <c:otherwise> 
        <spring:message code="label.updateservice" var="buttonName"/> 
        </c:otherwise> 
    </c:choose> 
    
    <c:out value="${buttonName}"> //Prints the desired value... 
    
    相关问题