Announcement Announcement Module
Collapse
No announcement yet.
Jstl fmt MessageFormat MessageSource (strange) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jstl fmt MessageFormat MessageSource (strange)

    Code:
    	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">	
    		<property name="basename"><value>messages</value></property>										
    	</bean>

    Code:
    <jsp&#58;useBean id="now" class="java.util.Date" />
    
      <fmt&#58;message key="nowkey">
        <fmt&#58;param value="$&#123;now&#125;" />
      </fmt&#58;message>
    messages.properties
    nowkey = hello {0, date, yyyyMM}

    and the result always be "hello 10/11/04 10:24 AM "

    modify the messages.properties file
    nowkey = hello222 {0, date, yyyyMM}

    and the result will be "hello222 10/11/04 10:24 AM "

    if I setBundle in jstl, the result is correct !

    it be "hello222 200410"

    Code:
    	<fmt&#58;bundle basename="messages"> 
          <fmt&#58;message key="nowkey"> 
                     <fmt&#58;param value="$&#123;now&#125;"> 
                  </fmt&#58;param> 
             </fmt&#58;message> 
    	</fmt&#58;bundle>
    how to resolve this problem?
    could I solve this problem without explicitly specify the bundle in every

    jsp file?

  • #2
    I'd suggest separating pure date formatting from the message.
    Code:
    helloKey=hello
    nowkey=yyyyMM
    Code:
        <fmt&#58;message key="nowkey" var="pattern"/>
        <fmt&#58;formatDate value="$&#123;now&#125;" type="date" pattern="$&#123;pattern&#125;"/>

    Comment

    Working...
    X