This blog is not about Studio, and frankly, it hurts. Well, I will talk about Nuxeo Studio a little bit because it is something requested by, well, life. As the saying goes: "A Studio a Day Keeps the Doctor Away".
It is about what the title states. And the title being very long, I am not repeating it here, but I assume you, dear reader, understand what I want to achieve:
- Have Suggestion Widget
- Fill it with data coming from a Web Service
Something like that:
This potentially requires some complex code. Complex, possibly complicated, maybe long to write. All these complex, complicated and long things do not fit at all with my lazy, lazy way of living, so I decided to use what Thierry Delprat(1) already wrote: A nuxeo-directory-connector, because the purpose of this plug-in is to provide "all the plumbing code to expose a Java Class implementing a simple interface as a Nuxeo Directory".
Sounds good. I'm not a big fan of plumbing: Using other people's plumbing works for me.
So, basically, I forked the plug-in and added an example calling our public demo site, demo.nuxeo.com. Once everything is installed and running, here is how it works in the browser, using a Suggestion Widget bound to the custom directory: When you click in the suggestion widget, you will wait some seconds (so it makes the call to the web service), and it will be filled with the titles of documents (a limit of 200) coming from demo.nuxeo.com. Then, If you enter “case”, or “study” in the widget, you will see the list being reduced.
Explanations and an example can be found here. I used the
JsonInMemoryDirectoryConnector to achieve my goal, and hopefully the README will be enough to understand how things work. There are also explanations in the
NuxeoDemoComInMemoryConnector class and in the
To test this plug-in (and assuming you have Maven correctly installed on your computer):
- Compile-it (
mvn package -DskipTests=true skipTests2)
- Install it in
- Update your Studio(3) project so it uses this plug-in. In a layout (creation, edit, view):
- Drop, a text field
- Choose the “Directory Suggestion” widget
- At the bottom of the properties, add a custom property:
- Key: “directoryName”
- Value: “demoNuxeoComDocuments” (this is the name of the directory as declared in miscDirectoryConnectorsContrib.xml)
- Start the server, update it with the Studio project
In the previous screen shot, I bound the selected value to a custom field, testdoc:external_doc_ref. The point is that the plug-in stores te id of the document, not the title, which is cool (if the title change, all stays good on our side):
(1) Thierry is our CTO. Sometime, he writes code.
(2) Skipping the test will save you 10 seconds but it’s not good habit, you should not do it. Nobody can testify he/she saw me Skipping test
(3) Remember: "Keeps the Doctor Away"