Using Grails 2.0.4. In building emails, I use a lot of images with absolute paths. Each one results in an annoying log entry. Is there an easy fix? They DO exist, it just seems the resource plugin doesn't like absolute paths. This happens outside of localhost / dev environment too.
<img src="${resource(dir: 'images/brochure', file: 'arrow_up.png', absolute: 'true')}" alt="Up" />
results in
WARN resource.ResourceTagLib - Invocation of <r:resource> for a resource that apparently doesn't exist: http://localhost:8080/images/brochure/arrow_up.png
The solution that has been working with me for Grails 2.1.x and above (including the newest 2.3.x) is adding these entries to your log4j config block in Config.groovy - no other code changes needed.
log4j = {
//your other stuff ...
error 'grails.app.services.org.grails.plugin.resource'
error 'grails.app.taglib.org.grails.plugin.resource'
error 'grails.app.resourceMappers.org.grails.plugin.resource'
}
I know this is an old question, but it still seems to be an issue with Grails 2.3.x. There is comment above the resource closure in ResourceTagLib that says:
#todo this currently won't work for absolute="true" invocations, it should just passthrough these
In order to remove the warnings in the log, I overrode the resource closure, changing this bit:
...
if (!info.debug && log.warnEnabled) {
log.warn "Invocation of <r:resource> for a resource that apparently doesn't exist: ${info.uri}"
}
...
to this:
...
if (attrs.absolute != true && !info.debug && log.warnEnabled) {
log.warn "Invocation of <r:resource> for a resource that apparently doesn't exist: ${info.uri}"
}
...
It appears to happen only when you try to use a sub directory when using the dir param. You would need to specify a uri. I'm assuming that dir can only be a single level directory.
You could try the following (from plugin docs) :
<r:img uri="images/logo.png" width="100" height="50"/>
uou are using 'grails-resources' plugin. It has also tag 'resource'. try to use direct G-tag:
<img src="${g.resource(dir: 'images/brochure', file: 'arrow_up.png', absolute: 'true')}" alt="Up" />
or use R-tag from resources plugin (RECOMMENDED):
<img src="${r.resource(uri: 'images/brochure/arrow_up.png')}" />
Get more info here
Related
I've recently upgraded a grails app to 2.4.3 and in the process upgraded the resources plugin to 1.2.14. I realize the assets plugin is preferred at this point, but I cannot make the switch just yet. I have the following defined in my ApplicationResources.groovy
modules = {
core {
resource url: '/js/main.js', disposition: 'head'
resource url: '/lib/bootstrap/css/bootstrap.css', disposition: 'head'
... more here
}
}
When I run the app, I get the following:
| Error 2015-02-01 23:13:40,005 [localhost-startStop-1] ERROR resource.ResourceMeta - Resource not found: /lib/bootstrap/css/bootstrap.css
If you look at the image I've attached, you can see that this file is indeed in the correct place, and this worked with an older version of the resources plugin.
The Grails Resources plugin uses the grails.resources.adhoc.patterns and grails.resources.adhoc.includes values in Config.groovy to determine which resources to process. Perhaps this behavior changed across versions and you need to add the lib directory like so:
grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*', '/lib/bootstrap/css/*']
grails.resources.adhoc.includes = ['/images/**', '/css/**', '/js/**', '/plugins/**', '/lib/bootstrap/css/**']
I know it is a very old question, but thought my finding would helpful to someone. If we place grails.resources.resourceLocatorEnabled = false in Config.groovy file then it should work. No need to add grails.resources.adhoc property.
I want to use fontawesome plugin in grails.
I have added in build config compile :font-awesome-resources:4.0.3.1 to add plugin.I have added
customBootstrap
{
dependsOn 'font-awesome'
resource url: 'css/bootstrap.css'
resource url: 'js/bootstrap.js' resource url: 'css/bootstrap-fixtaglib.css'
}
in applicationresource.groovy but when i run the application get error
ERROR resource.ResourceProcessor - Unable to load resources Message: No such property: pluginManager for class: org.springframework.web.context.support.XmlWebApplicationContext.Please provide solution.
I am not sure whether this is a configuration issue with migration from earlier grails versions or if font-awesome has not been migrated completely to grails 2.4.x. But I encountered this as well.
As a short (dirty) workaround, you can replace the code that causes the problem directly on the plugin.
File (replace X with your project name):
~/.grails/2.4.2/projects/X/plugins/font-awesome-resources-4.0.3.1/grails-app/conf/FontAwesomePluginResources.groovy
Replace lines 3 and 4 with:
def pluginManager = grails.util.Holders.pluginManager
def lesscssPlugin = pluginManager.getGrailsPlugin('lesscss-resources') || pluginManager.getGrailsPlugin('less-resources')
And give it a go.
Trying to use the Jquery-UI plugin from http://grails.org/plugin/jquery-ui
but apparently the documentations is not correct when discuss using the plugin with resources framework as following the instructions leads to an error:
Error processing GroovyPageView: Error executing tag <r:layoutResources>: No module found with name [jquery-ui]
Apparently the same problem is known around, but was not able to find a solution on the net (example: some discussion here and some other discussions with no solution or hints to a solution).
Did anyone managed to successfully configure jquery-ui in grails with the resource framework?
First you need to install the plugin, so in your BuildConfig.groovy
plugins {
...
compile ":jquery-ui:1.8.24"
...
}
Use grails compile --refresh-dependencies and see if the console output the download of the plugin. If you are using STS, you can go in right click > grails tools > refresh dependencies
After that, you can add <r:require module="jquery-ui"/> before the <r:layoutResources/>
A usefull tip is the change of the jquery ui theme, you can configure this in your ApplicationResources.groovy
modules = {
overrides {
'jquery-theme' {
resource id:'theme', url:'/css/ui/jquery-ui-1.8.21.custom.css'
}
}
}
In this example i have one css located in web-app/css/ui/.
Another tip is that you can force your modules to depend on jquery-ui:
modules = {
mymodule {
dependsOn 'jquery-ui'
resource url: '/js/my.js'
}
}
So if you add the resource mymodule to your GSP, the jquery-ui will be loaded too.
I am having trouble with the plugin. Everything seemed fine but after running the app in dev env, the page loads up but complains that it can't find the compiled css file. I am using Grails 2.0.1 and lesscss-resources 1.3.0.
Here is what I have in UiResources.groovy:
styling {
defaultBundle 'styling'
resources url: '/less/mainStyles.less', attrs:[rel: "stylesheet/less", type: 'css'], disposition: 'head', bundle: 'bundle_styling'
resources url: '/css/other.css', disposition: 'head'
}
What shows up on the page is this:
< link href="/appName/bundle-bundle_styling_head.css" type="text/css" media="screen, projection" rel="stylesheet" >
Although I can locate this file in the
~/.grails/2.0.1/projects/appName/tomcat/worl/Tomcat/localhost/appName/grails-resources ...
Grails console also complains:
Resources not found: /bundle-bundle_styling_head.css
I have been trying different things to get this to work till no avail. Did I do anything wrong here?
I had a similar problem and found that removing the bundle option fixed the problem. So remove ", bundle: 'bundle_styling'" making the line:
resources url: '/less/mainStyles.less', attrs:[rel: "stylesheet/less", type: 'css'], disposition: 'head'
Hope this works for you too.
Be aware what the docs say currently in the issues section - maybe you are facing one of the bugs:
For the Bundle to work you must have a .css file at the end of the bundle, even if it is just a blank file.
Must specify the default bundle manually as this is calculated based on file extension by default.
I just had a case where I specified this in an inplace plugin (MyPluginApplicationResources.groovy)
resource url:'/less/eip.less', attrs:[rel: "stylesheet/less", type:'css'],defaultBundle: 'eip'
resource url: '/css/dummy.css', defaultBundle: 'eip'
There was no error but also no css rendered by the plugin, so I changed it to:
resource url:[dir: '/less', file : 'eip.less', plugin: 'my-plugin'], attrs:[rel: "stylesheet/less", type:'css'],defaultBundle: 'eip'
resource url: '/css/dummy.css', defaultBundle: 'eip'
This worked for me.
dummy.css : this is an empty css file (see issues) - but I haven't tested if its really needed.
I am using Grails 1.3.5, SQL Server 2005, iReports 3.7.6, Jasper Plugin 1.1.3. In my GSP page I have given the jasperReprt tag as:
<g:jasperReport jasper="report1" format="PDF">
<input type="hidden" name="test_id" id="test_id"/>
<input type="hidden" name="order_no" id="order_no" />
</g:jasperReport>
For development, in Config.groovy I have specified the
jasper.dir.reports = './reports'
There are two files created in the reports folder when a new report is created and saved, i.e. report.jrxml and report.jasper.
When clicked on the PDF icon in IE or Firefox, an 500 server error is thrown and below is stack trace.
[2010-11-27 01:13:14.998] ERROR groovy.grails.web.errors.GrailsExceptionResolver Invalid byte 1 of 1-byte UTF-8 sequence.
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:684)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:554)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742)
at
But if I delete the report1.jasper, the error is no longer thrown when PDF icon is clicked and the PDF report is shown fine.
Is this the correct way to do it?
My second issue is with using Sub Reports. Sub report is in the same folder as the main report. But When the report is executed from the application, below error is thrown:
[2010-11-27 01:30:27.556] ERROR groovy.grails.web.errors.GrailsExceptionResolver Could not load object from location : ./reports\report1sub_report.jasper
net.sf.jasperreports.engine.JRException: Could not load object from location : ./reports\urine_routinepatient_details_sub_report.jasper
at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:262)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:301)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:327)
It does not find the sub report. How can I fix it?
Thank you.
Jay Chandran.
Edit:
I have been searching during this whole time, but still could not find a proper solution. So I did some trial and error. I figured out that, deleting report1.jasper and just leaving jasper.jrxml in the report directory works just fine as I said earlier.
For the sub-report issue: It was giving error Could not load object from location : ./reports\report1sub_report.jasper For some strange reason, the main report name report was getting appended to the name sub_report.jasper and was looking for a file named report1sub_report.jasper
So I created a sub-folder under reports folder and named it report1 and updated report1.jrxml file
<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "\\sub_report.jasper"]]></subreportExpression>
I had to add the extra \\ slash even though the "SUBREPORT_DIR" parameter had \\ the slashes at the end of the path as shown below.
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["F:\\Workspace\\SpringSource2.5.0\\GrailsProjec\\reports\\report1\\"]]></defaultValueExpression>
</parameter>
Notice the \\ at the end. I don't know why it was not getting appended!
Another way would have been to just change the sub-report name from sub_report.jasper
to report1sub_report.jasper!!! :)
I have tested this in production mode and it works fine. I am not sure if this is the way to do it, but all other possible solutions did not work for me.
Feedback will be very helpful.
I assume you have a version conflict here. iReport stores JRXML files and seems to compile them automatically to .jasper. The Grails Jasper plugin picks up the compile variant and gets into trouble with it. So try to disable compiled output in ireport.
The Grails Jasper plugin 1.1.3 uses internally Jasper 3.7.4, the used ireport is 3.7.6.
Regarding the sub reports: no idea.
The MalformedByteSequenceException is caused by a character encoding conflict. I'd suggest to use UTF-8 instead of Windows' Win-1252 (similar to ISO-8859-1) everywhere.
In Jasper's etc/ireport.conf file, change the default_options to:
default_options="-J-Dfile.encoding=UTF-8 -J-Xms24m -J-Xmx64m"
(Where Xms and Xmx are unrelated memory settings. If there are default settings with that config entry, you can overtake them, else, just leave them out.)
See this forum thread for alternative configurations.
As for the error with subreports, take a look at the backslash \ that's probably wrong.
EDIT : There is some information about two issues which maybe could help in
http://grails.org/plugin/jasper#faqTab
i hope i can help with one of the issues: which one related with subreports dir.
The problem is the plugin code sets SUBREPORT_DIR to the complete file path of main report, including its name. However the code honour the user provided param with the same name, so if you fill this param with whatever value except null the plugin will use it.
For example if you chain directly the jasper controller you can do:
def renderAs(data,format) {
def reportParams=params.clone()
reportParams["_format"]=reportParams["_format"]?:"${format.toUpperCase()}"
reportParams["SUBREPORT_DIR"]=CH.config.jasper.dir.reports+"/"
chain(controller:'jasper',action:'index',model:[data:[]+data],params:reportParams)
}
In your scenario an (ugly) option would be create an hidden input with name SUBREPORT_DIR and value the desired one. I would fill the paremeter in other way.
EDIT:
Another annoying problem is where do we have to put the main reports and compiled subreports:
When you run the app with run-app they work if you put them all in a folder with the same name as CH.config.jasper.dir.reports(reportDir) in the root of the grails app.
But if you want to deploy a war you have to put the main reports in a folder reportDir in the root of war file and compiled subreports in WEB-INF/classes/reportDir.
I've opted to keep all files in grailsApp/reports and copy the resources in the appropiate folders in the war grails task. In my BuildConfig.groovy i've added (reportDir is "reports"):
grails.war.resources = { stagingDir,args ->
def classpathDir="${stagingDir}/WEB-INF/classes"
copy(toDir:"${stagingDir}/reports") {
fileset(dir:"reports",includes:"**")
}
copy(toDir:"${classpathDir}/reports") {
fileset(dir:"reports",excludes:"**.jrxml")
}
}
Hope it helps.