[daisy] Help setting multivalue link field

Bruno Dumon bruno at outerthought.org
Mon Jan 21 06:33:35 CST 2008


On Sun, 2008-01-20 at 23:53 -0800, Derek Coffman wrote:
> Hi,
> 
> I am writing an "wizard" type extension to allow users to create and
> "InstrumentDefinition" document. The document contains a multivalue link
> field of "InstrumentTypes" (i.e., a list of documents of type
> "InstrumentType"). In the wizard, the user is presented with a
> double-listbox multivalue field and required to select at least one
> type. The types are show as the name of the InstrumentType. Once the
> user submits the completed form, I am trying to use getValue() of that
> widget which should return an array of Strings if I understand
> correctly. In order to set the multivalue link field, I need to turn
> those names into an array of VariantKey...correct?
> 
> My question: what is the best way to do this in javascript? Here's one
> iteration I've tried...
> 
>      var types = form.getChild("def_inst_types").getValue();
> 
>      var ids = new Array();
> 
>      for (i=1; i<types.length; i++) {
>          var type_str = types[i].toString();
> 
>          searchresults = queryManager.performQuery("select id where
> documentType='InstrumentType' and name='"+type_str+"'",locale.getDefault());
> 
>           rows =
> searchresults.getSearchResult().getRows().getRowArray();
> 
>                 var typeid = rows[0].getValueArray(0);
> 
>                 var typedoc =
> daisy.getRepository().getDocument(typeid,false);
>                 ids[i] = typedoc.getVariantKey();
> 
>       }
> 
>       var repository2 = daisy.getRepository();
>       var document = repository2.createDocument(title.toString(),
> "InstrumentDefinition");
>             document.setField("InstrumentTypes",ids);
> 
> 
> Am I completely off track here? When I run this, I get an error that says:
> 
> Wrapped org.outerj.daisy.repository.DocumentTypeInconsistencyException:
> The value for the multivalue-field "InstrumentTypes" should be an array.
> (file:/home/web/acglocal/daisy/acgwikidata/sites/cocoon/instrument/instrument.js#566)
> The value for the multivalue-field "InstrumentTypes" should be an array.
> 
> 

You need to supply a Java array instead of a Javascript array. The
javascript engine (rhino) doesn't automatically convert this.

See "Creating Java arrays" on this page:
http://www.mozilla.org/rhino/ScriptingJava.html

About the VariantKey's: this is a concrete class, you can immediately
instantiate it yourself. Doing repository.getDocument() is much more
expensive. So you can do:

new VariantKey(typeid, 1, 1)

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno at outerthought.org                          bruno at apache.org


More information about the daisy mailing list