spring
  • jsp
  • spring-mvc
  • jstl
  • 2013-07-30 56 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... 
    
    相關問題