本文整理汇总了Java中org.springframework.web.context.support.StaticWebApplicationContext.addMessage方法的典型用法代码示例。如果您正苦于以下问题:Java StaticWebApplicationContext.addMessage方法的具体用法?Java StaticWebApplicationContext.addMessage怎么用?Java StaticWebApplicationContext.addMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.support.StaticWebApplicationContext
的用法示例。
在下文中一共展示了StaticWebApplicationContext.addMessage方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionSupportWithContextLoaderPlugIn
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void actionSupportWithContextLoaderPlugIn() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.addMessage("test", Locale.getDefault(), "testmessage");
final ServletContext servletContext = new MockServletContext();
wac.setServletContext(servletContext);
wac.refresh();
servletContext.setAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX, wac);
ActionServlet actionServlet = new ActionServlet() {
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
ActionSupport action = new ActionSupport() {
};
action.setServlet(actionServlet);
assertEquals(wac, action.getWebApplicationContext());
assertEquals(servletContext, action.getServletContext());
assertEquals("testmessage", action.getMessageSourceAccessor().getMessage("test"));
action.setServlet(null);
}
示例2: actionSupportWithRootContext
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void actionSupportWithRootContext() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.addMessage("test", Locale.getDefault(), "testmessage");
final ServletContext servletContext = new MockServletContext();
wac.setServletContext(servletContext);
wac.refresh();
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
ActionServlet actionServlet = new ActionServlet() {
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
ActionSupport action = new ActionSupport() {
};
action.setServlet(actionServlet);
assertEquals(wac, action.getWebApplicationContext());
assertEquals(servletContext, action.getServletContext());
assertEquals("testmessage", action.getMessageSourceAccessor().getMessage("test"));
action.setServlet(null);
}
示例3: dispatchActionSupportWithContextLoaderPlugIn
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void dispatchActionSupportWithContextLoaderPlugIn() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.addMessage("test", Locale.getDefault(), "testmessage");
final ServletContext servletContext = new MockServletContext();
wac.setServletContext(servletContext);
wac.refresh();
servletContext.setAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX, wac);
ActionServlet actionServlet = new ActionServlet() {
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
DispatchActionSupport action = new DispatchActionSupport() {
};
action.setServlet(actionServlet);
assertEquals(wac, action.getWebApplicationContext());
assertEquals(servletContext, action.getServletContext());
assertEquals("testmessage", action.getMessageSourceAccessor().getMessage("test"));
action.setServlet(null);
}
示例4: dispatchActionSupportWithRootContext
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void dispatchActionSupportWithRootContext() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.addMessage("test", Locale.getDefault(), "testmessage");
final ServletContext servletContext = new MockServletContext();
wac.setServletContext(servletContext);
wac.refresh();
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
ActionServlet actionServlet = new ActionServlet() {
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
DispatchActionSupport action = new DispatchActionSupport() {
};
action.setServlet(actionServlet);
assertEquals(wac, action.getWebApplicationContext());
assertEquals(servletContext, action.getServletContext());
assertEquals("testmessage", action.getMessageSourceAccessor().getMessage("test"));
action.setServlet(null);
}
示例5: testInternalResourceViewResolverWithJstl
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
public void testInternalResourceViewResolverWithJstl() throws Exception {
Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;
MockServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.addMessage("code1", locale, "messageX");
wac.refresh();
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setViewClass(JstlView.class);
vr.setApplicationContext(wac);
View view = vr.resolveViewName("example1", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "example1", ((JstlView) view).getUrl());
view = vr.resolveViewName("example2", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "example2", ((JstlView) view).getUrl());
MockHttpServletRequest request = new MockHttpServletRequest(sc);
HttpServletResponse response = new MockHttpServletResponse();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
Map model = new HashMap();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, request, response);
assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
assertTrue("Correct rc attribute", request.getAttribute("rc") == null);
assertEquals(locale, Config.get(request, Config.FMT_LOCALE));
LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
assertEquals("messageX", lc.getResourceBundle().getString("code1"));
}
示例6: testInternalResourceViewResolverWithJstlAndContextParam
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
public void testInternalResourceViewResolverWithJstlAndContextParam() throws Exception {
Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;
MockServletContext sc = new MockServletContext();
sc.addInitParameter(Config.FMT_LOCALIZATION_CONTEXT, "org/springframework/web/context/WEB-INF/context-messages");
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.addMessage("code1", locale, "messageX");
wac.refresh();
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setViewClass(JstlView.class);
vr.setApplicationContext(wac);
View view = vr.resolveViewName("example1", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "example1", ((JstlView) view).getUrl());
view = vr.resolveViewName("example2", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "example2", ((JstlView) view).getUrl());
MockHttpServletRequest request = new MockHttpServletRequest(sc);
HttpServletResponse response = new MockHttpServletResponse();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
Map model = new HashMap();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, request, response);
assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
assertTrue("Correct rc attribute", request.getAttribute("rc") == null);
assertEquals(locale, Config.get(request, Config.FMT_LOCALE));
LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
assertEquals("message1", lc.getResourceBundle().getString("code1"));
assertEquals("message2", lc.getResourceBundle().getString("code2"));
}
示例7: setViewProperties
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
private void setViewProperties(AbstractJasperReportsView view) {
view.setUrl("/org/springframework/ui/jasperreports/DataSourceReport.jasper");
StaticWebApplicationContext ac = new StaticWebApplicationContext();
ac.setServletContext(new MockServletContext());
ac.addMessage("page", Locale.GERMAN, "MeineSeite");
ac.refresh();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);
view.setApplicationContext(ac);
}
示例8: getView
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
protected AbstractJasperReportsView getView(String url) throws Exception {
AbstractJasperReportsView view = getViewImplementation();
view.setUrl(url);
StaticWebApplicationContext ac = new StaticWebApplicationContext();
ac.setServletContext(new MockServletContext());
ac.addMessage("page", Locale.GERMAN, "MeineSeite");
ac.refresh();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);
view.setApplicationContext(ac);
return view;
}
示例9: lookupDispatchActionSupportWithContextLoaderPlugIn
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void lookupDispatchActionSupportWithContextLoaderPlugIn() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.addMessage("test", Locale.getDefault(), "testmessage");
final ServletContext servletContext = new MockServletContext();
wac.setServletContext(servletContext);
wac.refresh();
servletContext.setAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX, wac);
ActionServlet actionServlet = new ActionServlet() {
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
LookupDispatchActionSupport action = new LookupDispatchActionSupport() {
@Override
protected Map getKeyMethodMap() {
return new HashMap();
}
};
action.setServlet(actionServlet);
assertEquals(wac, action.getWebApplicationContext());
assertEquals(servletContext, action.getServletContext());
assertEquals("testmessage", action.getMessageSourceAccessor().getMessage("test"));
action.setServlet(null);
}
示例10: lookupDispatchActionSupportWithRootContext
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void lookupDispatchActionSupportWithRootContext() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.addMessage("test", Locale.getDefault(), "testmessage");
final ServletContext servletContext = new MockServletContext();
wac.setServletContext(servletContext);
wac.refresh();
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
ActionServlet actionServlet = new ActionServlet() {
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
LookupDispatchActionSupport action = new LookupDispatchActionSupport() {
@Override
protected Map getKeyMethodMap() {
return new HashMap();
}
};
action.setServlet(actionServlet);
assertEquals(wac, action.getWebApplicationContext());
assertEquals(servletContext, action.getServletContext());
assertEquals("testmessage", action.getMessageSourceAccessor().getMessage("test"));
action.setServlet(null);
}
示例11: tilesJstlView
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的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"));
}
示例12: tilesJstlViewWithContextParam
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的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"));
}