AEM:从 $PATH 获取当前语言环境
AEM: getting current locale from $PATH
我正在使用选择器 + 请求参数读取下拉列表的值。
/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=$PATH
$PATH
给了我 currentPath.path
。我可以使用路径获取当前语言环境。
例如:
/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=en-us
我如何才能 return 仅从 $PATH 中获取语言环境并将其传递给语言环境。这将解决问题。
使用 $PATH
检索语言环境
/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=$PATH
String compNodePath = (String) request.getParameter("locale");
String pagePath = StringUtils.substringBefore(compNodePath, "jcr:content");
PageManager pageMgr = request.getResourceResolver().adaptTo(PageManager.class);
Page page = pageMgr.getContainingPage(pagePath);
Locale pageLocale = page.getLanguage(false);
为此,页面属性中的语言字段应设置为合适的值。
Resource resource = resourceResolver.getResource(path);
if (resource != null) {
Page targetPage = resource.adaptTo(Page.class);
if (targetPage != null) {
Locale pageLocale = targetPage.getLanguage(true);
String countryLocale = pageLocale.getCountry();
}
}
我正在使用选择器 + 请求参数读取下拉列表的值。
/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=$PATH
$PATH
给了我 currentPath.path
。我可以使用路径获取当前语言环境。
例如:
/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=en-us
我如何才能 return 仅从 $PATH 中获取语言环境并将其传递给语言环境。这将解决问题。
使用 $PATH
检索语言环境/bin/services/myservlet.GET_DROPDOWN_VALUES.json?locale=$PATH
String compNodePath = (String) request.getParameter("locale");
String pagePath = StringUtils.substringBefore(compNodePath, "jcr:content");
PageManager pageMgr = request.getResourceResolver().adaptTo(PageManager.class);
Page page = pageMgr.getContainingPage(pagePath);
Locale pageLocale = page.getLanguage(false);
为此,页面属性中的语言字段应设置为合适的值。
Resource resource = resourceResolver.getResource(path);
if (resource != null) {
Page targetPage = resource.adaptTo(Page.class);
if (targetPage != null) {
Locale pageLocale = targetPage.getLanguage(true);
String countryLocale = pageLocale.getCountry();
}
}