Implementing a list widget for a predefined query

Hello,

How can I create a widget like the vocabulary widget (a user can select an item from a vocabulary list) but instead of the vocabulary list I want to have a list with items from a query. (i.e. I want the list to show all titles of documents belonging to a specific schema and be able to select one of them and set it as a property on another document on the creation page of that document).

Is there any documentation on this subject?

Thank you

0 votes

1 answers

1246 views

ANSWER



Hi,

There is an existing widget type called “multipleDocumentsSuggestion” (you can see its contribution here: http://explorer.nuxeo.org/nuxeo/site/distribution/Nuxeo%20DM-5.4.2/viewContribution/org.nuxeo.ecm.platform.forms.layouts.webapp.base–widgettypes) that can match your need, although it only handles lists of documents (no single selection). The page provider on this widget type can be configured, so that you can set your specific logic (e.g search among documents holding a given schema). The documentation for page providers is available at http://doc.nuxeo.com/x/HgFu.

If you'd like to have a simple selection instead of a suggestion, you can define a custom widget template (see the doc at http://doc.nuxeo.com/x/vwY7), using the nxu:selectItems tags will probably make your life easier (http://community.nuxeo.com/api/nuxeo/5.4/tlddoc/nxu/selectItems.html). You'll have to bind it to a seam component that will perform the query directly, or use a page provider to get the list of documents if you'd like the filtering to be configurable on the widget so that it's more generic and can be reused in different use cases (and you would also be able to reuse its other features, like handling the maximum number of results to avoid overloading the server if there are too many matching documents).

Note also that this kind of “rich” widget types is part of improvements we'd like to make on the platform so that it's available by default, and is easier to use and configure.

2 votes