grails-controller

Grails domain get(params.id) works in Controller.show() but not Contoller.edit()

半城伤御伤魂 提交于 2019-12-11 03:43:50
问题 So here's an interesting one. I've got a 2.1.1 Grails application with straigt-forward domains and controller with default scaffolding. My show() method works just find and retrieves the domain object with def quarterEndAdjustmentInstance = QuarterEndAdjustment.get(params.id) However, when I call the edit() method I get a java.lang.IllegalArgumentException - argument type mismatch on the exact same call def quarterEndAdjustmentInstance = QuarterEndAdjustment.findByID(params.id) I've confirmed

How can I substitute my own custom dynamic scaffolding methods

人走茶凉 提交于 2019-12-11 02:45:54
问题 My grails app has to define some additional behaviour for many of the standard dynamic scaffolding methods for each domain class. I know I can duplicate the methods I need to add to for each controller, and indeed that is what I currently do. This does mean that my custom code is obscured by the boilerplate scaffolding. I have tried importing and modifying the templates as well but they only seem to get involved if I generate static scaffolding in my controllers. Needless to say this doesn't

How to extend/override controller actions of plugins?

拈花ヽ惹草 提交于 2019-12-08 18:30:33
问题 The plugin (Nimble 0.3) I am using in my grails application, includes some controllers and associated actions. I want to change (slightly) some actions behavior , and I was wondering how I can achieve that. Can I create a child controller that inherits from my plugin controller and override some of the action implementation? Or, can I create another Controller with the same name as the plugin controller but located in a different package? Well actually what I really need to understand is :

Grails render() with a fragment parameter

匆匆过客 提交于 2019-12-08 00:05:21
问题 Is there a way to use render() with a fragment param so on page load it automatically scrolls to a specific part of the page? Similarly to how we can call redirect(controller: "book", action: "show", fragment: "profile") 回答1: You cannot pass it to render(), because by the time you're actually invoking render() , the URL has already been determined and mapped to your action; all render is doing is controlling what gets written back to the response. The fragment must already be in the URL

how to force https

旧巷老猫 提交于 2019-12-07 02:59:40
问题 I have a grails project. Right now, the user can access it either with HTTP or HTTPS. I would like to require that they can only access it through HTTPS. any ideas? I do have spring security core installed, if that can be of help thanks jason 回答1: Spring's core supports that: grails.plugins.springsecurity.secureChannel.definition = [ '/path/**': 'REQUIRES_SECURE_CHANNEL' ] 来源: https://stackoverflow.com/questions/7534844/how-to-force-https

Grails Command Object: How to load request.JSON into it?

两盒软妹~` 提交于 2019-12-06 19:10:45
问题 Question : is there a way to do automatic command object binding with request.JSON data? Given this simple Command object in my grails controller: class ProfileCommand{ int id String companyName static constraints = { companyName blank: false id nullable: false } @Override public String toString() { return "ProfileCommand{id=$id, companyName='$companyName'}"; } } and my controller method signature of: def update(ProfileCommand command) {...} How can I get request.JSON data into my command

Grails render() with a fragment parameter

坚强是说给别人听的谎言 提交于 2019-12-06 11:44:32
Is there a way to use render() with a fragment param so on page load it automatically scrolls to a specific part of the page? Similarly to how we can call redirect(controller: "book", action: "show", fragment: "profile") You cannot pass it to render() , because by the time you're actually invoking render() , the URL has already been determined and mapped to your action; all render is doing is controlling what gets written back to the response. The fragment must already be in the URL before the rendering controller action gets called. Here's an example: grails-app/controllers/MyController

How to access command objects from filter and is it possible at all?

人走茶凉 提交于 2019-12-06 06:42:49
I often write something like: def myAction{ MyActionCommand cmd -> if( cmd.hasErrors() ){ return render(status:HttpServletResponse.SC_BAD_REQUEST ); }else{ // actual action logic } So, I'd like to extract that common pattern into some reusable location. Filter looks like good candidate, but I can't find the way to get command object from the filter. Tryed something like this (in filters closure): formValidation( controller:'*', action:'*' ){ before = { cmd -> if( cmd.hasErrors() ){ response.sendError( HttpServletResponse.SC_BAD_REQUEST ); return false; }else{ return true; } } } Intersted in

Grails 2.4.2 - Dynamically referencing default datasource

ⅰ亾dé卋堺 提交于 2019-12-06 05:19:18
问题 This question has been partly answered here but there is still an issue with referencing the default datasource dynamically. I'm working on an internal application that allows developers to modify configuration settings for one of our multi-tenant applications and push those settings from dev to testing, staging and production. Each one of these will have their own datasource, and the Grails app will be installed on each developer's computer. The local datasource will be the default one, and

Grails - cross controller code, execute on every request

老子叫甜甜 提交于 2019-12-05 22:01:01
Is there a way of executing some piece of code before any controller action gets called? I need to set a session variable based on the value of a get parameter, without taking into account which controller gets called. Of course, once this processing is done, the request needs to follow its normal way to the corresponding controller/action. Thanks Sounds like you want to use a filter . e.g. grails-app/conf/MyFilter.groovy class MyFilter { def filters = { extractSomething(controller: '*', action: '*') { before = { session.setAttribute('foo', params['paramName']) } } } } filters are good if used