Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>Let's assume we want to use the temperature conversion service from grails. In order to make the project minimal, we will modify the default view of the project, add a controller proxying to the service and generate a minimal view to display the result. Here we go:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> grails create-app hotstuff cd hotstuff vi grails-app/views/index.gsp </pre></td></tr></table> <p>Modify the default view to</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <html> <head> <title>Welcome to Grails</title> <meta name="layout" content="main" /> </head> <body> <g:form name="temperature" controller="temperature" action="conversion"> <p> <g:set var="units" value="${['Fahrenheit', 'Celsius']}" /> Convert <g:textField name="value" value="10.0" /> <g:select name="from" from="${units}" /> in <g:select name="to" from="${units}"/> </p> <g:submitButton name="submit" value="Convert" /> </g:form> </body> </html> </pre></td></tr></table> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> grails create-controller temperature </pre></td></tr></table> <p>Here is the controller code:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import groovyx.net.ws.WSClient class TemperatureController { def index = { } def conversion = { def proxy = new WSClient("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL", this.class.classLoader) proxy.initialize() def message if (!params?.value || params.from.equals(params.to)) { message = "Units are probably the same. Don't aske me :)" } else { def result if ("Celsius".equals(params.from)) { result = proxy.CelsiusToFahrenheit(params.value) } else { result = proxy.FahrenheitToCelsius(params.value) } message = "${params.value} degrees ${params.from} are ${result} degrees ${params.to}" } flash.message = message } } </pre></td></tr></table> <p>Then, we create the view to display the result</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> mkdir grails-app/views/temperature vi grails-app/views/temperature/conversion.gsp </pre></td></tr></table> <p>Here is the simplistic view:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta name="layout" content="main" /> <title>Here we are</title> </head> <body> <div class="body"> <g:if test="${flash.message}"> <div class="message">${flash.message}</div> </g:if> </div> </body> </html> </pre></td></tr></table> <p><img class="emoticon emoticon-cross" data-emoticon-name="cross" border="0" src="/s/en_GB/3278/15/_/images/icons/emoticons/error.png" alt="(error)" title="(error)" /> Currently, the Grab annotation cannot be used without interfering with native grails jars, so you have to add the following jars into your application lib directory</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>$ ls -lrt lib/ total 31960 -rw-r--r-- 1 alleon alleon 26072 Apr 15 11:01 groovyws-0.5.0-SNAPSHOT.jar -rw-r--r-- 1 alleon alleon 4201229 Apr 15 11:03 cxf-bundle-2.1.4.jar -rw-r--r-- 1 alleon alleon 520969 Apr 15 12:48 wstx-asl-3.2.7.jar -rw-r--r-- 1 alleon alleon 60686 Apr 15 13:31 commons-logging-1.1.1.jar -rw-r--r-- 1 alleon alleon 1485863 Apr 15 13:31 bcprov-jdk15-140.jar -rw-r--r-- 1 alleon alleon 143806 Apr 15 13:31 XmlSchema-1.4.4.jar -rw-r--r-- 1 alleon alleon 291779 Apr 15 13:31 FastInfoset-1.2.2.jar -rw-r--r-- 1 alleon alleon 226915 Apr 15 13:31 jaxen-1.1.1.jar -rw-r--r-- 1 alleon alleon 3127729 Apr 15 13:31 jaxb-xjc-2.1.9.jar -rw-r--r-- 1 alleon alleon 856752 Apr 15 13:31 jaxb-impl-2.1.9.jar -rw-r--r-- 1 alleon alleon 89967 Apr 15 13:31 jaxb-api-2.1.jar -rw-r--r-- 1 alleon alleon 14611 Apr 15 13:31 geronimo-ws-metadata_2.0_spec-1.1.2.jar -rw-r--r-- 1 alleon alleon 28804 Apr 15 13:31 geronimo-stax-api_1.0_spec-1.0.1.jar -rw-r--r-- 1 alleon alleon 47817 Apr 15 13:31 geronimo-jaxws_2.1_spec-1.0.jar -rw-r--r-- 1 alleon alleon 204851 Apr 15 13:31 geronimo-javamail_1.4_spec-1.5.jar -rw-r--r-- 1 alleon alleon 12452 Apr 15 13:31 geronimo-annotation_1.0_spec-1.1.1.jar -rw-r--r-- 1 alleon alleon 34126 Apr 15 13:31 geronimo-activation_1.1_spec-1.0.2.jar -rw-r--r-- 1 alleon alleon 444503 Apr 15 13:31 xmlsec-1.4.2.jar -rw-r--r-- 1 alleon alleon 84091 Apr 15 13:31 xml-resolver-1.2.jar -rw-r--r-- 1 alleon alleon 3176148 Apr 15 13:31 xalan-2.7.1.jar -rw-r--r-- 1 alleon alleon 313982 Apr 15 13:31 wss4j-1.5.6.jar -rw-r--r-- 1 alleon alleon 148429 Apr 15 13:31 wsdl4j-1.6.2.jar -rw-r--r-- 1 alleon alleon 278281 Apr 15 13:31 serializer-2.7.1.jar -rw-r--r-- 1 alleon alleon 278145 Apr 15 13:31 saaj-impl-1.3.2.jar -rw-r--r-- 1 alleon alleon 18817 Apr 15 13:31 saaj-api-1.3.jar -rw-r--r-- 1 alleon alleon 32900 Apr 15 13:31 neethi-2.0.4.jar -rw-r--r-- 1 alleon alleon 153115 Apr 15 13:31 jdom-1.1.jar </pre></td></tr></table> <p><img class="emoticon emoticon-warning" data-emoticon-name="warning" border="0" src="/s/en_GB/3278/15/_/images/icons/emoticons/warning.png" alt="(warning)" title="(warning)" /> If you have been running our very first example all these jars are probably in your </p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>~/.groovy/grapes/</pre></td></tr></table> <p> directory</p> <h3>BuildConfig.groovy</h3> <p>If you reference groovyws in your grails app then you will need a set of exclusions to prevent version conflicts ( from list <a href="http://grails.1312388.n4.nabble.com/Consume-web-service-in-Grails-app-td1585031.html#a3499373">Nabble - Ronny Løvtangen</a> ):</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> compile("org.codehaus.groovy.modules:groovyws:0.5.2") { excludes 'geronimo-servlet_2.5_spec', 'servlet-api', 'jaxb-xjc', 'jaxb-impl', 'xml-apis', 'saaj-impl', 'junit', 'slf4j-jdk14', 'xmlParserAPIs', 'jaxb-api', 'saaj-api', 'xmlbeans', 'jaxen', 'geronimo-stax-api_1.0_spec', 'geronimo-activation_1.0.2_spec', 'abdera-client', 'geronimo-activation_1.1_spec' } </pre></td></tr></table>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced