gsp

How to call a Grails service in a view?

时间秒杀一切 提交于 2020-01-02 03:43:09
问题 Simple question : I have a service class (let's say helpersService ) and a method def constructURI(params) . How can I call this method from a template view. I have tried the following code without success <% def helpersService = new HelpersService() // or def helpersService %> <img src="${helpersService. constructURI(params)}"/> But I get the following result: No signature of method: com.HelpersService. constructURI() is applicable for argument types... or (in case I use def helpersService )

Grails/GSP: break out of <g:each>

社会主义新天地 提交于 2020-01-01 17:10:55
问题 Is there a way to break out of a <g:each>? I have a page wherein I'm iterating through a list and I have to make sure that a checkbox is checked if that was the value stored in DB. To make it a little clearer, please consider something like: <g:each in=${list1}> <g:each in=${list2}> <g:if test="${list1.id == list2.id}"> <input type="checkbox" ... checked="checked" /> </if> </g:each> ... </g:each> where list1 is, say Domain1.list() (i.e. ALL possible values) and list2 is Domain2.find(...) (i.e

Grails “render” renders the template

北城余情 提交于 2019-12-31 22:41:12
问题 In my Grails controller I'm responding to an AJAX call and using render to return the text: def ajaxRandomPersonName = { def person = get a random person ... render "Name: ${person.name}" } The problem is that render renders the whole template. So instead of just rendering "Name: John" it renders all the icons, navigation, etc defined in the template. How do I get render to just render without the template? I'm pretty much following Chapter 1 of "Grails in Action" (page 28) using Grails 1.1.1

Identifying ajax request or browser request in grails controller

天涯浪子 提交于 2019-12-31 10:50:22
问题 I am developing a grails application which uses lot of ajax.If the request is ajax call then it should give response(this part is working), however if I type in the URL in the browser it should take me to the home/index page instead of the requested page.Below is the sample gsp code for ajax call. <g:remoteFunction action="list" controller="todo" update="todo-ajax"> <div id ="todo-ajax"> //ajax call rendered in this area </div> if we type http://localhost:8080/Dash/todo/list in the browser

Where should I put javascript libraries in a Grails app?

情到浓时终转凉″ 提交于 2019-12-30 05:45:26
问题 I have a couple of Javascript libraries of my own that do some nice prettyfying of my HTML pages and I want to include them in my gsp pages, particularly the landing page of my app. I have tried putting them in views folder and web-app/js and $APP_HOME/scripts but when I load my index.gsp the scripts don't show up. I have also tried a variety of alternatives in my code none of which work... <script src="mylib.js" type="text/javascript"></script> <script src="js/mylib.js" type="text/javascript

How do I call a Grails service from a gsp?

江枫思渺然 提交于 2019-12-28 05:18:10
问题 How can I invoke a service directly from a view? I'm trying with ${my.domain.service.method} , but it complains it can't find the property. And no, I don't want to use a controller because the view is a template. 回答1: <%@ page import="com.myproject.MyService" %> <% def myService = grailsApplication.classLoader.loadClass('com.myproject.MyService').newInstance() %> And then you can call ${myService.method()} in your gsp view Be aware that calling transactional service methods from views hurts

How do I call a Grails service from a gsp?

三世轮回 提交于 2019-12-28 05:18:00
问题 How can I invoke a service directly from a view? I'm trying with ${my.domain.service.method} , but it complains it can't find the property. And no, I don't want to use a controller because the view is a template. 回答1: <%@ page import="com.myproject.MyService" %> <% def myService = grailsApplication.classLoader.loadClass('com.myproject.MyService').newInstance() %> And then you can call ${myService.method()} in your gsp view Be aware that calling transactional service methods from views hurts

my checkbox pass value even unchecked - Grails

落爺英雄遲暮 提交于 2019-12-25 02:48:06
问题 I have lots of checkbox element on my Grails form , one is this: <g:checkBox id="consolidate" name="consolidate" value="${true}" checked="${false}" /> Then on the receiving controller , I verify the value of the checkbox using this code : println params?.consolidate And it displays: on Regardless whether I've tick my checkbox or not. In other language, if the checkbox is not ticked, its value on the controller will be null or undefined . What should be its value when unchecked, and what is

Grails field pattern for different time formats

隐身守侯 提交于 2019-12-25 02:38:38
问题 I'm trying to use patterns for my gsp file in Grails. I want to check if the time entered is in the correct format. For example: 12.15 == 12:15 == 12,15 == 12-15 and so on. <g:field type="text" name="startTime" class="date" pattern="\\$##:##"/> <g:field type="text" name="endTime" class="date" pattern="[0-9]{2}:[0-9]{2}" /> That's my code. The patterns are just some trys. Maybe someone knows a solution. Greetings Nik 回答1: the pattern in your g:field tag will be pass into date template (for

GSP rendering issue after server is idle overnight

陌路散爱 提交于 2019-12-24 17:57:45
问题 I have been intermittently encountering a difficult to replicate issue now for a few weeks. It seems (ie I can't yet be sure) that if the Grails app is not touched overnight something is perhaps unloaded causing: GSP rendered with values such as: <meta http-equiv="org.apache.commons.lang.StringUtils@72cd722b" content="org.apache.commons.lang.StringUtils@4e520b18"> <link href="/appname/static/bundle-bundle_application_head.css" type="org.apache.commons.lang.StringUtils@31da0262" rel="org