Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, Grails uses a MVC pattern and therefore you should not directly change a domain class property within a GSP page.</p> <p>Of course you can use the JQuery date picker but you should provide a controller action to update your domain class property</p> <pre><code>def updateDateUsingAjax() { def domain = MyDomain.load(params.id) /* Lets pretend the content of params.date has the format MM/dd/yyyy You can use Date.parse method of the Groovy JDK to create a java.util.Date instance of a String. http://groovy.codehaus.org/groovy-jdk/java/util/Date.html#parse(java.lang.String, java.lang.String) */ domain.myDate = Date.parse('MM/dd/yyyy', params.date) domain.save() } </code></pre> <p>Now all you have to write is an Ajax call to this controller action and you successfully separated the presentation layer from the rest of your application.</p> <p>And here is how your GSP could look like.</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;meta name="layout" content="main"/&gt; &lt;title&gt;Welcome to Grails&lt;/title&gt; &lt;r:require module="jquery-ui"/&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;g:formRemote name="myForm" url="[controller: 'standard', action: 'updateDateUsingAjax']" onSuccess="showDialog()"&gt; &lt;p&gt;Your date: &lt;g:textField name="pick"/&gt; &lt;/p&gt; &lt;p&gt;&lt;g:hiddenField name="id" value="your id"/&gt;&lt;/p&gt; &lt;input type="submit" value="Delete Book!" /&gt; &lt;/g:formRemote&gt; &lt;/div&gt; &lt;div id="dialog" title="Success" style="display:none;"&gt; &lt;p&gt;You have successfully updated your date&lt;/p&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $("#pick").datepicker({dateFormat: 'yy/mm/dd'}); }) function showDialog() { $("#dialog").dialog(); } &lt;/script&gt; &lt;/body&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload