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.
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]
When I create a RESTful API in Grails, I add #Resource(uri='env',formats=['multipart/form-data'] before the domain class. And then use grails generate-all domain_name to generate the controller and view.
However, in Eclipse there is an Java problem like
The project was not built due to "RequestEnvironmentController$_on_closure51 [in [Working copy] RequestEnvironment.groovy [in test.environment.manager [in grails-app/domain [in restful-api-for-tem]]]] does not exist". Fix the problem, then try refreshing this project and building it since it may be inconsistent.
Then I get rid of the annotation and the error disappears and the post method still works. I am confused, is the annotation necessary or not? If it is necessary, how can I remove the Java error?
When you use the #Resource annotation there is no need to create a controller because this will be automatically generated as per documentation
Simply by adding the Resource transformation and specifying a URI,
your domain class will automatically be available as a REST resource
in either XML or JSON formats. The transformation will automatically
register the necessary RESTful URL mapping and create a controller
called BookController.
After upgrading a grails app from version 2.2.2 to 2.3.2 and eventually 2.3.3, I noticed that some links that are previously working, now returns a 404 status.
To illustrate, here are the sample links and the corresponding URL mapping entry that was originally working in v2.2.2:
http://localhost:7080/pages/mytestpage
http://localhost:7080/pages/mytestpage.html
UrlMappings.groovy
static mappings = {
"pages/mytestpage"(controller: 'testController', action: 'testAction')
}
After upgrade, among the given links, the link below does not work anymore (i.e. the link with .html):
http://localhost:7080/pages/mytestpage.html
One way to fix this issue is by changing the URLMappings entry to as below:
UrlMappings.groovy (MODIFIED)
static mappings = {
"pages/mytestpage(.$format)?"(controller: 'testController', action: 'testAction')
}
My question is, is there a way to resolve this problem without having to update the URLMappings entry? Anybody who can explain how such mapping actually worked in version 2.2.2 will also be a great help. Thanks!
UPDATE
Using (.html)? instead of (.$format)? in UrlMappings.groovy works as well and was actually used.
Also, in this example the app server is being hit directly and web server is not used.
In Grails 2.2.x, the grails.mime.file.extensions = true setting along with the grails.mime.types controlled the extension in the URL. Basically, Grails ignored the extensions that are listed in the mime type and mapped the url to the controller accordingly.(thats why mytestpage.html works and not mytestpage.exe nor mytestpage.anything)
It appears that the above behavior was change in Grails 2.3.x+ to support the REST improvements. Even the default mappings in URLMappings.groovy have changed accrodingly
//Grails 2.2.x
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
to
//Grails 2.3.x
"/$controller/$action?/$id?(.${format})?"{
constraints {
// apply constraints here
}
}
Your solution seems to be the correct way to fix the issue
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.