How to get Form data as a Map in Spring MVC controller?

You can also use @RequestBody with MultiValueMap e.g. @RequestMapping(value=”/create”, method=RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) public String createRole(@RequestBody MultiValueMap<String, String> formData){ // your code goes here } Now you can get parameter names and their values. MultiValueMap is in Spring utils package

When to use javax.inject.Provider in Spring?

In cdi, Providers are used to inject objects of narrower scope into a more broadly-scoped bean, e.g., if a session-scoped bean needs access to a request scoped object it injects a provider and then a method, which is running in a request, calls provider.get() to obtain a local variable reference to the appropriate request-scoped object. … Read more

Spring security. How to log out user (revoke oauth2 token)

Here’s my implementation (Spring OAuth2): @Controller public class OAuthController { @Autowired private TokenStore tokenStore; @RequestMapping(value = “/oauth/revoke-token”, method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public void logout(HttpServletRequest request) { String authHeader = request.getHeader(“Authorization”); if (authHeader != null) { String tokenValue = authHeader.replace(“Bearer”, “”).trim(); OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue); tokenStore.removeAccessToken(accessToken); } } } For testing: curl -X GET -H “Authorization: … Read more

Neither BindingResult nor plain target object for bean name available as request attr [duplicate]

Make sure that your Spring form mentions the modelAttribute=”<Model Name”. Example: @Controller @RequestMapping(“/greeting.html”) public class GreetingController { @ModelAttribute(“greeting”) public Greeting getGreetingObject() { return new Greeting(); } /** * GET * * */ @RequestMapping(method = RequestMethod.GET) public String handleRequest() { return “greeting”; } /** * POST * * */ @RequestMapping(method = RequestMethod.POST) public ModelAndView processSubmit(@ModelAttribute(“greeting”) Greeting … Read more

How to inject in @FacesValidator with @EJB, @PersistenceContext, @Inject, @Autowired

JSF 2.3+ If you’re already on JSF 2.3 or newer, and want to inject CDI-supported artifacts via e.g. @EJB, @PersistenceContext or @Inject, then simply add managed=true to the @FacesValidator annotation to make it CDI-managed. @FacesValidator(value=”emailExistValidator”, managed=true) JSF 2.2- If you’re not on JSF 2.3 or newer yet, then you basically need to make it a … Read more