I have some problems to configure iReports, I´m using iReport4.8.0 (I tried iReport4.7.1 before and the same problem happened) and grails ggts 3.0.0.
I have a domain class called Consulta in a package called consultas, I want to list them and create a report using ireports, I´ve followed the steps I found in a book: Beginning Groovy
and Grails From Novice to Professional CHAPTER 9 it says that create a report from groovy clases is very easy (in theory it is) you just have to create a jar with the classes compiled and place it in the reports lib directory, then select "javabeans set data source option from data connections where the only field to fill is the name, it says to set the others blank, when I test it an error pop-up appears saying ClassNotFoundError, I'm sure there are some missing steps but i don't know which.
in my consulta controller I have this code:
def report ={
def consultas = Consulta.list()
chain(controller: "jasper", action: "index", model: [data: consultas], params:params)
}
and I think jassper plugins are OK.
Related
I'm trying to write a grails plugin that can view files. Actually, I'm just trying to upgrade this one here... https://github.com/intelligrape/File-Viewer-Grails-Plugin to grails4, and get it working in my app.
Anyway, after I get it working in the app, I visit http://localhost:8080/file/index and I get this error:
URI
/file/index
Class
javax.servlet.ServletException
Message
Could not resolve view with name '/plugins/file-explorer-0.1/file/fileList' in servlet with name 'grailsDispatcherServlet'
This occurs when the controller does this...
def index(String filePath) {
Map model = [locations: fileLocations.locations]
// blah blah
render(view: "/file/fileList", model: model, plugin: 'fileExplorer')
}
The render() method is called (I checked in the debugger). I also tried removing the plugin: parameter, but it made no difference.
Now if I run the plugin as a standalone app (by going to that folder, and running "grails run-app", then it works as expected, and http://localhost:8080/file/index renders the view as one would expect.
This all leads me to believe that the plugin is basicly working and installed into my app EXCEPT the view component, which for whatever reason cannot find the views from a plugin.
If you want to know what the source looks like, it's basically what you see here:.. https://github.com/intelligrape/File-Viewer-Grails-Plugin Except I've renamed it from FileViewer to FileExplorer.
I'm using grails 4.1.0.M5 I don't know if it could be a bug in this version or what.
It seems that I should have had
plugin: 'filexplorer'
instead of
plugin: 'fileExplorer'
I could have sworn I tried this already. I guess the thing is it can be confusing which name to use where as far as plugins, as in the build.gradle name, the name in the *Plugin.groovy, the name in settings.gradle, the package name etc. Anyway, somehow I screwed up.
I'am new to grails, I wanted to make use of Dynamic Controller Plugin (http://grails.org/plugin/dynamic-controller) in my project.
I am using grails version 3.2.11
I've added the dependency as directed on the page. It downloads the dependency in the form of zip, I can see it in External libraries. But when I am trying to import two classes (as directed on http://burtbeckwith.com/blog/?p=1041 Linking to existing Controller Actions
approach)
import com.burtbeckwith.grails.plugins.dynamiccontroller.ControllerClosureSource
import com.burtbeckwith.grails.plugins.dynamiccontroller.DynamicControllerManager
it gives " unable to resolve class" error. Please suggest what am I doing wrong here. Thanks!
You're trying to install a Grails 2 plugin in a Grails 3+ app, but that's not possible since they're not compatible. Grails 2 plugins must be upgraded and reworked to be used in Grails 3, and there's no plan to do so for this plugin.
I would say take a look at the URL Mappings & Embedded variables in the grails documentation.
https://docs.grails.org/3.2.11/guide/single.html#embeddedVariables
For example:
static mappings = {
"/blog/$topic"(controller: "blog")
}
which gives you a feeling like you are dynamically declaring actions.
And the topic variable is accessible through GrailsParameterMap params object # controller.
With this you can construct url like:
www.mysite.com/blog/football
www.mysite.com/blog/tvshow
www.mysite.com/blog/etc
Edit: you can also take a look at Dynamic Controller and Action Names [https://docs.grails.org/3.2.11/guide/single.html#_dynamic_controller_and_action_names]
IMPORTANT ---> ... it looks like this is a currently known bug in Grails 3.1.1 (Issue #9729) Apparently its been fixed in 3.1.2 ...
--- My Original Post is Below ---
It appears as though no views are generated when executing a dynamically scaffolded controller. I'm using Grails 3.1.1 (w/ scaffolding plugin specified in dependencies), JDK 8, all running on OSX...
My test case is a very simple 'Book' example with the following domain class and controller...
// Domain Class...
package scaffoldtest
class Book {
String name
String author
static constraints = {
}
}
// Controller (scaffolded)...
package scaffoldtest
class BookController {
static scaffold = Book
}
When I issue a run-app command and navigate to http://localhost:8080/book/index I get the following exception...
Error 500: Internal Server Error
URI: /book/index
Class: javax.servlet.ServletException
Message: Could not resolve view with name 'index' in servlet with name 'grailsDispatcherServlet'
...and FWIW, I also cannot see any sign of the generated view files down the "/build" tree... Also, and again FWIW, I believe I've read somewhere that dynamic scaffolding was temporarily removed during the initial versions of Grails 3, but my understanding (and the Grails manual concurs) is that dynamically generated views were put back in. In any case, I'm not seeing why the above dynamic scaffolding example doesn't work...
FYI, that bug should be fixed in Grails 3.1.2, which was released earlier today. See the changelog at https://github.com/grails/grails-core/issues?q=milestone%3Agrails-3.1.2.
I am new to Grails and I like it very much. I want to place my classes in packages like org.company.project.module.model. Its quite painful for to me to repeat create-domain-class <package>.<class_name>. Is there something like "package templates" or can I somehow "enter" (like grails cd org.comopany...) and then just write Class names (grails Person will be generated in ./ location)? Is that possible or should I use copy paste design pattern?
Thanks in advance for any help.
If I understood your question, you are looking for default package name for your domain classes. In your config.groovy file there is a line saying:
grails.project.groupId = appName
if you give it an appName, Grails will use that as the default package name when it generates the artifacts.
grails.project.groupId = 'com.example.yourpackagename'
If you now create a domain class by default it will locate it under com/example/yourpackagename.
UPDATE
It is not required to use Grails commands like create-domain-class or other commands to create artifacts. These are all just classes that you can manually create. Just create a file and duplicate it in the same package.
UPDATE
Grails interactive mode (when you type grails) for some of the commands by pressing tab it will type ahead the unique portion of the package name.
UPDATE for Grails 3.0
The setting has moved into conf/application.yml:
grails:
profile: web
codegen:
defaultPackage: com.example.yourpackagename
Update: as of Grails 1.3.6 one has access to the full domain from Gant scripts.
From the Grails 1.3.6 release notes:
You can now run one or more Groovy scripts from the commandline using the run-script command, e.g.
grails run-script [path-to-script-1] [path-to-script-2]...[path-to-script-n]
This works around the issue in Gant scripts where you can't conveniently access application classes since they're not available in the classpath when the scripts start.
Hi all,
I am new to using Grails (in a real project) and I have a one-off script I need to execute that reads a file and then populates my database.
I wanted the script to run in the context of my grails app, so I used the create-script command. I now understand that makes it a 'Gant' script. The reason for doing so was that I thought it would allow me easy access to all the grails domain good-ness, so that i would be able to do something like this easily:
Car car = new Car(model: 'bar', brand: 'Ford')
car.save()
Here, Car is one of my domain classes and the strings 'bar' and 'Ford' I have retrieved from my file.
The start of my script looks like this:
import com.foo.Car
grailsHome = Ant.project.properties."environment.GRAILS_HOME"
includeTargets << new File ( "${grailsHome}/scripts/Bootstrap.groovy" )
target(main: "a script for storing cars") {
depends(bootstrap, classpath) // code dealing with the file with cars follows
Surprisingly, groovy gives me a java.lang.NoClassDefFoundError: com.foo.Car when I execute the script with the command grails LoadCars
Am I taking the wrong approach, or is there something more simple I am doing wrong?
Any help is appreciated
i know the scripts are useful, and I will probably get hate mail for even suggesting it, but I have just incorporating this kinda of stuff directly into my application in the past.
I have a flag set in my configuration which indicates if the data should be bootstrapped, if so, the bootstrap code looks for a comma delimited file at startup and calls a service method to load up the data.
I've updated the grails run-script Gant script (referred to by Jared above) to work with grails 1.3.5. I'd been meaning to do it for a while, but this question nudged me into finally getting around to it).
Just download the script described in the post, save it in your grails "scripts" directory and you can then run your own groovy script to bootstrap data with:
grails run-script script-path/boostrapMyDataIntoApp.groovy
I've had to do this and you have to create a special script to allow you to access GORM from a standard grails script. See this question for more info. I'm not sure what the current status of the script is under grails 1.3 but the author of the script posted in the comments.
Hans, there are several choices here, assuming you are not out to polish the GANT scripting chops 8^)
So assume that you are doing some integration-mode TDD, correct?
Have you looked into the db-stuff plugin? Actually that one leverages the open source package (extension of the JUnit project) called dbUnit, which is also an outstanding choice, for both Java and Groovy projects.
*db-stuff <0.3.0> -- db schema managment and data import/export. Generate generic schema files and import or export base/seed/test data into your database.
I have traditionally done this as well in the BootStrap depending on the environment - and I try to never let those domain assumptions / constraints get too far out of synch. with my schema.
Here's the canon I'm talking about :
class BootStrap {
def init = { servletContext ->
if (GrailsUtil.environment.equals( GrailsApplication.ENV_DEVELOPMENT )) {
log.info( "Loading sample data for 2010 models..." );
new Car( manufacturer: new Manufacturer( name: "Toyota" ), model: "Prius" )
new Car( manufacturer: new Manufacturer( name: "GM" ), model: "Volt" )
//...