spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » GRAILS » Page 1
Gradle grails - how to exclude dependency based on environment?
It seems more to me like you want to INCLUDE a dependency based upon the environment. However, the approach will be the same either way. In your build.gradle file you have a 'dependencies' section. Since this is Groovy, it is code. The -PgrailsEnv value is used by gradle to specify the environment. Just use that: dependencies { // if no property, then gradle will be default to prod. So

Categories : Grails

Grails saved list not in dbconsole
Take a look at Grails documentation about associations. Focus on 'One to many' and 'Many to many' associations. You can find nice examples on how to declare association (static hasMany property) and add elements to them (addTo* method).

Categories : Grails

How can I test my Grails webapp that has a subdomain for each client?
We have a different way of achieving what we want (I for one would be interested in your UrlMappings solution). I wrote a Groovy trait (something like SubdomainAware) and every controller implements it. That trait then has a getter (something like getCustomer) that sniffs the domain from the request object and fetches the customer domain object (so in my controllers I can do things like User.find

Categories : Grails

Grails - get domain relationship id without fetching the whole object
You will need to enhance your domain to use GORM based mapping hints (given to Hibernate) to accomplish this. Your domain could look something like this: class A { static hasOne = [b: B] } class B { // stuff } Using the hasOne will allow Hibernate to manage the association and thus allows you to use the a.bId notation. Hope this helps.

Categories : Grails

how to set radio button for edit in grails
You may want to consider the radioGroup tag within Grails instead of manually authoring your radio buttons. However, if you decide to continue manually authoring your radio buttons you will need to account for selecting the current value. For example: <g:radio name="religion" value="muslim" checked="${radioButtonInstance?.religion.equals('muslim')}"/> In the above example you will notice

Categories : Grails

Get a service bean from Grails Holders class
Don't use Holders, and avoid pulling in dependencies. Use dependency injection, it's a Good Thing. Your src/groovy class is probably called from a controller, service, Quartz job, or some other Grails artifact that supports DI, right? If so, inject this service there, and when you call your src/groovy class, pass it as a method argument, or inject it once in a constructor or a setter. Even if it

Categories : Grails

Case-insensitive order on nested properties
I stumbled upon this question when trying to solve a similar issue related to sorting in grails. Maybe in the meanwhile a solution has already been found. If not, I wanted to suggest you tried the following: Foo.createCriteria().list() { createAlias("bar","_b") order("_b.name", (params.sortOrder == "asc")?"asc":"desc") } In this way you should be able to order instances of Foo by bar.na

Categories : Grails

How to get Get parameter from url in grails
The documentation shows you how to use params http://grails.org/doc/latest/ref/Controllers/params.html So params.key

Categories : Grails

Setting Heap size and other JVM parameters in Grails 2.2.4
I will assume that you are needing to change these settings for development and doing so is accomplished using GRAILS_OPT environment variable. Consult instructions for your OS on how to do so. From the Grails documentation: It's often useful to provide custom arguments to the JVM when running Grails commands, in particular with run-app where you may for example want to set a higher maxim

Categories : Grails

Will Slf4j annotation work in Grails?
All Grails artefacts (controllers, domain classes, taglibs, services, etc.) have a static logger field (named log) added to them automatically. Classes in src/groovy also have a logger field named log added to them automatically, but in this case, the logger is non-static. Therefore, the only time you'll need to explicitly add a logger is if you want to log something statically from a src/groovy

Categories : Grails

grails: How to derive custom views while keeping generated ones for reference
There's no particular reason why you need to create your own controllers, why not just add additional actions into the scaffolded controllers and have them render views with different names to the scaffolded views. Then your custom actions/views can happily co-exist with those created by scaffolding.

Categories : Grails

Grails ClassNotFoundException: org.apache.log4j.Logger
I had exactly the same stacktrace, and solved it by adding a slf4j log4j bridge to ensure that all transitive or plugins still depending on log4j will now log through logback: runtime "org.slf4j:jul-to-slf4j:1.7.7" runtime "org.slf4j:log4j-over-slf4j:1.7.7" Hope that helps.

Categories : Grails

Custom Grails Constraint doesn't seem to work
It looks your constraint is good. I use something very similar in my Url Without Scheme Validator Plugin, in class UrlWithoutSchemeConstraint and it works like a charm in recent Grails (2.3.x, 2.4.x). However, I never tried to access it at runtime, so I'd try to investigate this area. For example, have you tried ThatClass.constraints.someProperty.busca?

Categories : Grails

Grails IntegrationSpec rollback after each test case possible?
Integration tests are running in a transaction that is rolled back after test execution by default. In the docs it says: Integration tests differ from unit tests in that you have full access to the Grails environment within the test. Grails uses an in-memory H2 database for integration tests and clears out all the data from the database between tests. For further information see Grails Docs

Categories : Grails

Grails params.controller bug
Rather than using params.controller you could use the controllerName variable. This should always be set to the name of the current controller, but will be empty for direct GSP requests because there is no controller involved

Categories : Grails

How to Create Controller and Views with diffrent name Grails scaffolding
Install the templates on the project with grails install-templates and change the name on src/templates/scaffolding/Controller.groovy: Example: class Admin${className}Controller { and the package name you can control on the create-scaffold-controller: From the docs: grails create-scaffold-controller org.bookstore.Book or change directly in the template with variables: <%=package org.admi

Categories : Grails

Passing values to input through g:each iteration
Assuming your model contains the following def myAction() { [value: ['TEST1', 'TEST2', 'TEST3']] } This should do it <g:each status="i" in="${value}" var="item"> <g:textField id="justATest${i}" name='justATest' value="${item}"> </g:each>

Categories : Grails

How to use spock to test a service with real transactions in Grails application?
Mocking In your test you're testing MemberService, which means you don't need to mock it. Just refer to it via service. Test Data This looks like unit test, not the integration one. So it doesn't use your database at all. What you need to do is to create the Member instance manually in test. You have it in your @Mock annotation, which is good. Now, create the object, preferably in given block

Categories : Grails

Grails logout button not working
Simply invalidating your session for spring security is probably not advisable. As there is a SecuritySession which also has cookies. It may be better to use whats provided by spring security already. import grails.plugin.springsecurity.SpringSecurityUtils redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl Then you can configure your default login url via the config opt

Categories : Grails

How to properly remove H2 from Grails
In your grails-app/conf/DataSources.groovy you probably have some references to the h2 Driver, e.g. dataSource { pooled = true jmxExport = true driverClassName = "org.h2.Driver" username = "sa" password = "" } Remove the dataSource configuration completely if you're not using any DB. If you're using a different DB, replace the h2 driver class name with the class name of the

Categories : Grails

Grails - Do Services have access to session?
if you want to code a great and scalable functionality you must use a design pattern. When like in your case you have a list of operations that depends on some conditional things or are governed by a process the right approach is to use Chain of Responsability pattern. I used it also in a grails application. I'll show you my solution The first step is to create an interface this is not a Service

Categories : Grails

Grails spring-security-ldap connecting to localhost:389
You should be getting a warning in the output telling you that you're using grails.plugins.springsecurity as the property prefix but that it's been changed in 2.0 to grails.plugin.springsecurity. Your custom properties are being ignored and only the defaults are being used.

Categories : Grails

how can i rollback all the transactions if one domain save fails?
withTransaction has nothing to do with the domain class it's called on, but it's a bit of a hack, because it lets you do silly things like transactional persistence in controllers. Controllers should focus on HTTP-related stuff, and delegate real work to services, which are conveniently transactional by default unless you disable it for a particular service. Move all database updates and business

Categories : Grails

Grails internationaliization with custom bundles
To answer your question you have to understand what Grails (well, Spring really) is doing to accomplish this. You are on the right path with the multiple files. What you have outlined there matches the documentation and will work. However, under the covers what is really being done is they are being combined into a single bundle (per language). So there is no need to tell Grails/Spring which b

Categories : Grails

Grails NPE on root context?
One problem you have is with the following: // ... render(view: "web/index") // ... render(view: "web/signin") // ... The problem with those is you are specifying a relative path. It will be relative to grails-app/views/web/ since you are in the Web controller. You could make them absolute like this... // ... render(view: "/web/index") // ... render(view: "/web/signin") // ... But

Categories : Grails

How to define custom table mapping by Config.groovy entry in Grails
I believe you can read the config variables right from your mapping block. So this line in the app consuming your plugin's Config.groovy grails.myplugin.useIndexForFoo = true Should allow you to have a configurable domain class, such as class Foo { String myString static mapping = { if (Holders.config?.grails?.myplugin?.useIndexForFoo) myString index: "myString_idx

Categories : Grails

Grails rollback withTransaction on save
When using transactions there are important considerations you must take into account with regards to how the underlying persistence session is handled by Hibernate. When a transaction is rolled back the Hibernate session used by GORM is cleared. This means any objects within the session become detached and accessing uninitialized lazy-loaded collections will lead to LazyInitializationExceptions.

Categories : Grails

Is Scribe sticking around for a while?
With the exception of hearing from the Scribe team it's nearly impossible to answer this question with a simple yes/no. However, I think it's better to look at it from this perspective to arrive at a valid answer. Does it meet your needs today? Do you have access to the source code? Does it have an active community? Do you have other options if you need to replace it in the future? Should you n

Categories : Grails

Grails and Spring Security Plugin: Redirecting user upon login based on roles
After looking at the source, I figured it out. The problem was that SavedRequestAwareAuthenticationSuccessHandler's method onAuthenticationSuccess would never reach the overridden method determineTargetUrl with the simple login scheme I was using( the default that is generated by the plugin ). I had to actually override onAuthenticationSuccess instead and put my logic there. The source in questio

Categories : Grails

Stop Grails compilation from showing dots
Grails does offer a switch on the console/command line to remove the dots from the output (and a few other fancy things). It's called --plain-output and it can be used as such: grails prod war --plain-output

Categories : Grails

Grails search owned objects by properties
In order to avoid (N+1) queries for lazy associations per a, you can use a criteria as: ObjA.withCriteria { b { eq 'someProperty', someValue } } or where queries: ObjA.where { b.someProperty == somevalue }.list() If you use something like a.b.findAllBsSuchThat(b.someproperty = somevalue) then you would be getting all b's for a and then filtering on the result. This will affec

Categories : Grails

Grails Criteria query with a condition on data
This will do? A.createCriteria().list{ or { eq 'propOver', search_input and { isNull 'propOver' eq 'propBase', search_input } } }

Categories : Grails

Grails - Websphere - No bean named 'springSecurityFilterChain' is defined
You won't find many xml files in a Grails app, pretty much just web.xml (and this is going away in Grails 3 since servlet 3.0 lets you do everything programmatically), and web-app/WEB-INF/applicationContext.xml and web-app/WEB-INF/sitemesh.xml. Installed plugins also have plugin.xml files. Most everything is configured with code. You don't say whether you're using the spring-security-core plugin

Categories : Grails


Recently Add
Grails: Can a config item(BuildConfig.groovy) inside environments block override a generic configuration?
Gradle grails - how to exclude dependency based on environment?
Grails saved list not in dbconsole
How can I test my Grails webapp that has a subdomain for each client?
Grails - get domain relationship id without fetching the whole object
how to set radio button for edit in grails
Get a service bean from Grails Holders class
Case-insensitive order on nested properties
How to get Get parameter from url in grails
Setting Heap size and other JVM parameters in Grails 2.2.4
Will Slf4j annotation work in Grails?
grails: How to derive custom views while keeping generated ones for reference
Grails ClassNotFoundException: org.apache.log4j.Logger
Custom Grails Constraint doesn't seem to work
Grails IntegrationSpec rollback after each test case possible?
Grails params.controller bug
How to Create Controller and Views with diffrent name Grails scaffolding
Passing values to input through g:each iteration
How to use spock to test a service with real transactions in Grails application?
Grails logout button not working
How to properly remove H2 from Grails
Grails - Do Services have access to session?
Grails spring-security-ldap connecting to localhost:389
how can i rollback all the transactions if one domain save fails?
Grails internationaliization with custom bundles
Grails NPE on root context?
How to define custom table mapping by Config.groovy entry in Grails
Grails rollback withTransaction on save
Is Scribe sticking around for a while?
Grails and Spring Security Plugin: Redirecting user upon login based on roles
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.