grails-controller

Reading out all actions in a Grails-Controller

时光毁灭记忆、已成空白 提交于 2019-12-18 16:54:24
问题 I need to read out all available actions from any controller in my web-app. The reason for this is an authorization system where I need to give users a list of allowed actions. E.g.: User xyz has the authorization for executing the actions show, list, search. User admin has the authorization for executing the actions edit, delete etc. I need to read out all actions from a controller. Does anyone has an idea? 回答1: This will create a List of Maps (the 'data' variable) with controller

How to do a Union SQL statement in HQL?

耗尽温柔 提交于 2019-12-17 16:44:19
问题 I'm trying to create a Union between two tables, using HQL (Hibernate Query Language). This SQL script works fine on my SQL server: SELECT COUNT(DISTINCT linkedin_id) as test, school_name FROM (SELECT * FROM alum_education UNION SELECT * FROM alum_connection_educations) AS UNIONS where school_name='some string' the problem is, when i try to run it in grails like this: def countOfEdu = AlumEducation.executeQuery("select count (distinct linkedinId ) as countOfEdu, schoolName as SchoolName from

How to change a class's metaClass per test

余生长醉 提交于 2019-12-13 03:05:13
问题 I'm using the ExpandoMetaClass to make a service always return success in an integration test but I would like to have one test that actually fails. Example use of ExpandoMetaClass: static { ExpandoMetaClass someService = new ExpandoMetaClass(Object, false) someService.accessAnotherSystem = { return 'success' } someService.initialize() SomeService.metaClass = someService } Note: currently the service isn't defined for the controller but since it's a spring bean referencing the class named

How to populate 2nd combobox(g:select) values on basis of 1st combobox(g:select)?

柔情痞子 提交于 2019-12-12 17:30:16
问题 I'm trying to load 2nd combobox ( g:select ) values on the selection of 1st combobox ( g:select ) value in GSP. Domain classes: class Person { String name static hasMany = [telephones:Telephone] } class Telephone { String tNumber Person person static belongsTo = [person:Person] } GSP: <td> <g:select id="person" name="selectedPersonId" from="${Person.list(sort:name, order:asc)}" value="name" optionValue="name" optionKey="id" noSelection="['0':'--Select--']" /> </td> <td> <g:select id=

Grails using ajax submit a form

无人久伴 提交于 2019-12-12 06:44:02
问题 I'm stacking with issues related to ajax in grails, please help! In domain book, I got book name and book type, then I generated a controller and view base on that domain. Then in update action of bookController , I use jquery to pop up input book name and book type, then I used ajax technique to update that book. I hope you got me. Here my code: For Update function def update(Long id, Long version) { def bookInstance = Book.get(id) if (!bookInstance) { flash.message = message(code: 'default

In Grails 3.2.4, controller that has an .async.task call in it sets request.asyncStarted() to true but doesn't render response

假装没事ソ 提交于 2019-12-12 02:18:57
问题 First off, this wasn't an issue in Grails 2.5.4. I'm making an angular AJAX call to my Grails controller and the Grails controller is never responding. The front end call looks something like this.. $http({ method: "GET", url: actionLink, params: {} }).then(function successCallback(response) { console.log("Yaaay, I got back with some sort of response"); }, function errorCallback(response) { console.log("ERROR PULLING DETAIL") }); I've confirmed that AJAX calls to other controllers that don't

Domain class not found in grails-app/domain

我的梦境 提交于 2019-12-11 14:18:06
问题 With Grails 2.3.4, and scaffold 2.0.1; no object appears in the index (list) page of the controllers. The views are being automatically created by grails official scaffolding plugin. I'm positive there actually are objects added, since when creating a object that needs another, the latter appears as an option in the former's creation page. What appears is the "main" layout and an empty table that would contain the actual data. One example of a domain class(Bairro) that doesn't appear in it's

Grails read from existing DB

寵の児 提交于 2019-12-11 12:17:14
问题 I want to fetch data from already existing database from another project into my Grails project and list the data. Should I be creating a domain controller for the already existing db? I know how to create domain-controller and use data migration plugin to update db but none of the books I read had any information on how to setup and read from an existing database. I'm using MySQL for my database. 回答1: Use the Reverse Engineer plugin to create domain classes from your existing database: http:

Using custom renderer in grails unit testing (and in general) on JSON content types

半腔热情 提交于 2019-12-11 08:19:59
问题 I am trying to get a custom JSON renderer for exceptions working in my REST api. I was able to get a custom marshaller working that did most of what I needed, but I would like to have control over the context that I don't have access to in the marshaller. The grails documentation shows how to write a custom renderer, and I have one that I think should work, but I can't use it during unit testing my REST controller. Grails docs: http://grails.org/doc/2.3.4/guide/webServices.html

Grails 2.3.3 namespaced controller render view

匆匆过客 提交于 2019-12-11 04:38:54
问题 For Grails 2.3.3, it allows same name controller in different package with namespaced controller according to http://grails.org/doc/latest/guide/theWebLayer.html#namespacedControllers So we have package like this: /admin/FooController /public/FooController To keep consistent we want the view package like this: /views/admin/foo/... /views/public/foo/... However, in the FooController action, if you don't hard code the render method. It will find the view in the /views/foo/index.... It seems it