Some libraries have duplicate dependencies.
If you want prevent errors and warnings you should exclude duplicates from one of library:
compile (‘org.docx4j:docx4j-ImportXHTML:3.2.1’) { exclude “slf4j-log4j12” }
Some libraries have duplicate dependencies.
If you want prevent errors and warnings you should exclude duplicates from one of library:
compile (‘org.docx4j:docx4j-ImportXHTML:3.2.1’) { exclude “slf4j-log4j12” }
First off all you could find out some plugins https://grails.org/plugins/search?q=mongo
1. Edit BuildConfig.groovy
add string like this: compile ‘org.mongodb:mongo-java-driver:3.0.3’ to dependencies section
dependencies { //... compile 'org.mongodb:mongo-java-driver:3.0.3' }
2. Edit Config.groovy
mongodb.uri = "mongodb://username:password@your.mongodb.server/yourDataBaseName" mongodb.database = "yourDataBaseName"
3. Add to resources.groovy
beans = { mongoClientURI(MongoClientURI) { bean -> bean.constructorArgs = [grailsApplication.config.mongodb.uri.toString()] } mongoClient(MongoClient) { bean -> bean.constructorArgs = [ref(mongoClientURI)] bean.destroyMethod = 'close' } mongoDb(mongoClient: 'getDB') { bean -> bean.constructorArgs = [grailsApplication.config.mongodb.database.toString()] } }
4. Add to any controller (in my case MyController)
package mypackage import com.mongodb.DB class MyController { DB mongoDb def users() { def collection = mongoDb.getCollection('myCollection') collection.insert(new BasicDBObject(['name':'Piter'])) def users = collection.find(new BasicDBObject(['name':'Piter'])).toArray() render (contentType: 'application/json', text: JSON.serialize(users)) } def user() { def userId = params.userId def collection = mongoDb.getCollection('myCollection') def user = collection.findOne(new BasicDBObject(['_id': new ObjectId(userId)])) render (contentType: 'application/json', text: JSON.serialize(user)) } }
I have some view (“basicView.gsp”) and want to pass other view content (“_someTemplate.gsp”) to this view to javascript variable (“template”).
basicView.gsp:
<html> <head> ... </head> <body> ... <script> var template = '${raw(include(view:"myTemplates/_someTemplate.gsp").replaceAll('\n',''))}'; </script> </body> </html>
_someTemplate.gsp:
<div> <h1>Some header</h1> <p>Lorem ipsum dolor sit...</p> </div>
Resulted html:
<html> <head> ... </head> <body> ... <script> var template = '<div><h1>Some header</h1><p>Lorem ipsum dolor sit...</p></div>'; </script> </body> </html>
Details:
Create Grails app in ItelliJ IDEA 14 as in this manual –
https://vaadin.com/wiki/-/wiki/Main/Vaadin+on+Grails+-+Create+project+in+IntelliJ+IDEA
But use only 1. and 2. points.
After 2. point use next suggestions:
add to BuildConfig.groovy:
to dependencies – runtime ‘org.hibernate:hibernate-validator:5.1.1.Final’
to plugings – compile “:vaadin:7.5.2”
click Apply Grails changes to IDEA project structure
run – grails vaadin-quickstart
Next couple steps:
press “+” and select Grails:
select “your app” in Module:
change name on “your app name”:
result:
Thats all.
def someMap = [ 'phones':['iPhone','Galaxy','Nexus'], 'laptops':['HP','MacBook','Samsung'], 'tablets':['Galaxy Tab','iPad','Asus'], ] someMap.eachWithIndex{ k, v, index -> println "${k}:${v} - ${index}" }
Result:
phones:[iPhone, Galaxy, Nexus] – 0
laptops:[HP, MacBook, Samsung] – 1
tablets:[Galaxy Tab, iPad, Asus] – 2
def map = [a:"cc", b: "dd"] println "map - " + map println "map.keySet() - " + map.keySet() println "map.values() - " + map.values() println "map.entrySet() - " + map.entrySet() println "map.entrySet().key - " + map.entrySet().key println "map.entrySet().value - " + map.entrySet().value
Result:
map – [a:cc, b:dd]
map.keySet() – [a, b]
map.values() – [cc, dd]
map.entrySet() – [a=cc, b=dd]
map.entrySet().key – [a, b]
map.entrySet().value – [cc, dd]