Codota Logo
Rendering
Code IndexAdd Codota to your IDE (free)

How to use
Rendering
in
org.springframework.web.reactive.result.view

Best Java code snippets using org.springframework.web.reactive.result.view.Rendering (Showing top 19 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Charset c =
  • Codota IconString charsetName;Charset.forName(charsetName)
  • Codota IconCharset.defaultCharset()
  • Codota IconContentType contentType;contentType.getCharset()
  • Smart code suggestions by Codota
}
origin: spring-projects/spring-framework

@Test
public void defaultValues() {
  Rendering rendering = Rendering.view("abc").build();
  assertEquals("abc", rendering.view());
  assertEquals(Collections.emptyMap(), rendering.modelAttributes());
  assertNull(rendering.status());
  assertEquals(0, rendering.headers().size());
}
origin: spring-projects/spring-framework

@Test
public void redirectWithAbsoluteUrl() throws Exception {
  Rendering rendering = Rendering.redirectTo("foo").contextRelative(false).build();
  Object view = rendering.view();
  assertEquals(RedirectView.class, view.getClass());
  assertFalse(((RedirectView) view).isContextRelative());
}
origin: spring-projects/spring-framework

@Test
public void httpHeaders() throws Exception {
  HttpHeaders headers = new HttpHeaders();
  headers.add("foo", "bar");
  Rendering rendering = Rendering.view("foo").headers(headers).build();
  assertEquals(headers, rendering.headers());
}
origin: spring-projects/spring-framework

@Test
public void modelAttributes() throws Exception {
  Foo foo = new Foo();
  Bar bar = new Bar();
  Rendering rendering = Rendering.view("foo").modelAttributes(foo, bar).build();
  Map<String, Object> map = new LinkedHashMap<>(2);
  map.put("foo", foo);
  map.put("bar", bar);
  assertEquals(map, rendering.modelAttributes());
}
origin: spring-projects/spring-framework

@Test
public void viewName() {
  Rendering rendering = Rendering.view("foo").build();
  assertEquals("foo", rendering.view());
}
origin: spring-projects/spring-framework

@Test
public void model() throws Exception {
  Map<String, Object> map = new LinkedHashMap<>();
  map.put("foo", new Foo());
  map.put("bar", new Bar());
  Rendering rendering = Rendering.view("foo").model(map).build();
  assertEquals(map, rendering.modelAttributes());
}
origin: spring-projects/spring-framework

returnValue = Rendering.view("account").modelAttribute("a", "a1").status(status).header("h", "h1").build();
String expected = "account: {a=a1, id=123}";
ServerWebExchange exchange = testHandle("/path", returnType, returnValue, expected, resolver);
origin: spring-projects/spring-framework

@Test
public void header() throws Exception {
  Rendering rendering = Rendering.view("foo").header("foo", "bar").build();
  assertEquals(1, rendering.headers().size());
  assertEquals(Collections.singletonList("bar"), rendering.headers().get("foo"));
}
origin: spring-projects/spring-framework

