cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Derek Hohls" <DHo...@csir.co.za>
Subject Re: [CForms] Setting dynamic values in selection-list?
Date Tue, 20 Jul 2004 06:22:20 GMT
The way I would approach it, is *not* to write new code
but to make use of the existing functionality in Cocoon.

In your form model, you will have:

    <fd:field id="movie-theme">
      <fd:label>Movie Theme</fd:label>
      <fd:datatype base="string"/>
        <fd:selection-list  src="cocoon:/form-sql/theme.xml"
dynamic="true"/> 
    </fd:field> 


The source for this list comes from a Cocon pipeline
(assumes you have setup your connection correctly)
which is in your sitemap:

   <!-- === data for form from database list === -->
   <map:match pattern="form-sql/theme.xml">
     <map:generate src="docs/basic-sql.xml"/>
     <!-- === SQL Connector ==== -->       
     <map:transform type="sql">
       <map:parameter name="use-connection" value="movie_user"/>
       <map:parameter name="show-nr-of-rows" value="true"/> 
       <map:parameter name="clob-encoding" value="UTF-8"/> 
     </map:transform> 
     <map:transform src="stylesheets/widget-theme.xsl"/>
     <map:serialize type="xml"/>
   </map:match>


Where the two key files are the basic-sql.xml and widget-theme.xsl

basic-sql.xml (to access database and generate datae)

<?xml version="1.0" encoding="UTF-8"?>
<fd:selection-list
  xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
>
  <sq2:execute-query xmlns:sq2="http://apache.org/cocoon/SQL/2.0"> 
    <sq2:query name="themes">
       SELECT ThemeID, ThemeDesc FROM MovieTheme
    </sq2:query>
  </sq2:execute-query>
  </fd:selection-list>

widget-theme.xsl (to create the correct format for the selection list)

<?xml version="1.0"  encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
  xmlns:sq2="http://apache.org/cocoon/SQL/2.0" 
  >

<xsl:template match="/">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="fd:selection-list">
<fd:selection-list>
  <xsl:apply-templates select="sq2:rowset"/>
</fd:selection-list>
</xsl:template>

<xsl:template match="sq2:rowset">
  <xsl:apply-templates select="sq2:row"/>
</xsl:template>

<xsl:template match="sq2:row">
  <fd:item value="{sq2:themeid}"><fd:label><xsl:value-of
select="sq2:themedesc"/></fd:label></fd:item>
</xsl:template>

</xsl:stylesheet>


Hope this helps!
Derek


>>> cromosom@gmx.net 2004/07/19 09:35:25 PM >>>
Hello,

I want to display a selection box in my form. I had seen that CForms 
support such kind of formfield: selection-list. But all examples only 
shows handling static values. Is it possible to set the values for the

selection box from a database (dynamically) using the form binding? Do

you have an example about this? Do I need the repeater for this?

Thank you!

Regards

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org 
For additional commands, e-mail: users-help@cocoon.apache.org 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message