Ok,

I ended up successfully setting my date parameter from a string 
combining velocity and groovy. Here is what I've done :

Created a Groovy class on a page named Project.DateParser :

/* Groovy Class : Date parser#* */

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

class DateParser {

  Date parse(toParse) {
    def formatter = new SimpleDateFormat("dd/MM/yyyy");
    return formatter.parse(toParse);
   
  }
}

/* *# */


Then I called it from my velocity script :

##Create an instance of my parser
#set($dateParser = $xwiki.parseGroovyFromPage("Project.DateParser"))
##Set the value from this parser calling its parse method
$releaseObj.set("startDate",$dateParser.parse($date))
##Save the doc
$releaseDoc.save()
##Write the saved property
${releaseObj.startDate}

Now it works really fine. I can edit my date parameters with Ajax and 
that's pretty cool stuff.

Jean

Jean Couteau a écrit :
> Hi xwiki users,
>
> I have a problem setting an object date property from a String.
>
> The code I am doing is :
>
> ($startDate is a string I got from the request)
>
> #if($context.getUser()!="XWiki.XWikiGuest")
>   #set($releaseDoc=$xwiki.getDocument("Project.${releaseid}"))
>   #set($releaseObj=$releaseDoc.getObject("XWiki.ReleaseClass"))
>   $releaseObj.set("startDate",$datetool.toDate($startDate))
>   $releaseDoc.save()
>   ${releaseObj.startDate}
> #else
>   NoRight
> #end
>
> This piece of code is placed on the Skin Object and I call it using Ajax 
> (I use an InPlaceEditor from scriptaculous)
>
> What I got in result from this is NoRight if I am not connected but a 
> wiki page with this template does not exist if i am logged in. I don't 
> understand what is missing.
>
> I tried using Groovy, but I got the Groovy code in response, it was not 
> executed.
>
> If someone can point out my error, I am all heard.
>
> Thanks in advance
>
> Jean
>   


-- 
----
Jean Couteau
Code Lutin - http://www.codelutin.com
44 Bd des Pas Enchantés - 44230 St-Sébastien/Loire
Tél : 02 40 50 29 28 - Fax : 09 59 92 29 28 

_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to