cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stev...@outerthought.org
Subject [WIKI-UPDATE] HowTos Main GroovyGetFormsParameters Tue Jun 8 12:00:06 2004
Date Tue, 08 Jun 2004 10:00:06 GMT
Page: http://wiki.cocoondev.org/Wiki.jsp?page=HowTos , version: 168 on Mon Jun  8 10:57:57
2004 by 195.5.211.156

+ 
+ * __[Groovy Get Forms Parameters]__ -- how to use Groovy to get values of parameters from
Forms ? - olivier demah


Page: http://wiki.cocoondev.org/Wiki.jsp?page=Main , version: 460 on Mon Jun  8 09:01:57 2004
by Andrew

- * June 8, 2004
- ** Slove [Chinese program] of FOP


Page: http://wiki.cocoondev.org/Wiki.jsp?page=GroovyGetFormsParameters , version: 1 on Mon
Jun  8 10:55:26 2004 by 195.5.211.156

New page created:
+ __a little Howto get the values of a form you just submitted__
+ 
+ my form will be composed only with one fields ; a select multiple ; to see how to get the
choosen values.
+ 
+ the little piece of xsl :
+ {{{
+ <form action="fox.xml" method="post">
+    <fieldset><legend>Players</legend>
+        <select name="player_url_name[]" multiple="multiple">
+             <option value="Player1">The is the Player1</option><br/>
+             <option value="Player2">The is the Player2</option><br/>
+             <option value="Player3">The is the Player3</option><br/>
+             </select>
+     </fieldset>
+     <fieldset><legend>Valid</legend
+         <input type="submit" value="ok" name="valid"/>
+      </fieldset>
+ </form>
+ }}}
+ 
+ 
+ the __pipeline__ in the __sitemap.xmap__ :
+ {{{
+     <map:match pattern="fox.xml">
+         <map:generate type="script" src="fox.groovy"/>
+         <map:serialize type="xml"/>
+     </map:match>
+ }}}
+ 
+ 
+ 
+ the groovy script __fox.groovy__ : 
+ 
+ {{{
+ 
+ import org.apache.cocoon.environment.ObjectModelHelper
+ 
+ import groovy.xml.SAXBuilder
+ 
+ // get the parameters from the form
+ objectModel = bsf.lookupBean("objectModel");
+ request = ObjectModelHelper.getRequest(objectModel);
+ 
+ player_url_name = request.getParameterValues("player_url_name[]");
+ 
+ // Create a Groovy Builder which writes directly to
+ // the Cocoon pipeline
+ contentHandler = bsf.lookupBean("contentHandler")
+ xml = new SAXBuilder(contentHandler)
+ 
+ // Builder does not seem to call this
+ contentHandler.startDocument()
+ 
+ xml.root() {
+     foxyz() {
+         // loop in the array and make my appropriate node
+        for ( i in player_url_name ) {
+                player("${i}")
+         }
+     }
+ }
+ 
+ contentHandler.endDocument()
+ }}}
+ 
+ the generating __xml output__ after choosing all the players :
+ 
+ {{{
+ <?xml version="1.0" encoding="ISO-8859-1"?>
+ <root>
+  <foxyz>
+    <player>Player1</player>
+    <player>Player2</player>
+    <player>Player3</player>
+  </foxyz>
+ </root>
+ }}}
+ 
+ ----
+ 
+ Thanks to Bertrand Delacretaz for his help about bsf.lookupBean 
+ 
+ - olivier demah -
+ 
+ [how to use Groovy with SQL database access ?|http-link-towiki.cocoondev.org/Wiki.jsp?page=GroovyWithSQLDatabaseAccess]
+ 



Mime
View raw message