You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Stephan Coboos <cr...@gmx.net> on 2004/07/19 21:35:25 UTC

[CForms] Setting dynamic values in selection-list?

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


Re: [CForms] Setting dynamic values in selection-list?

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 19/lug/04, alle 21:35, Stephan Coboos ha scritto:

> 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?

See the carselector and countryselector samples. The best way to do it, 
IMHO, is to use a type="flow-jxpath" selection-list and pass a 
collection to showForm.

	Ugo

-- 
Ugo Cei - http://beblogging.com/

Re: [CForms] Setting dynamic values in selection-list?

Posted by Tony Edwards <te...@civica.com.au>.
Hi Stephan,
I use good old xsp to query a database and return the results as 
fd-selection items.
Behold:


                <esql:results>
                    <esql:row-results>
                   
                        <xsp:logic>
                            int hcy_num = <esql:get-int column="hcy_num"/>;
                            String hierarchy = <esql:get-string 
column="dsc_lv1"/>.trim();
                        </xsp:logic>                               
                       
                        <fd:item><xsp:attribute 
name="value"><xsp:expr>hcy_num</xsp:expr></xsp:attribute>
                            
<fd:label><xsp:expr>hierarchy</xsp:expr></fd:label>
                        </fd:item>
                       
                    </esql:row-results>
                </esql:results>

Then in your form definition, you specify the selection list as dynamic:
            <fd:selection-list src="cocoon:/resources/getHcyList.xsp" 
dynamic="true"/>

Hope this helps,

Tony


Scott Yeadon wrote:

>Hi Stephan,
>
>One way of doing it is to specify a pipeline on your fd-selection list 
>element's src attribute in the form definition and use an internal 
>pipeline to turn the results of your db query into the fd:selection-list
>
>markup. There are certainly other ways, but I like to avoid scripting 
>within cocoon (prefer to use only the XML and Java, minimising 
>cocoon-specific scripting and JavaScript) and I see this as one clean 
>way of doing it.
>
>E.g.
>In form definition:
>...
><fd:selection-list src="cocoon:/myListPipeline"/>
>...
>
>In Sitemap:
>...
><map:generator name="aGenerator" src="my.package.GeneratorClass"/>
>...
><map:pipeline intermal-only="true">
><map:match pattern="myListPipeline">
>    <map:generate type="aGenerator">
>        <map:paraneter name="aParm" value="aParmValue"/>
>        ...
>    </map:generate>
>    <map:serialize type="xml"/>
></map:match>
></map:pipeline>
>
>The output of the pipeline is serialized XML such as
><fd:selection-list>
><fd:item value="aValue"/>
><fd:item value="anotherValue"/>
></fd:selection-list>
>
>You need to write your own generator (and any transformers you want) but
>
>the cocoon doco is pretty clear on doing that. If you make the generator
>
>generic enough you can also re-use it for other lists or queries (e.g. 
>you could pass a basic query as a parameter). There may be some cocoon 
>generators already that may help with this but not sure (check out the 
>generator page).
>
>Scott.
>
>Stephan Coboos wrote:
>
>  
>
>>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
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>  
>

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


Re: [CForms] Setting dynamic values in selection-list?

Posted by Scott Yeadon <sc...@anu.edu.au>.
Hi Stephan,

One way of doing it is to specify a pipeline on your fd-selection list 
element's src attribute in the form definition and use an internal 
pipeline to turn the results of your db query into the fd:selection-list 
markup. There are certainly other ways, but I like to avoid scripting 
within cocoon (prefer to use only the XML and Java, minimising 
cocoon-specific scripting and JavaScript) and I see this as one clean 
way of doing it.

E.g.
In form definition:
...
<fd:selection-list src="cocoon:/myListPipeline"/>
...

In Sitemap:
...
<map:generator name="aGenerator" src="my.package.GeneratorClass"/>
...
<map:pipeline intermal-only="true">
<map:match pattern="myListPipeline">
    <map:generate type="aGenerator">
        <map:paraneter name="aParm" value="aParmValue"/>
        ...
    </map:generate>
    <map:serialize type="xml"/>
</map:match>
</map:pipeline>

The output of the pipeline is serialized XML such as
<fd:selection-list>
<fd:item value="aValue"/>
<fd:item value="anotherValue"/>
</fd:selection-list>

You need to write your own generator (and any transformers you want) but 
the cocoon doco is pretty clear on doing that. If you make the generator 
generic enough you can also re-use it for other lists or queries (e.g. 
you could pass a basic query as a parameter). There may be some cocoon 
generators already that may help with this but not sure (check out the 
generator page).

Scott.

Stephan Coboos wrote:

> 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
>


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