gsp

grails display images in folder

好久不见. 提交于 2019-12-10 11:57:08
问题 I'm trying to do a Grails webapp and now I'm trying to display all images in a folder. To do that I have the following: def display(){ def dir = new File("/tmp/images") def list = [] dir.eachFileRecurse() { file -> def avatarFilePath = new File(file.path) response.setContentType("application/jpg") OutputStream out = response.getOutputStream(); out.write(avatarFilePath.bytes); out.close(); } } So using the code above I'm displaying one image using: <img class="thumbnail" src='${createLink

Grails GSP - cannot call body with parameters

好久不见. 提交于 2019-12-10 11:53:17
问题 I have defined a taglib like this: class FooTagLib { static namespace = "foo" def bar = { attrs, body -> out << render(template: "/taglib/foo/bar", model: [body: body]) } } The body closure takes two parameters, baz and qux, why can't I do this in my /taglib/foo/_bar.gsp: ${body(baz: 'Hello', qux: 'world!')} ? This is how I use this tag in my gsp views: <foo:bar> ${baz} ${qux} </foo:bar It prints the content of the body, but the parameters are all null : null null Is this a bug or is there

Using GSP views in plain Spring MVC without Grails

﹥>﹥吖頭↗ 提交于 2019-12-09 06:02:43
问题 I would like to use GSP views instead of JSP/JSTL views in a plain old Spring MVC application. I have added a groovy.servlet.TemplateServlet to web.xml like this: <servlet> <servlet-name>GroovyTemplate</servlet-name> <servlet-class>groovy.servlet.TemplateServlet</servlet-class> <init-param> <param-name>template.engine</param-name> <param-value>groovy.text.GStringTemplateEngine</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>GroovyTemplate</servlet-name> <url-pattern>*

How to check for resource file existence at run-time [grails]?

自古美人都是妖i 提交于 2019-12-09 04:36:30
I need to test whether a resource file (an image, for instance) exists and if not, I will display another image. My GSP view code looks like: <% if (resExists(dir: "images", file:"img.jpg")) {%> <img src="${g.resource(dir:'images',file: 'img.jpg')}"> <% else { %> <img src="${g.resource(dir:'images',file: 'noimg.jpg')}"> <%}%> How can I test for a file existence in Grails? What is the code of the method boolean resExists() I found out the answer: def resExists(resPath) { def resFile = grailsApplication.parentContext.getResource(resPath) resFile?.exists() } or def resExists(resPath) { def

Grails GSP accessing variables within script

六眼飞鱼酱① 提交于 2019-12-08 12:30:54
问题 I have searched for this but cannot seem to find the right solution. I am going to dumb down this a bit and see where I am going wrong. I am using Grails for a project and I am really enjoying it. Where I think it is hard to get around is in the GSP's. Can someone tell me given: Controller: def index() { def message = "This is a test" [message: message] } Within the view <!DOCTYPE html> <html lang="en"> <head> <script type="text/javascript"> $(document).ready(function() { HOW DO YOU ACCESS

How to check for resource file existence at run-time [grails]?

a 夏天 提交于 2019-12-08 05:06:58
问题 I need to test whether a resource file (an image, for instance) exists and if not, I will display another image. My GSP view code looks like: <% if (resExists(dir: "images", file:"img.jpg")) {%> <img src="${g.resource(dir:'images',file: 'img.jpg')}"> <% else { %> <img src="${g.resource(dir:'images',file: 'noimg.jpg')}"> <%}%> How can I test for a file existence in Grails? What is the code of the method boolean resExists() 回答1: I found out the answer: def resExists(resPath) { def resFile =

Using GroovyPagesTemplateEngine without a request?

烂漫一生 提交于 2019-12-08 04:57:29
问题 I'm trying to evaluate a GSP file without a real http request. I'm trying this: String compileGsp(File input) { def text = '' try{ text = groovyPagesTemplateEngine.createTemplate(input).make().toString() } catch( Exception e ){ StackTraceUtils.sanitize(e).printStackTrace() } return text } but this throws an exception and yields this: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request

How I access a variable from JavaScript and Grails?

孤人 提交于 2019-12-08 03:25:19
问题 I have a Grails variable which is of type JASONList that is rendered in a template. Is there a way to access this list from inside a JavaScript function? Let's say I want onresize to fit all the objects on the screen. Without making a database call and refetching the entire list from Ajax... Let's say the template does something like this: <g:each var="report" in="${reportList?.myArrayList}"> <li style="display:inline; list-style:none;"> <img src=" ${report?.img}"> </li> </g:each> <script

css background is not working when convert template into pdf using rendering plugin

ぃ、小莉子 提交于 2019-12-08 02:45:32
问题 I am using rendering plugin to generate pdf in grails. I am using a background color which is prepared by css. code is here. #container #content #mainContent .block .backgroundStyle { background: #ffffff; /* Old browsers */ /* IE9 SVG, needs conditional override of 'filter' to 'none' */ background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA

Use regex to do validation in g:TextField

∥☆過路亽.° 提交于 2019-12-07 16:02:10
问题 I am working on a grails applications and want the ability to do validation on a g:textField. I just want to make sure that numbers are numbers and words are words. I would like to avoid doing it through JS but if that is the only way, then so be it. Here is what I am trying out. <g:textField type="number" pattern="^(?:[-+]?[1-9]\d*|0)?(?:\.\d+)?\$" class="form-control" name="hours" value="${hours}"/></div> Any suggestions or directions? Or should I just do it through JS? 回答1: So I was able