concept view in category spring

appears as: view, The view, view, views, views, A view
Spring in Action, Sixth Edition

This is an excerpt from Manning's book Spring in Action, Sixth Edition.

Spring comes with a powerful web framework known as Spring MVC. At the center of Spring MVC is the concept of a controller, a class that handles requests and responds with information of some sort. In the case of a browser-facing application, a controller responds by optionally populating model data and passing the request on to a view to produce HTML that’s returned to the browser.

In a Spring web application, it’s a controller’s job to fetch and process data. And it’s a view’s job to render that data into HTML that will be displayed in the browser. You’re going to create the following components in support of the taco creation page:

Spring Boot in Action

This is an excerpt from Manning's book Spring Boot in Action.

  • readersBooks()—Handles HTTP GET requests for /{reader} by retrieving a Book list from the repository (which was injected into the controller’s constructor) for the reader specified in the path. It puts the list of Book into the model under the key “books” and returns “readingList” as the logical name of the view to render the model.
  • 6.2. Defining views with Groovy Server Pages

    Up until now, we’ve been using Thymeleaf templates to define the view for the reading-list application. In addition to Thymeleaf, Spring Boot also offers Freemarker, Velocity, and Groovy-based templates. For any of those choices, all you must do is add the appropriate starter to your build and start writing templates in the templates/ directory at the root of the classpath. Auto-configuration takes care of the rest.

    Spring in Practice

    This is an excerpt from Manning's book Spring in Practice.

    InternalResourceViewResolver converts the logical view name to a physical path by taking the logical view name, prepending a configurable prefix, and appending a configurable suffix. By default, the prefix and suffix are empty, which means you have to specify full view paths instead of logical view names to use. Because you don’t usually want to specify full view paths from your controllers—that ties the controller too closely to the view—you’ll generally want to define your own InternalResourceViewResolver. Here’s a typical configuration:

    <bean class="org.springframework.web.servlet.view.
            InternalResourceViewResolver"
        p:prefix="/WEB-INF/jsp/"
        p:suffix=".jsp"/>

    If this resolver receives the logical view name contact, for example, it converts that to /WEB-INF/jsp/contact.jsp and then builds a corresponding view. The view is an InternalResourceView if JavaServer Pages Standard Tag Library (JSTL) isn’t on the classpath or else a JstlView if JSTL is present. InternalResourceViewResolver automatically detects the presence or absence of JSTL and selects the correct view type accordingly.

    Spring Roo in Action

    This is an excerpt from Manning's book Spring Roo in Action.

  • Views—Components that display information or provide ways to edit data. Commonly Java Server Pages or JSF Facelets.
  • Controllers—Accept incoming HTTP web requests and return responses, generally using views to present the data.
  • Web service layer—Some applications expose web services, using a convention such as SOAP or REST. These are analogous to web controllers and views and exist in the same layer as those in this diagram.
  • In this chapter we use a simple Roo shell command, web mvc controller, to install Spring’s MVC web framework, and generate a sample controller and view. Then we use web mvc scaffold to generate full web pages complete with create, read, update, delete, and searching capability. We review the scaffolding in depth so that you understand how it functions, and to prepare you for customizing the user interface in chapter 6.

  • View —A view is the output of a Spring MVC operation, a representation of the results of a given request. Views can access any object provided in the model, and can be written using a number of rendering technologies, such as JSP, Velocity, FreeMarker, or even using PDF or Excel. Spring Roo is configured to use XML-compliant JSPs, which are commonly referred to as JSPX views. Roo’s JSPX views are configured to use Apache Tiles, which is a layout engine that separates boilerplate code such as headers, footers, and other panels from the code specific to the view being rendered.
  • Figure 5.1 illustrates the interplay between the dispatcher servlet, controllers, models, and views.

    Figure 7.2. The JSF layout—course listing view