cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Johnston <>
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="" />

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!


> 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:
For additional commands, e-mail:

View raw message