Taking an action AFTER rendering a view with Spring MVC - java

I have a Spring MVC app that uses JSP to render pages. Spring has a built-in concept of Interceptors that go off before and after the controllers are invoked, but the postHandle() call still happens before the actual rendering of the view. I have some cleanup that I want to do AFTER the JSP page completes its rendering. Is there any built-in place I can put that without resorting to adding Tomcat interceptors? I like my nice, contained Spring app.

use HandlerInterceptor.afterCompletion() that is triggered after view rendering.
(but ony if HandlerIntercpetor.preHandle() was sucefully completed and returned true)

Related

Vaadin 14 how to move the vaadin servlet to a different URL?

I have a pretty basic vaadin application running. The application is spring-boot backed and I defined some rest API.
I've added OpenAPI documentation using org.springdoc:springdoc-openapi-ui:1.4.4, which worked perfectly before adding vaadin.
After adding the vaadin dependencies as shown in the vaadin spring-boot tutorial, and creating a view (which works), the swagger UI is no longer reachable.
It seems to me that vaadin completely takes over all web requests. Digging deeper, I've found that vaadin registers a new servlet and catches all requests.
I don't find any docs on how to configure this -- I'd expect that one could configure vaadin such that it serves UI from a different path, say /ui or similar.
I've tried to set
vaadin:
url-mapping: "/ui/*"
in my application.yaml -- but this results in blank pages (no errors) for my vaadin views,
and the vaadin servlet does still take over /.
I use spring.boot 2.3.2.RELEASE, vaadin 14.3.1.
The value to override is (note the camelCase instead of the kebab-case):
vaadin:
urlMapping: /ui/*
Using the kebab-case did (does) not work. As expected, this is a bug. See https://github.com/vaadin/spring/issues/637
From the docs at the point of time:
You can set properties for Spring Boot in your application.properties file.
Example: Setting Spring URL mapping in application.properties.
vaadin.urlMapping=/my_mapping/*
By default, URL mapping is /*.
An additional servlet, such as /my_mapping/*, is required to handle the frontend resources for non-root servlets. The servlet can be defined in your application class. See this Application class for a example.
Source: https://vaadin.com/docs/v14/flow/spring/tutorial-spring-configuration.html#using-spring-boot-properties

Spring MVC bean data flow

I got task unfortunately from work to create page using spring mvc, but i never work with that. I have to do that web app with restricted specifications which are following:
JSP cannot contain javascript, java, jstl only spring mvc tag's, but it's not everything. Controller must containt vaiable's only inside methods, all methods can return only String or void, so I'm unable to use #ModelAttribute, ModelMap, Model to move data from one view to another.
Is it possible to create page with following rules? I dont realy know how beans work in Spring MVC, but it seems that it will doesnt work without it.

JSF with Spring Controllors

I am new to Spring and JSF,and I want to integrate JSF for the front end, and use Spring controller. Can Anyone give me a explanation or an example how this can be done?. Basically what I want is a form submission (which will create a Business object and feed it to the database) and navigate using controllers.
The required xml files ? and its element?
A Basic form( ex: Like a User registration )
Spring class with #Controller, and #RequestMapping etc.
I just want to know how the form submission works and the flow of that.
If you want to integrate Spring with JSF you don't need to use #Controller and #RequestMapping, those are for SpringMVC. JSF itself has navigation mechanism use that.
If you need example check Integrate Spring into JSF 2

harmony between webflow and Spring MVC Controllers

Spring 2.5.6SEC02
Spring Webflow 2.0.9
I have a normal flow in which I have a form in flow scope. I now want to call my annotated spring MVC #Controller and get access to the form information. I basically want to display details as a modal dialog box on the screen. I've been reading up on spring-js, but I'm not very familiar with it and it seems to want to incorporate dojo into my code.
Thanks in Advance.
You can keep the form in session scope instead, that way it is available both to webflow and other controllers. That will however mean that it is shared between tabs and possibly reused in later conversations (Though you can probably prevent that).
Another solution is passing the flow execution key to the controller and have the controller read it from the FlowExecutionRepository.

url-action mapping & routing in Spring MVC 3.0

I'm developing a web application using Spring MVC 3.0 and looking for a ready-made solution, if any, or a "best practices" reference for a url/action mapping and routing system that can achieve the following:
REST-friendly controller / method name to view mapping. The current mapping implementation translates the request to a view name, which may be problematic when using several parameters and is incompatible with REST urls
A service that accepts the name of a controller, a method and arguments values and renders the URL that's represented by them
Integration with Spring Security that can allow me to check for a given URL whether the current user is allowed to access it, so that I can decide whether or not to render a URL
A menuing system based on the above that can define menues composed of these actions and render them to page
Basically what I need is the ability to define URLs in one centralized place, so that changing a URL (during development; I'm aware of the don't-change-live-urls idea :) ) does not mean looking up and changing that URL in a zillion pages.
Any directions to such an existing solution / tutorial / guide would be great.
Thanjs
This is a feature I really miss in Spring MVC.
That's why I created the springmcv-router project, basically a port of PlayFramework's Router implementation in Spring MVC (HandlerMapping + HandlerAdapter).
I'm heavily using it in several real-world projects and the Router implementation itself is reliable.
Try using Spring Roo. It utilizes many best practices for spring MVC, and it has a scaffolding feature that automatically maintains a menu, jsp's and all the CRUD methods of a controller.
Setting up Spring Security with Roo is as simple as typing "security setup".
Hope this is helpful.

Categories