How to specify validation group for @Valid?

The standard java @Valid annotation doesn’t support groups. However, Spring now includes an @Validated annotation which does the same job as @Valid, but allows you to specify which groups to use in the validation: @ModelAttribute(“myCandidate”) @Validated(UpdateGroup.class) Candidate myCandidate Note that this annotation is only available in Spring 3.1 and newer.

Spring MVC – Multiple submit button to a Form

if the form has these buttons specified: input type=”submit” class=”button” name=”save” value=”Save” input type=”submit” class=”button” name=”delete” value=”Delete” input type=”submit” class=”button” name=”cancel” value=”Cancel” you may direct to different url request according to button pressed with one controller. for cancel button, @RequestMapping(params = “cancel”, method = RequestMethod.POST) public String cancelUpdateUser(HttpServletRequest request) { return “redirect:/users.html”; } what request … Read more

Rails: access controller instance variable in CoffeeScript or JavaScript asset file

a couple of ways I have done this in the past put the data in hidden fields, access the data in js/coffee # single value <%= hidden_field_tag “foo_name”, @foo.name, { :id => “foo-name” } %> $(‘#foo-name’).val(); # when the ‘value’ has multiple attributes <%= hidden_field_tag “foo”, @foo.id, { :id => “foo”, “data-first-name” => @foo.first_name, “data-last-name” … Read more

Spring MVC Controller redirect using URL parameters instead of in response

I had the same problem. solved it like this: return new ModelAndView(“redirect:/user/list?success=true”); And then my controller method look like this: public ModelMap list(@RequestParam(required=false) boolean success) { ModelMap mm = new ModelMap(); mm.put(SEARCH_MODEL_KEY, campaignService.listAllCampaigns()); if(success) mm.put(“successMessageKey”, “campaign.form.msg.success”); return mm; } Works perfectly unless you want to send simple data, not collections let’s say. Then you’d have … Read more

passing JSON data to a Spring MVC controller

Add the following dependencies <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.7</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> <version>1.9.7</version> </dependency> Modify request as follows $.ajax({ url:urlName, type:”POST”, contentType: “application/json; charset=utf-8”, data: jsonString, //Stringified Json Object async: false, //Cross-domain requests and dataType: “jsonp” requests do not support synchronous operation cache: false, //This will force requested pages not to be cached by the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)