cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Johnston <coc...@lojjic.net>
Subject Re: Dynamic selection list
Date Tue, 04 Jul 2006 17:08:24 GMT
Toby wrote:
> I'm trying to implement a dynamic selection list for a form field.
> I need to extract the selection values and labels from a database.
> 
> The only way of filling a selection list with dynamic values, that I
> could glean from the documentation, is by using flow-jxpath.
> 
> Which poses the problem of how to make a SQL query in javascript.

It can be done, though the syntax isn't quite as nice.  You could also 
implement the query in a Java method and just call that method from 
Javascript to get back a List of items.

But there's also JavaSelectionList, which mysteriously doesn't appear to 
be in the published user docs.  It sounds like this is closer to what 
you're looking for.

To use it, create a Java class that extends 
AbstractJavaSelectionList[1].  It will need to implement the build() 
abstract method; in this method you can run your query to get the list 
of items, and then add those items to the selection list by calling 
addItem(value, label) for each.  Then return either true or false 
depending on whether or not you want the selection list to be rebuilt 
every time or just the first time.

Then in your form definition, reference your class like so:

<fd:field id="...">
    ...
    <fd:selection-list type="java" class="foo.bar.MyJavaSelectionList" />
</fd:field>

The fd:selection-list element also accepts a nullable="true" attribute 
for if you want a null item to be added to the top of the list.

In addition, you can add any arbitrary attributes you want and then 
access their values within your Java class via getAttribute(name).  This 
is a very easy way to use the same class many times with different 
parameters affecting its behavior.

Hope that helps!
--Jason

[1] 
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/datatype/AbstractJavaSelectionList.html


> 
> Or, if flowscript could fetch an arbitrary sitemap URI and access the
> generated XML data, I could write the query in ESQL.  Is it possible?
> 
> Am I barking at the wrong tree here?  How should I proceed?
> 
> 
> Toby
> 


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


Mime
View raw message