Hello once again everone,
Yesterday, I went through the XWiki main API reference guide at
http://platform.xwiki.org/xwiki/bin/download/DevGuide/API/xwiki-core-1.7.2-…
.
I was wondering if the Context class could be used to pass parameter from
one page to another (let's say input page to the page which does the actual
database insert using groovy).
There are two methods defined in the Context class:
1.put
@Programming
public void *put*(java.lang.String key,
java.lang.Object value)
Puts an object on the context using the given key. The context can be seen
as a map of (paramName, paramValue) pairs. Requires programming rights.
*Parameters:*key - The parameter name.value - The parameter value.
2. get
@Programming
public java.lang.Object *get*(java.lang.String key)
Returns the value associated with the given key in the XWiki context.
Programming rights are needed in order to call this method. The context can
be seen as a map of (paramName, paramValue) pairs. This mechanism is useful
for passing parameters between pages or from Java to Velocity. For instance
an exception caught in Java code can be put on the context and handled in a
user-friendly way in Velocity. This method is protected because sensitive
information may be placed in the internal context, which shouldn't be
publicly accessible.
*Parameters:*key - The key to look for in the context. *Returns:*The value
associated with the given key in the XWiki context, if you have programming
rights, or null otherwise.Would it be possible to use the put method to
assign a parameter and get to retrieve this parameter in the next page.
I tried my little experiment with an html form with the action set to
another page. This html form page sets the parameters using the put()
method. However, when i try to access the parameter using the get() method
on the next page, I get null values.
I've tried context.put("key1","value1") and
context.put('key1','value1') and
also context.put(key1,value1). The first two give me null values whereas the
last technique gives me a script error (probably because my syntax is
incorrect).
I am pretty sure that i do have programming rights since using just
context.getDatabase() gives me the database name.
Requesting some assistance here...
Thank you in advance.
On Sat, Apr 18, 2009 at 6:16 PM, Dilipkumar Jadhav <
jadhav.dilipkumar(a)gmail.com> wrote:
Hello Friends,
I have been asked to connect an external database with XWiki (XWiki will be
used as the application & MySql as the database).
I am using XWiki Enterprise 1.7.14685 :: MySql 5.0.
The external database (let's call it titan) is on the same mysql instance
(port) as XWiki database itself.
The requirement is to fetch user input (in terms of check boxes, radio
buttons & text boxes) from XWiki page and insert it into database.
Also, some degree of read operation from the database is required.
I've been able to read from my external database using the following code
directly in my XWiki page (under XWiki 1.0 syntax):
<%
import groovy.sql.Sql
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/titan",
"root",
"test", "com.mysql.jdbc.Driver")
sql.eachRow("select * from user"){
println "${it.user}"
}
%>
Hence, I am confident that an update or insert operation can be performed
with ease too (thanks to the groovy page at
http://groovy.codehaus.org/Database+features).
But I am not familiar with how to retrieve session parameters from the page
context. Could someone please guide me to a resource or a working example of
fetching context variables/parameters. Maybe it is a very simple solution,
but I have very little background in velocity. Any help would be much
appreciated.
Also, any time-frame on the page rating feature which is being discussed
very often now?(what version we could expect to see it?). Also, would page
rating be available for all the documents in an existing wiki (as in
embedded in the velocity templates) or would it be available only for newly
created pages/documents.
Thank you everyone...