a little Howto get the values of a form you just submitted

my form will be composed only with one field ; 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 ?

GroovyGetFormsParameters (last edited 2009-09-20 23:41:47 by localhost)