When to Use the Preview Tool for Tiles

I am new to JSP and Tiles, as well as to Java. We are currently replicating our site, but I am confused when something needs to be placed in preparation for viewing or from the controller.

For example, on the current page I'm working on, a fragment will be displayed for pagination, including the content type (X of Y content-type). My initial plan was to use the View Preparationer to transfer the data sent by the controller (HashMap), and output a couple of attributes for pagination, but an employee told me that this should be done in the controller.

If so, then what is the point of view viewer? I'm just a little confused. I checked the Tiles docs and they are pretty simple / unusable.

Can someone give me the correct usage example to prepare for viewing?

+4
source share
1 answer

The controller is designed to perform business operations or transactional logic. That is, in response to a user action, the application must perform one or more actions, and then decide which view to perform. This is why it is called the controller because it β€œcontrols” the application flow. When the controller completes its task, changes in the data should be visible to the user. However, preparing this data for display is not the task of the controller. Just make sure that the necessary actions are completed and that the data is available.

In this case, your jsp pages will display data and display them. As far as I understand, the preparation tool for viewing helps you take into account some aspects of the presentation, so preparation that can be done in several different views can be done by the preparer.

Thus, the example in the menu preparation docs is a good use case. Menus are sometimes dynamic, in the sense that it depends on the state of the system, which is accurately displayed to the user. Suppose you want to display a link to enter the menu when the user is not logged in and did not remove this link from the menu when the user is logged in. Instead of encoding this logic on every page that the menu should display, you can use ViewPreparer, which generates a menu that implements any necessary logic. This viewer can be linked to multiple pages.

Think of it more as manipulating data for viewing, rather than business logic.

+4
source

All Articles