s:message 태그 설명

spring 2014. 9. 25. 09:26

<s:message code=""/>

 

해당 태그의 경우 spring태그중 message 태그를 이용해서 정해진 파일의 메시지를 출력 하는데 사용 되어 집니다.

작업중인 프로그램 에서는 아래의 설정을

 

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">  

<property name="basename" value="classpath:messages/message"/> 

<property name="defaultEncoding" value="UTF-8"/> 

</bean>  

 

/main/resources/config/hibernate/applicationContext-hibernate.xml에 추가해서 사용하고 있습니다.

 

(classpath:messages/message 이 부분의 내용은 메시지 파일의 경로가 /main/resources/messages/message_ko.porperties 

이렇게 되어 있는 경우 /messages 폴더 하위의 파일들중 message_ 로 시작하는 파일명의 파일을 메시지 파일로 사용하겠다는 

의미 입니다.

 

ko 와 en의 구분의 경우 applicationContext-hibernate.xml 파일의

 

<bean id="localeChangeInterceptor"

class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">

<property name="paramName" value="lang" />

</bean>

 

<bean id="localeResolver"

class="org.springframework.web.servlet.i18n.CookieLocaleResolver">

<property name="defaultLocale" value="#{config['language']}" />

</bean>

 

설정에 의해서 처리가 되고 있습니다.

localeChangeInterceptor의 내용은 parameter로 넘어오는 내용중 lang 이라는 값이 있는 경우 해당 값을 사용한다는 뜻이고

localeResolver의 내용은 config['language'] 즉 /main/resources/config/program/config.properties의 

내용중 language key에 해당하는 값을 기본으로 설정 하겠다는 이야기로 lang 파라미터가 넘어오면 해당하는 언어 파일로 없다면 config.properties 의 language key에 해당하는 파일을 사용 하겠다는 뜻으로 보시면 됩니다.

 

<--- 이부분중 properies를 사용하지 않는 경우 고정 값을 사용 하거나 다른 방식의 설정 파일을 이용해도 상관 없습니다.

 

사용시 jsp페이지 상단에

 

<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>

부분을 추가후 <s:message code="common.button.tip.alt"/> 같이 사용하면 해당 key에 맞는 

/main/resources/messages/message_ko.porperties파일의 내용이 출력 되게 됩니다.

 

s:message의 속성

 code

 fmt:message의 key에 해당

 arguments 

 리소스 번들의 메시지에 {0}, {1} 같은 기호 자리에 들어갈 값을 나열

 argumentSeparator 

 rguments 속성에 값을 구분하는 기호, 기본은 콤마(',') 

 text 

 code에 해당하는 메시지가 리소스 번들에 없을 때 사용될 메시지

해당 attr이 없고 code에 해당하는 데이터가 없는경우 error발생

 message 

 MessageSourceResolvable 인터페이스를 구현한 객체 또는 MessageSourceResolvable를 나타내는 spel 식. 에러 메시지를 표시하려고 한다면 필요하겠죠.

 htmlEscape 

 true일 때 HTML 엔티티를 인코딩

 javaScriptEscape 

 true일 때 자바스크립트 문자열로 인코딩 

 var  

 fmt:message와 동일

 scope  

 mt:message와 동일

 

반응형

'spring' 카테고리의 다른 글

aspect bofore 관련  (0) 2016.07.01
sessionFactory annotatedClasses/packagesToScan 방식  (0) 2015.07.27
spring+hsqldb 사용설정  (0) 2015.07.15
스프링 관련 문서  (0) 2015.03.05
스프링 버전 변경시 에러 사항(3.1.1->3.2.1)  (0) 2015.03.03
Posted by 질주하는구
,