I have installed the GrailsUI plugin from this page http://grails.org/plugin/grails-ui. Installation was successful. I want to use a date picker, in that case I added this code into my view file:
<div class="yui-skin-sam">
<gui:datePicker id='withCalendar' formatString="yyyy/MM/dd" />
</div>
And I added tag into my head tag:
<head>
<meta name="layout" content="main" />
<title><g:message code="User's profile" /></title>
<gui:resources components="['datePicker']"/>
</head>
Ya well its working fine, but the layout of the whole page have changed now, when i added the tag. How do overcome this? Is this is an error ?
And also when ever I select a date from the datepicker, I see this error in my console:
| Error 2012-02-12 12:53:33,592 ["http-bio-8080"-exec-7] ERROR resource.ResourceMeta - Resource not found: /plugins/grails-ui-1.2.3/js/grailsui/SimpleDateFormat-min.js
What does this error means?
Thanks in advance.
Related
I'm just trying to setup a very simple controller to return a very simple view (with a very simple layout), however I keep getting errors related to the content type.
class SimpleController {
def index() {
render(view: "simple")
}
}
_simple.gsp:
<html>
<head>
<meta name="layout" content="blank" />
</head>
<body>
Simple test page.
</body>
</html>
blank.gsp:
<!DOCTYPE html>
<html>
<head>
<g:layoutHead />
</head>
<body>
<g:layoutBody />
</body>
</html>
It doesn't get much simpler than that. The controller method is found correctly, the issue seems to be during the rendering. Here's the error I'm getting:
2016-07-05 16:07:14,931 [http-bio-8085-exec-5] ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] /testApp/simple/
Stacktrace follows:
Message: null
Line | Method
->> 15 | in com.opensymphony.module.sitemesh.filter.HttpContentType
| 49 | build in com.opensymphony.sitemesh.compatability.PageParser2ContentProcessor
| 89 | getContent . . . . . . . . . . in org.codehaus.groovy.grails.web.sitemesh.GrailsContentBufferingResponse
| 107 | obtainContent in org.codehaus.groovy.grails.web.sitemesh.GrailsLayoutView
Debugging confirms that context.contentType is null. I've found four different way to set the content type, but none of them seem to work.
<%# page contentType="text/html;charset=UTF-8" %>
At the top of the view.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
In the head tag of the view.
contentType: "text/html"
Passed to the render method in the controller.
response.setContentType("text/html")
Called in the controller method.
This is in an existing project, where many other controllers and views work perfectly fine. I need to add a new controller and view, which I originally copied existing working pieces. When that didn't work, I tried to reduce the problem down to be as simple as possible, and ended up with the above code, which is still not working.
Btw, this is with Grails 2.5.1 (stuck with this version).
What you have there should work.
If you're using the default URL mappings you should name your view simple.gsp instead of _simple.gsp
If it's not as simple as that you might try recreating a simple app.
Could be even simpler and incidentally solve your problem.
class SimpleController {
def index() {
}
}
Rename _simple.gsp to index.gsp and needs to be located in views/simple/ directory. If blank.gsp its in views/layouts directory it should work now.
As #jmallen said, the page should be named "simple.gsp".
The underscore at the beginning is something I only know for templates, gsp-files, that could be included in other pages with the following statement:
<g:render template="/layouts/menu" />
than the gsp file for the menu is named
_menu.gsp
I made a script that loads content based on the current request locale. Something like
class ScriptsTagLib {
static namespace = "my"
def loadLangInfo = { attrs ->
Locale locale = RequestContextUtils.getLocale(request)
r.script() {
out << '$(function(){ loadLangInfo("'+locale.language+'") });'
}
}
}
If I add this in my layout, the page throws an error:
Error evaluating expression [my.loadLangInfo()] on line [6]: Cannot
add module [-page-fragments-] which requires disposition [defer] to
this request - that disposition has already been rendered.
Error 2012-11-19 15:13:54,801 [http-bio-8080-exec-5] ERROR
[Tomcat].[localhost] - Exception Processing ErrorPage[errorCode=500,
location=/grails-errorhandler] Message:
java.io.UnsupportedEncodingException: The character encoding [null] is
not supported
But if I add this tag in my page instead of the layout, the page is rendered with success.
It's not possible to add r.script() to a layout?
EDIT: The problem is really with resources in the layout. Another example that fails is:
<g:layoutHead/>
<r:script>
$(function(){ });
</r:script>
<r:layoutResources />
EDIT 2: More info about the context
Grails 2.0.4
Resources 1.2.RC2
Also, it's a layout inside a plugin, and not one app.
Not tested in Grails 2.1, but will do that.
EDIT 3:
Just tested now, with Grails 2.1.1 and Grails 2.0.4 new fresh plugin projects, and the script tag in the layout is ignored!
./views/layout/test.gsp -> Script ignored
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><g:layoutTitle default="Insoft4 UI Plugin"/></title>
<g:layoutHead/>
<r:layoutResources />
</head>
<body>
<g:layoutBody/>
<r:script disposition="defer">
alert('layout!');
</r:script>
<r:layoutResources />
</body>
</html>
./views/index.gsp -> Script OK
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Teste</title>
<meta name="layout" content="teste" />
<r:script disposition="defer">
alert('index!');
</r:script>
<r:layoutResources />
</head>
<body>
<h1>Testing this index!</h1>
<r:layoutResources />
</body>
</html>
I found out that the problem occurs when you have declared <r:layoutResources /> in both, layout and page and you try to add a script in the layout.
To correct I removed the layoutResources from every view, leaving just in the layout.
Try to add tag before the last r:layoutResources on the layout.
I'm trying to get started with Cassette via NuGet. I'm having issues with it in my app so I rolled back and tried it in a new empty ASP.NET MVC 3 web application.
However, the problem persists. Following the documentation page "Easy to use", I simply can't get it to work. Here's the exception along with a bit of the stack:
"Object reference not set to an instance of an object."
[NullReferenceException: Object reference not set to an instance of an object.]
Cassette.CassetteApplicationContainer.get_Application() +6
Cassette.Views.Bundles.Reference(String assetPathOrBundlePathOrUrl, String pageLocation) +14
ASP._Page_Views_Shared__Layout_cshtml.Execute() in d:\Dave\Documents\Visual Studio 2010\Projects\CasetteTest\Views\Shared\_Layout.cshtml:2
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207
I simply followed the two steps in the documentation and this is what I get. What am I doing wrong?
This is what my _Layout.cshtml file looks like:
#{
Bundles.Reference("Scripts/jquery-1.5.1.min.js");
Bundles.Reference("Scripts/modernizr-1.7.min.js");
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>#ViewBag.Title</title>
<link href="#Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
</head>
<body>
#RenderBody()
#Bundles.RenderScripts();
</body>
</html>
I figured it out.
I included the Cassette.Views package which does not create a default CassetteConfiguration.cs file that bundles each script and each css file in its own bundle. That's what triggered the NullReferenceException. In order to get it to work, you'll need to add the Cassette.Web package instead. In my defense, the package descriptions in the NuGet gallery are not clear and one is led to believe that the Views package is required for MVC and the other for WebForms.
The next problem was that I referenced the minified '.min.js' scripts which are not picked up by the bundler (it seems).
Cannot reproduce the issue.
4 simple steps allowed me to get a fully working prototype in less than 30 seconds:
Create a new ASP.NET MVC 3 project in Visual Studio
Install-Package Cassette.Web
Index.cshtml:
#using Cassette.Web
#{
Bundles.Reference("~/Scripts/jquery-1.5.1.js");
Bundles.Reference("~/Scripts/jquery-ui-1.8.11.js");
Bundles.Reference("~/Content/site.css");
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Web App</title>
#Bundles.RenderStylesheets()
</head>
<body>
<div>Hello World</div>
#Bundles.RenderScripts()
</body>
</html>
Hit Ctrl+F5 to run the project
Setting up a simple grails app with Dojo, i used the
grails install-plugin dojo
to setup the dojo js files. In my main.gsp i have this
<html>
<head>
<title><g:layoutTitle default="Grails" /></title>
<link rel="stylesheet" href="${resource(dir:'css',file:'main.css')}" />
<link rel="shortcut icon" href="${resource(dir:'images',file:'favicon.ico')}" type="image/x-icon" />
<g:layoutHead />
<g:javascript library="application"/>
<g:javascript library="dojo"/>
<dojo:header modules="['dojo.data.ItemFileReadStore','dijit.form.ComboBox']"/>
<g:javascript>
//dojo.addOnLoad(function(){alert("dojo loaded.");});
</g:javascript>
</head>
On my index.gsp page, i setup the following elements
<div>
<div jsId="search" dojoType="dojo.data.ItemFileReadStore"
url="<g:createLink controller="runner" action="findrunner"/>"></div>
<input dojoType="dojo.data.FilteringSelect"
id="chooser"
name="feed"
store="search"
searchAttr="url"
autocomplete="true"
pageSize="5"/>
</div>
Start the app but keep getting this error from firebug
GET http://localhost:8080/xxx/js/dojo/1.4.3/dojo/data/ItemFileReadStore.js
404 Not Found
5ms
dojo.js (line 16)
ParamsHeadersPostPutResponseCacheHTML
..</head><body><h1>HTTP Status 404 - /xxx/js/dojo/1.4.3/dojo/data/ItemFileReadStore.js</h1>
<HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b>
<u>/xxx/js/dojo/1.4.3/dojo/data/ItemFileReadStore.js</u></p><p><b>description</b>
<u>The requested resource (/xxx/js/dojo/1.4.3/dojo/data/ItemFileReadStore.js) is not available.</u>
</p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0-snapshot</h3></body></html>
Any ideas?
Seems the 'dojo plugin' didn't seems to install all the required dojo files. I manually installed dojo 1.5 and extract the zip to /webapps/js/dojo/1.5.0 and enabled the version in my main.gsp like this
<script src="js/dojo/1.5.0/dojo/dojo.js"></script>
The new plugin version makes things a lot easier now. There is even a script to launch your custom builds in a breeze... and it's updated to dojo 1.6. Give it a try ;-)
I'm programming a page that uses the grails-ui plugin "autocomplete" feature. It doesn't work and the error console shows the error "YAHOO is not defined"; searching the web I tried the following:
Install the yui2 ad 3 plugins
Uninstall the grails-ui plugin
reinstall the grails-ui plugin
With no luck.
Any ideas ? I'm using grails 1.2
Here's my gsp:
<%# page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<gui:resources components="autocomplete" />
<title>Sample title</title>
</head>
<body>
<h1>Sample line</h1>
<g:form action="autoespec" id="id1">
<gui:autoComplete
id="spec"
name="spec"
resultName="result"
labelField="name"
idField="id"
controller="inscripcion"
action="autoespec"
/>
<input type="text" name="query">
<input type="submit">
</g:form>
</body>
</html>
Added an input to check that the controller worked (it does).
You have to add a special class to your body.
<body class="yui-skin-sam">
...
It appears that you've got the tag namespaces wrong. Assuming you're using the latest richui plugin from http://www.grails.org/RichUI+Plugin and installed it using grails install-plugin richui you need the following tags:
<resource:autoComplete skin="default"/>
in the page head and for the autocomplete box itself:
<richui:autoComplete ... />
I also notice that the attributes you're using for the riuchui:autocomplete element are not in the documentation so you might want to give it another read: http://www.grails.org/RichUI+Plugin#AutoComplete
HTH