gsp

grails: show list of elements from database in gsp

北城余情 提交于 2019-12-07 13:53:23
问题 in my grails app I need to get some data from database and show it in a gsp page. I know that I need to get data from controller, for example List<Event> todayEvents = Event.findAllByStartTime(today) gets all Event with date today Now, how can I render it in a gsp page?How can I pass that list of Event objects to gsp? Thanks a lot 回答1: You can learn many of the basic concepts using Grails scaffolding. Create a new project with a domain and issue command generate-all com.sample.MyDomain it

Difference between view and template in Grails

你说的曾经没有我的故事 提交于 2019-12-07 05:11:06
问题 In a Grails app, I am trying to figure out when to use a view and when to use a template for a gsp. Are there any obvious reasons? Or does it just come down to reuse? 回答1: Basically Template is a (reusable) part of a View. Useful for splitting View into logical parts and/or for reusing same code from different views. So, if you're rendering a whole page - use View. If you need just a small part - use Template. See docs for Views and Templates - http://grails.org/doc/latest/guide/theWebLayer

How do I save a composite field value in Grails GSP?

…衆ロ難τιáo~ 提交于 2019-12-07 02:00:33
I have a composite domain object as follows: class Person { static embedded = ['forSale'] Boolean isSelling House forSale } class House { Integer numBedrooms } I have a select control for the numBedrooms as follows: <tr class="prop"> <td valign="top" class="name"> <label for="numBedrooms"><g:message code="person.numBedrooms.label" default="Num Bedrooms" /></label> </td> <td valign="top" class="value ${hasErrors(bean: personInstance, field: 'forSale.numBedrooms', 'errors')}"> <g:select name="numBedrooms" value="${fieldValue(bean: personInstance, field: 'forSale.numBedrooms')}" noSelection="${[

Importing and using groovy code in GSP

霸气de小男生 提交于 2019-12-06 21:56:11
问题 I am trying to use a groovy function inside a GSP. Please help as I am about to tare my hair out here. At the top of my GSP i have <%@ page import = company.ConstantsFile %> Inside my GSP I have <p> I have been in the heating and cooling business for <%(ConstantsFile.daysBetween())%> </p> and my ConstantsFile.groovy package company import static java.util.Calendar.* class ConstantsFile { def daysBetween() { def startDate = Calendar.instance def m = [:] m[YEAR] = 2004 m[MONTH] = "JUNE" m[DATE]

using value of enum in g:select when enum is attribute of selection object

假如想象 提交于 2019-12-06 19:10:13
问题 Example: batchTag is an enumerated type attribute of a batchRange, with values like so: JAN1 "January Biweekly 1", JAN2 "January Biweekly 2", etc. I want to display the VALUE of the batchTag in the select, IOW, the select should contain "January Biweekly 1" "January Biweekly 2" ... not JAN1 JAN2 FEB1 FEB2 FEB3 ... I have tried several things in the g:select to do this, but without any success. I thought perhaps "it" would be available as part of the g:select (as it is clearly an iteration)

Using GroovyPagesTemplateEngine without a request?

六眼飞鱼酱① 提交于 2019-12-06 16:07:06
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 outside of the originally receiving thread? If you are actually operating within a web request and

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

做~自己de王妃 提交于 2019-12-06 10:40:54
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/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI

Grails iterating in gsp vs. accessing Map elements

点点圈 提交于 2019-12-06 10:22:07
问题 Full context: I'm trying to process multiple files using a grails Application. The code I will display comes from the post-processing page where it gives information about the files processed. My initial sense was to use code like this: <table> <tr> <th>Parsed from Excel:</th> <th>Uploaded to DS:</th> <th>File Name:</th> <th>Size:</th> </tr> <tr> <g:each in="${fileContents}" var="item"> <td>${item}</td> </g:each> <%-- <td>${fileContents.ExcelRows?.encodeAsHTML()}</td> <td>${fileContents

Reading the g:datePicker-value in Grails without using the “new Object(params)”-method

纵然是瞬间 提交于 2019-12-06 07:36:31
问题 Let's say I have a datePicker called "foobar": <g:datePicker name="foobar" value="${new Date()}" precision="day" /> How do I read the submitted value of this date-picker? One way which works but has some unwanted side-effects is the following: def newObject = new SomeClassName(params) println "value=" + newObject.foobar This way of doing it reads all submitted fields into newObject which is something I want to avoid. I'm only interested in the value of the "foobar" field. The way I originally

Use regex to do validation in g:TextField

不羁岁月 提交于 2019-12-06 03:00:49
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? So I was able to figure out the correct regex. The issue that I was having was about the escape characters and the way they