Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

3.9 render series method


May 14, 2021 JFinal manual



The render series method renders different types of views and returns them to the client. The types of views JFinal currently supports are:
FreeMarker, JSP, Velocity, JSON, File, Text, Html, and more. In addition to the view types supported by JFinal, you can extend view types indefinitely by inheriting render abstraction classes.


Typically, the view is rendered using the Controller.render method, and the visual class at Controller.render is set by constants in JFinalConfig.configConstant. ViewType determines that the setup method supports ViewType for FreeMarker, JSP, Velocity, and the default configuration for FreeMarker when not configured.


In addition, you can set the views used by Controller.render through constants.setMainRenderFactory, which is designed to extend views other than FreeMarker, JSP, and Velocity to the Controller.render method.

Suppose there is the following Controller mapping configuration in JFinalConfig.configRoute (Routes routes): routes.add ("/user", UserController.class, "/path"), render (String view) uses examples:

Method call

Describe

render(”test.html”)

Renders a .html called test, which has a full path of "/path/test.html"

render(”/other_path/test.html”)

Renders a view called test.html, which has a full path of "/other_path/test.html", i.e. an absolute path when the argument begins with "/".

Other render methods use examples:

Method call

Describe

renderFreeMarker(”test.html”)

Renders a view .html test, and the view type is

FreeMarker。

renderJsp(”test.html”)

Renders a .html named test, and the view type is Jsp.

renderVelocity(“test.html”)

Renders a view .html test, and the view type is Velocity.

renderJson()

Convert all variables set by Controller.setAttr (String, Object) into json data and render them.

renderJson(“users”, userList)

With "users" as the root, only the data in userList is converted to json

Data and render.

renderJson(user)

Convert the user object into json data and render it.

renderJson(“{\”age\”:18}” )

Render the json string directly.

renderJson(new String[]{“user”, “blog”})

Only properties set by setAttr ("user", user) and setAttr ("blog", blog) are converted to json and rendered. Other properties set with setAttr are not converted to json.

renderFile(“test.zip”);

Renders a file .zip test, which is typically used for file downloads

renderText(“Hello JFinal”)

Renders the plain text content Hello JFinal.

renderHtml(“Hello Html”)

Render html content "Hello Html."

renderError (404 , “test.html”)

Renders a file .html test and has a status of 404.

renderError (500 , “test.html”)

Renders a file .html test and has a status of 500.

renderNull()

If you do not render, you do not return data to the client.

render(new XmlRender())

Render with a custom XmlRender.

Attention:

1: IE does not support contentType as application/json, and IE prompts you to download the document when the ajax upload file is complete, and the solution is to make use of: render (new JsonRender().forIE()) or new JsonRender (params). This only happens when the IE browser ajax file is uploaded, and other normal ajax requests are ignored.

2: With the exception of the renderError method, the program does not return immediately after the method of the render series is called, and the return statement is required if the return needs to be returned immediately. Calling the render method multiple times in one action is only valid for the last time.