입니다. Displaytag의 키에서 i18n 리소스를 가져 오는 http://displaytag.svn.sourceforge.net/viewvc/displaytag/trunk/displaytag/src/main/java/org/displaytag/localization/I18nWebworkAdapter.java?revision=1173&view=markup의 코드를 적용했습니다 (아래 코드 참조).ActionContext (i18n)에서 TextProvider를 가져 오는 가장 좋은 방법은
이것이 가장 깨끗한 접근법인지 궁금해하고 있습니다. (필자는 이터레이터를 싫어합니다.) 그러나 내가 볼 수있는 유일한 대안은 ActionInvocation (ActionContext.getContext(). getActionInvocation(). getAction())에서 Action을 가져오고 ActionSupport로 캐스팅하여 리소스 (TextProvider를 구현)를 가져 오는 것입니다. 이것은 매우 안전하지는 않지만 (action은 actionsupport를 확장하지 못할 수도 있습니다).
다른 의견이 있으십니까?
/**
* @see I18nResourceProvider#getResource(String, String, Tag, PageContext)
*/
public String getResource(String resourceKey, String defaultValue, Tag tag, PageContext pageContext)
{
// if resourceKey isn't defined either, use defaultValue
String key = (resourceKey != null) ? resourceKey : defaultValue;
String message = null;
OgnlValueStack stack = TagUtils.getStack(pageContext);
Iterator iterator = stack.getRoot().iterator();
while (iterator.hasNext())
{
Object o = iterator.next();
if (o instanceof TextProvider)
{
TextProvider tp = (TextProvider) o;
message = tp.getText(key, null, null);
break;
}
}
// if user explicitely added a titleKey we guess this is an error
if (message == null && resourceKey != null)
{
log.debug(Messages.getString("Localization.missingkey", resourceKey)); //$NON-NLS-1$
message = UNDEFINED_KEY + resourceKey + UNDEFINED_KEY;
}
return message;
}