當前位置: 首頁>>代碼示例>>Java>>正文


Java InternalResourceViewResolver.resolveViewName方法代碼示例

本文整理匯總了Java中org.springframework.web.servlet.view.InternalResourceViewResolver.resolveViewName方法的典型用法代碼示例。如果您正苦於以下問題:Java InternalResourceViewResolver.resolveViewName方法的具體用法?Java InternalResourceViewResolver.resolveViewName怎麽用?Java InternalResourceViewResolver.resolveViewName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.servlet.view.InternalResourceViewResolver的用法示例。


在下文中一共展示了InternalResourceViewResolver.resolveViewName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: tilesJstlView

import org.springframework.web.servlet.view.InternalResourceViewResolver; //導入方法依賴的package包/類
@Test
public void tilesJstlView() throws Exception {
	Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;

	StaticWebApplicationContext wac = prepareWebApplicationContext();

	InternalResourceViewResolver irvr = new InternalResourceViewResolver();
	irvr.setApplicationContext(wac);
	irvr.setViewClass(TilesJstlView.class);
	View view = irvr.resolveViewName("testTile", new Locale("nl", ""));

	MockHttpServletRequest request = new MockHttpServletRequest(wac.getServletContext());
	MockHttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
	wac.addMessage("code1", locale, "messageX");
	view.render(new HashMap<String, Object>(), request, response);

	assertEquals("/WEB-INF/jsp/layout.jsp", response.getForwardedUrl());
	ComponentContext cc = (ComponentContext) request.getAttribute(ComponentConstants.COMPONENT_CONTEXT);
	assertNotNull(cc);
	PathAttribute attr = (PathAttribute) cc.getAttribute("content");
	assertEquals("/WEB-INF/jsp/content.jsp", attr.getValue());

	assertEquals(locale, Config.get(request, Config.FMT_LOCALE));
	LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
	assertEquals("messageX", lc.getResourceBundle().getString("code1"));
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:29,代碼來源:TilesViewTests.java

示例2: tilesJstlViewWithContextParam

import org.springframework.web.servlet.view.InternalResourceViewResolver; //導入方法依賴的package包/類
@Test
public void tilesJstlViewWithContextParam() throws Exception {
	Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;

	StaticWebApplicationContext wac = prepareWebApplicationContext();
	((MockServletContext) wac.getServletContext()).addInitParameter(
			Config.FMT_LOCALIZATION_CONTEXT, "org/springframework/web/servlet/view/tiles/context-messages");

	InternalResourceViewResolver irvr = new InternalResourceViewResolver();
	irvr.setApplicationContext(wac);
	irvr.setViewClass(TilesJstlView.class);
	View view = irvr.resolveViewName("testTile", new Locale("nl", ""));

	MockHttpServletRequest request = new MockHttpServletRequest(wac.getServletContext());
	MockHttpServletResponse response = new MockHttpServletResponse();
	wac.addMessage("code1", locale, "messageX");
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));

	view.render(new HashMap<String, Object>(), request, response);
	assertEquals("/WEB-INF/jsp/layout.jsp", response.getForwardedUrl());
	ComponentContext cc = (ComponentContext) request.getAttribute(ComponentConstants.COMPONENT_CONTEXT);
	assertNotNull(cc);
	PathAttribute attr = (PathAttribute) cc.getAttribute("content");
	assertEquals("/WEB-INF/jsp/content.jsp", attr.getValue());

	LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
	assertEquals("message1", lc.getResourceBundle().getString("code1"));
	assertEquals("message2", lc.getResourceBundle().getString("code2"));
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:31,代碼來源:TilesViewTests.java


注:本文中的org.springframework.web.servlet.view.InternalResourceViewResolver.resolveViewName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。