I'm working on a very basic Grails application in order to dip my toes into web development.
Unfortunately, I'm stuck at trying to display a collection within my MongoDB database using the <f:table>-field tag.... Because the tag somehow seems to be incompatible with the unique constraint of my domain class? Is there anything I can do?
Here's the error message:
There was an unexpected error (type=Internal Server Error, status=500).
Error processing GroovyPageView: [views/teaser/index.gsp:17] Error executing tag <f:table>: Exception thrown applying constraint [unique] to class [class com.test.site.Teaser] for value [true]: Cannot invoke "grails.gorm.validation.Constraint.isValid()" because "c" is null
My BootStrap contains two object instances for testing purposes; they seem to be working fine, since they appear in my MongoDB. Just to be safe, here is how I stored them:
new Teaser(imageUrl: "", teaserUrl: "", name: "mainTeaser", text: "").save()
new Teaser(imageUrl: "", teaserUrl: "", name: "footerTeaser", text: "").save()
Here's my domain class:
package com.test.site
class Teaser {
String imageUrl
String teaserUrl
String name
String text
static mapWith = "mongo"
static constraints = {
name blank: false
name unique: true
}
Here's the current state of my index.gsp (linked to my controller):
<!doctype html>
<html>
<head>
<meta name="layout" content="main">
<asset:stylesheet href="styles.css"/>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Teaser Details</title>
</head>
<body id="body">
<header class="header">
</header>
<main class="main">
<div class="container">
<section>
<f:table collection="${teaserList}"/>
</section>
</div>
</main>
<footer class="footer">
</footer>
</body>
</html>
Finally, here's my controller:
package com.test.site
class TeaserController {
static scaffold = Teaser
def index() {
def teaserList = Teaser.list()
render view: "index", model: [teaserList : teaserList]
}
I'm grateful for any help :)
Related
I have creating my website using composite c1 .net cms with razor master template.
but I can't able to render the script in the masterlayout.Here is my razor files.
1.MaserLayout.cshtml
#inherits CompositeC1WebPage
#{
string websiteTitle = HomePageNode.Title;
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" class="no-js" lang="#Lang">
<head>
<title>#CurrentPageNode.Title</title>
#if (!string.IsNullOrEmpty(CurrentPageNode.Description))
{
<meta name="description" content="#CurrentPageNode.Description" />
}
#PageTemplateFeature("Descriptive HTML head elements")
</head>
<body>
<div class="container-fluid main-container">
#* renders the sub template: *#
#RenderBody()
</div>
</body>
</html>
above is my master template and here is my home template
#inherits RazorPageTemplate
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
#*you can add template specific head elements here*#
</head>
<body class="frontpage">
<div>Test template</div>
<script>
$(document).ready(function () {
$('.test').click(function () {
alert("test");
})
});
</script>
</body>
</html>
But I can't able to run the script in the masterpage.Cn anyone help.
Thanks in advance for help.
If Composit-c1 uses some special razor functionality/flow other than default then please ignore this comment
I think it's not related to composit-c1 razor, you should define layout in home page to use master page. & also any script is not defined in you master pages.
in derived pages you don't create complete DOM structure (html, head & body etc. tags)
Now, I'm developing Grails plugin for simplify use of Amazon PAAPI in Grails apps.
The goal of this plugin is provide convenient TagLib to doing Amazon PAAPI Operation like shown below.
<paapi:img idType="ISBN" itemId="4048668161" relationshipType="AuthorityTitle" size="medium" alt="alttext" />
The code will rendered like below.
<img src="http://mediumimageurl.jpg" alt="alttext" />
The Taglib need means connection to Amazon PAAPI. I choosed Grails REST Client Builder Plugin for that.
And I written below code. This is service method.
def itemLookup(
String condition,
String idType,
String itemId,
String merchantId,
String offerPage,
String relatedItemsPage,
String relationshipType,
String reviewPage,
String reviewSort,
String searchIndex,
String tagPage,
String tagsPerPage,
String tagSort,
String variationPage,
ResponseGroup responseGroup) {
def associateId = grailsApplication.config.grails.plugin.foo.amazonpaapi.associateId
def paapiAccessKey = grailsApplication.config.grails.plugin.foo.amazonpaapi.paapiAccessKey
def paapiSecretAccessKey = grailsApplication.config.grails.plugin.foo.amazonpaapi.paapiSecretAccessKey
def rest = new RestBuilder()
def resp = rest.get(
"http://ecs.amazonaws.com/onca/xml",
[
Service:'AWSECommerceService',
AWSAccessKeyId:paapiAccessKey,
AssociateTag:associateId,
Operation:'ItemLookup',
Condition:condition,
IdType:idType,
ItemId:itemId,
MerchantId:merchantId,
OfferPage:offerPage,
RelatedItemsPage:relatedItemsPage,
RelationshipType:relationshipType,
ReviewPage:reviewPage,
ReviewSort:reviewSort,
SearchIndex:searchIndex,
Tagage:tagPage,
TagsPerPage:tagsPerPage,
TagSort:tagSort,
VariationPage:variationPage,
ResponseGroup:responseGroup.getLabel()
]) {
accept "application/xml"
}
return resp.xml
}
The code is failed.
I got below result. It had entered resp.txt.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html> <head> <title>400 Bad Request</title> </head> <body> <div align=center> <img src="http://g-images.amazon.com/images/G/01/icons/amazon-logo.gif" width=140 height=30 alt="Amazon.com" border=0><br> </div> <h1>Bad Request</h1> <p>Parameter Operation is missing</p> </body> </html>
The problem is the thing you do not know why did this happen.
I want know, what URL sent to Amazon PAAPI from RestBuilder.get(). And I didn't find it.
Do you have any means to know how to do this?
Self solved.
Finally, I could not find means to know REST request url.
But, This error is solved. I found error message in request from Amazon
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html> <head> <title>400 Bad Request</title> </head> <body> <div align=center> <img src="http://g-images.amazon.com/images/G/01/icons/amazon-logo.gif" width=140 height=30 alt="Amazon.com" border=0><br> </div> <h1>Bad Request</h1> <p>Parameter Operation is missing</p> </body> </html>
Parameter Operation is missing
I can resolve this error like below.
def resp = rest.get('http://ecs.amazonaws.com/onca/xml?Operation={Operation}') {
urlVariables Operation:'ItemLookup'
}
Error seems to have been returned because there is no Operation parameters is essential.
I am using grails 2.3.4
However when I start my application I get:
|Server running. Browse to http://localhost:8080/testApplication
....[/testApplication].[gsp] Servlet.service() for servlet [gsp] in context w
ith path [/testApplication] threw exception
java.lang.RuntimeException: It looks like you are missing some calls to the r:la
youtResources tag. After rendering your page the following have not been rendere
d: [defer]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewIns
tance(ReflectiveInterceptor.java:986)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstru
ctor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteN
oUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstru
ctor(CallSiteArray.java:57)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor
(AbstractCallSite.java:182)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor
(AbstractCallSite.java:190)
at org.grails.plugin.resource.DevModeSanityFilter.doFilter(DevModeSanity
Filter.groovy:54)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:210)
at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doF
ilterInternal(GrailsWebRequestFilter.java:69)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerR
equestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:210)
at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilte
rInternal(HiddenHttpMethodFilter.java:67)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerR
equestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterIntern
al(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerR
equestFilter.java:107)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(D
elegatingFilterProxy.java:343)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(Delegat
ingFilterProxy.java:260)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:123)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:100)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoin
t.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:603)
at java.lang.Thread.run(Thread.java:722)
My index.gsp file looks like that:
<html ng-app>
<head>
<meta name="layout" content="main" />
<title>Title Page</title>
<!-- here we are loading angularjs -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js"></script>
<!-- other way: <script src="" $ {resource(dir: 'js/lib', file: 'file.js')}"></script> -->
<!-- <r:require module="angular" />
<r:layoutResources />
-->
</head>
<body>
<div>
<div>
<label>Name:</label>
<input type="text" ng-model="yourName" placeholder="Enter a name here">
<hr>
<h1>Hello {{yourName}}!</h1>
</div>
</div>
</body>
</html>
As you can see the tag is commented out. So why do I get this and how to fix this long expeception?
I really appreciate your answer!
<r:layoutResources/> should appear twice in your page (or more usually in your layout GSP) - once just before </head> to render resources with the "head" disposition and again just before </body> to render the "defer" ones. It's the missing second occurrence that the error message is complaining about, the first isn't really "commented out" (it's inside an HTML comment so it will still be rendered, but its output will be commented out in the resulting HTML).
So you need to "uncomment" the first occurrence and also add the second one, or make sure that your page is using a layout that includes the <r:layoutResources/> tags at the right places.
I have installed:
compile ":jquery-ui:1.8.24"
compile ":jqgrid:3.8.0.1"
I got the next error:
| Error 2013-06-03 15:20:33,892 [http-bio-8080-exec-7] ERROR resource.ResourceMeta - While processing /plugins/jqgrid-3.8.0.1/css/jqgrid/ui.jqgrid.css, a resource was required but not found: /plugins/jqgrid-3.8.0.1/css/jqgrid/ellipsis-xbl.xml
I opened the file C:\Users\user\.grails\ivy-cache\org.grails.plugins\jqgrid\zips\jqgrid-3.8.0.1.zip. There is not any: css/jqgrid/ellipsis-xbl.xml
The latest version of JQGrid (4.5.2) has the file ellipsis-xbl.xml included. But I'm using the latest Grails plugin which uses that older version.
How could I tell Grails to look for ellipsis-xbl.xml in another location (let's say web-app/css/jqgrid-additions/ellipsis-xbl.xml).
I did a research on Google and it is what could be related:
taglib: <jqgrid:resources /> (according with the documentation, it
includes the required javascript and css for the plugin)
Add a configurationmapping in BuildConfig.groovy (I didn't find any
Grails documentation about that!)
I added to the GSP the next code to check if it looked at a different
location (and it check in the same location, at /plugins...):
<style>
.ui-jqgrid tr.jqgrow td {text-overflow:ellipsis; -moz-binding:url('ellipsis-xbl.xml#ellipsis');}
</style>
I end up by removing all css/js plugins except for jQuery (which is built-in). Just extract css/js files in /web-app directory. Then include them in /grails-app/conf/ApplicationResources.groovy like this:
modules = {
ui {
dependsOn 'jquery'
resource url: 'css/default.css'
resource url: 'css/print.css', attrs:[media:'print']
}
bootstrap {
dependsOn 'jquery'
resource url: 'css/bootstrap.css'
resource url: 'css/bootstrap-responsive.css'
resource url: 'js/bootstrap.js'
}
choice {
resource url: 'js/choice.js'
}
application {
dependsOn 'jquery,choice'
resource url: 'js/application.js'
}
}
Choice and application are application specific. Include here as an example. Then, call them in layout:
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><g:layoutTitle default="My Application" /></title>
<g:layoutHead />
<r:require modules="jquery,ui,bootstrap,choice,application" />
<r:layoutResources />
</head>
<body>
<div id="wrapper">
<div id="main" class="container-fluid">
<div class="row-fluid">
<div class="span12">
<g:layoutBody/>
</div>
</div>
</div>
</div>
<r:layoutResources />
</body>
</html>
This way, I can manage css/js library myself.
I am getting file name in action as null, uploaded from plupload plugin. how can i get the original file name. Please tell where is my mistake.
jsp
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
<head>
<title>test</title>
<sj:head compressed="false"/>
<link rel="stylesheet" type="text/css" href="plup/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" media="screen" />
<script type="text/javascript" src="plup/plupload.full.min.js"></script>
<script type="text/javascript" src="plup/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript">
/* Convert divs to queue widgets when the DOM is ready */
$(function(){
function plupload(){
$("#uploader").pluploadQueue({
// General settings
runtimes : 'html5,gears,browserplus,silverlight,flash,html4',
url : 'uploads',
max_file_size : '10mb',
unique_names : true,
chunk_size: '2mb',
// Specify what files to browse for
filters : [
{title: "Image files", extensions: "jpg,gif,png"},
{title: "Zip files", extensions: "zip"}
],
resize: {width: 320, height: 240, quality: 90},
// Flash settings
flash_swf_url : 'plup/Moxie.swf',
// Silverlight settings
silverlight_xap_url : 'plup/Moxie.xap',
multipart_params: {'user': 'admin', 'time': '2012-06-12'}
});
}
plupload();
$('#clear').click(function(){
plupload();
});
});
</script>
</head>
<body>
<div>
<div style="width: 750px; margin: 0px auto">
<form id="formId" action="submit.action" method="post">
<div id="uploader">
<p>Flash, Silverlight, Gears, BrowserPlus,HTML5 .</p>
</div>
<input type="button" value="Clear" id="clear"/>
</form>
</div>
</div>
</body>
</html>
Action
#Action(value="plupUploaduploads")
public String upload() throws Exception {
isMultipart = ServletFileUpload.isMultipartContent(getReq());
System.out.println(getReq().getParameter("value"));
ServletContext servletContext = getReq().getServletContext();
String filePath = servletContext.getRealPath("/");
System.out.println(filePath);
System.out.println(this.file);
System.out.println(this.fileName);
System.out.println(this.contentType);
File theFile = new File("c:\\",this.getFileName());
FileUtils.copyFile(file,theFile);
return SUCCESS;
}
//getters and setters
i can see this on console according to print statements given.
o_17oq47949abc11n51pg11rnah06a.jpg
E:\Documents and Settings\Pluto\My Documents\NetBeansProjects\ShareApp\build\web\
c:\temp\upload__408094b5_13e30976641__7fea_00000003.tmp
null
null
is it the problem in my struts config? I am using annotations hence dont have struts.xml file. Or the problem is in plupload sending the file name, because when i retrived the name parameter i am getting some different name "o_17oq47949abc11n51pg11rnah06a.jpg" which is not the actual name. If so how can i get the original name?
Thanks and regards
I still don't understand why you are using all this plugins to perform an operation that simple. Do you need AJAX upload ? If not, you can simply use <s:file /> to upload one or more files to Action, with automatic filesize check, filename and contenttype detection, by simply declaring three variables with the same prefix into your Action:
Action code:
private File fileUpload;
private String fileUploadContentType;
private String fileUploadFileName;
/* getters and setters */
JSP code:
<s:file name="fileUpload" />
Then you can perform a client-side (HTML5, with javascript) filesize check, a server-side filesize check, and set a server-side overall multipart request size (in Struts.xml, that you should have even when using Annotations).
You can read the details here: struts2 s:form element trims the s:url parameter in the action attribute
As a final suggestion: make something simple that works, then start customizing / extending it.
Solution:
Add fileupload interceoptor in struts.xml (< interceptor-ref name="fileUpload" />)
Add the following properties in the action class.
private String[] fileFileName;
private String[] fileContentType;
private File[] file;
It is solved now. I set unique_names : false in plupload options. The content type and filename are null in struts action. I retrieved file name using getParameter("name");.