Evelina:
Congratulations; you sent me to the dictionary in my own language! I
presume that you mean that the documentation is full of holes, which is
charitable of you; like most software not sold commercially, it's more
like one large hole, in which one occasionally finds something useful.
One positive comment is that (aside from giving two classes the same
name) the Javadocs are as useful as they can be with virtually no
comments because the names of methods and their arguments are about as
meaningful as one could hope for.
What the Velocity manual can't tell you, of course, is what can be found
in XWiki's Velocity context, and that's the whole story. I don't
remember where I found the following; it's been a long time.
There are five objects placed in the Velocity context available to a
user page by the XWiki action servlet. They are:
* xwiki - XWiki object wrapper (class com.xpn.xwiki.api.XWiki,
subclassed from com.xpn.xwiki.api.Api) giving rights-controlled access
to the core XWiki object (class com.xpn.xwiki.XWiki)
* context - the XWiki context, (class com.xpn.xwiki.api.Context), an
access-controlled wrapper for the XWikiContext object, which also
contains a reference to the Velocity context from which you got it
* doc - com.xpn.xwiki.api.Document, API wrapper for the
com.xpn.xwiki.doc.XWikiDocument representing the current document
* request - com.xpn.xwiki.web.XWikiRequest, an XWiki-specific wrapper
for the HttpServletRequest or HttpPortletRequest to which the current
action is responding
* response - com.xpn.xwiki.web.XWikiResponse, an XWiki-specific wrapper
for the HttpServletResponse or HttpPortletResponse with which the action
will respond
A helpful way to tie the XWiki Velocity script stuff to the actual Java
APIs is: starting from those five objects, you can get all of their
properties to which Velocity, XWiki, and the Java permissions structure
will allow you access, and since all of them inherit from
java.lang.Object, you can get their class names by appending ".class" to
the variable reference (which Velocity translates to ".getClass()") to
display its Class object, whose toString() method is invoked to return
its fully-qualified classname. From that, you can go to the Javadocs
for the named class; that's how I did most of my debugging before I
started running XWiki under Eclipse.
Looking at the J2EE Servlet API (available from
java.sun.com) will show
that the HttpServletRequest interface has methods to get the various
pieces of the request, of which the GET parameters are found in method
getQueryString(), which XWikiRequest wraps in a method called
getParameter(paramName), which through some magic or other XWiki tells
Velocity to call with the reference $request.paramName.
As an aside, note that it actually doesn't matter whether the HTTP
request method is GET or POST as far as XWikiRequest is concerned; the
value of a form field named "paramName" will be returned by
XWikiRequest.getParameter(paramName), and hence $request.paramName
within Velocity, in exactly the same way as if it were in the GET query
string.
So, to sum up: if a browser sends XWiki the request URL
http://myhost.org/xwiki/bin/view/Me/MyDoc?param1Name=foo¶m2Name=bar=bar,
then the XWiki document Me.MyDoc will find $request.param1Name returns
"foo", and that $request.param2Name is "bar". See the Javadocs for
more
methods to get a Map of all the name/value pairs, or an Enumeration of
just the names, etc. Further, the Velocity #foreach directive works
great for stepping through nearly any kind of standard Java collection
you can throw at it.
My apologies if I misunderstood the question, of course, but I think
that should get you started...
brain[sic]
-----Original Message-----
From: evelyne24(a)gmail.com [mailto:evelyne24@gmail.com]
Sent: Thursday, May 10, 2007 2:45 AM
To: xwiki-users(a)objectweb.org
Subject: [xwiki-users] How to use GET/POST in xwiki
I have a question regarding the use of GET/POST in xwiki. How
do I send to a velocity script a string using GET or maybe
something similar (like $context??) in xwiki?
I read something about xwiki context, like getResponse() and
getRequest(), but I would like an example to understand
better, because the api is very lacunal. Thank you.
Evelina Slatineanu