HttpStatus status = render.status();
if (status != null) {
  exchange.getResponse().setStatusCode(status);
exchange.getResponse().getHeaders().putAll(render.headers());
model.addAllAttributes(render.modelAttributes());
Object view = render.view();
if (view == null) {
  view = getDefaultViewName(exchange);
origin: spring-projects/spring-framework

@Test
public void modelAttribute() throws Exception {
  Foo foo = new Foo();
  Rendering rendering = Rendering.view("foo").modelAttribute(foo).build();
  assertEquals(Collections.singletonMap("foo", foo), rendering.modelAttributes());
}
origin: daggerok/spring-5-examples

 @PostMapping({ "/", "/404" })
 public Rendering post(@RequestParam(required = false, name = "name") final Optional<String> name) {

  final String result = name.orElse("World");

  return Rendering.view("index")
          .modelAttribute("name", result)
          .build();
 }
}
origin: spring-projects/spring-framework

@Test
public void redirectWithPropagateQuery() throws Exception {
  Rendering rendering = Rendering.redirectTo("foo").propagateQuery(true).build();
  Object view = rendering.view();
  assertEquals(RedirectView.class, view.getClass());
  assertTrue(((RedirectView) view).isPropagateQuery());
}
origin: daggerok/spring-5-examples

@Bean
RouterFunction<ServerResponse> routes() {
 return
   route(GET("/api/v1/messages"),
      request -> ok().contentType(request.headers()
                        .accept()
                        .contains(TEXT_EVENT_STREAM)
                      ? TEXT_EVENT_STREAM : APPLICATION_STREAM_JSON)
              .body(Flux.zip(
                Flux.interval(Duration.ofSeconds(1)),
                messages.findAll())
                   .map(Tuple2::getT2)
                   .share(), Message.class))
     .andRoute(POST("/api/v1/messages"),
          request -> ok().contentType(APPLICATION_JSON)
                  .body(request.bodyToMono(Message.class)
                        .flatMap(messages::save), Message.class))
     .andRoute(GET("/"),
          request -> ok().render("index",
                      Rendering.view("index")
                          .modelAttribute("name", "Max")
                          .build()
                          .modelAttributes())
     );
}
origin: daggerok/spring-5-examples

@GetMapping({ "/", "/404" })
public Rendering index(@RequestParam(required = false, name = "name") final Optional<String> name) {
 final String result = name.orElse("World");
 return Rendering.view("index")
         .modelAttribute("name", result)
         .build();
}
origin: spring-projects/spring-framework

@Test
public void defaultValuesForRedirect() throws Exception {
  Rendering rendering = Rendering.redirectTo("abc").build();
  Object view = rendering.view();
  assertEquals(RedirectView.class, view.getClass());
  assertEquals("abc", ((RedirectView) view).getUrl());
  assertTrue(((RedirectView) view).isContextRelative());
  assertFalse(((RedirectView) view).isPropagateQuery());
}
origin: snicoll-demos/smart-meter

@GetMapping("/")
public Rendering home() {
  return Rendering
      .view("index")
      .modelAttribute("zones", this.zoneDescriptorRepository.findAll())
      .build();
}
origin: snicoll-demos/smart-meter

@GetMapping(path = "/zones/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Rendering streamZoneEvents() {
  Flux<ElectricityMeasure> events = this.measuresCollector
      .getElectricityMeasures()
      .filter(measure -> measure.getPower() == 0);
  ReactiveDataDriverContextVariable eventsDataDriver =
      new ReactiveDataDriverContextVariable(events, 1);
  return Rendering.view("zone :: #events")
      .modelAttribute("eventStream", eventsDataDriver)
      .build();
}
origin: snicoll-demos/smart-meter

@GetMapping("/zones/{zoneId}")
public Mono<Rendering> displayZone(@PathVariable String zoneId) {
  PageRequest pageRequest = PageRequest.of(0, this.historySize,
      Sort.by("timestamp").descending());
  Flux<PowerGridSample> latestSamples = this.powerGridSampleRepository
      .findAllByZoneId(zoneId, pageRequest);
  return this.zoneDescriptorRepository.findById(zoneId)
      .switchIfEmpty(Mono.error(new MissingDataException(zoneId)))
      .map(zoneDescriptor -> Rendering
          .view("zone")
          .modelAttribute("zone", zoneDescriptor)
          .modelAttribute("samples", latestSamples)
          .build());
}
origin: daggerok/spring-5-examples

 @GetMapping
 Rendering index() {
  return Rendering.view("index")
          .modelAttribute("message", Message.of("hello, la-la!"))
          .modelAttribute("messages", new ReactiveDataDriverContextVariable(
            Flux.zip(
              Flux.interval(Duration.ofSeconds(1)),
              Flux.just(
                Message.of("and one"),
                Message.of("and two"),
                Message.of("and three"),
                Message.of("and four!"))
            ).map(Tuple2::getT2),
            1
          ))
          .build();
 }
}
org.springframework.web.reactive.result.viewRendering

Javadoc

Public API for HTML rendering. Supported as a return value in Spring WebFlux controllers. Comparable to the use of ModelAndView as a return value in Spring MVC controllers.

Controllers typically return a String view name and rely on the "implicit" model which can also be injected into the controller method. Or controllers may return model attribute(s) and rely on a default view name being selected based on the request path.

Rendering can be used to combine a view name with model attributes, set the HTTP status or headers, and for other more advanced options around redirect scenarios.

Most used methods

  • view
    Create a new builder for response rendering based on the given view name.
  • modelAttributes
    Return attributes to add to the model.
  • headers
    Return headers to add to the response.
  • status
    Return the HTTP status to set the response to.
  • redirectTo
    Create a new builder for a redirect through a RedirectView.

Popular in Java

  • Finding current android device location
  • getExternalFilesDir (Context)
  • orElseThrow (Optional)
  • getContentResolver (Context)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • ArrayList (java.util)
    Resizable-array implementation of the List interface. Implements all optional list operations, and p
  • ConcurrentHashMap (java.util.concurrent)
    A hash table supporting full concurrency of retrievals and adjustable expected concurrency for updat
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now