Problems with Facets: schema property values of document not being saved

I am facing some problems and questions with facets.

Problem 1: Facet fields (assigned schema's fields) don't get saved:

I have defined a schema called 'InvoiceSchema' and a facet called 'InvoiceFacet' and assigned the schema to the facet, like this:

type an image title

type an image title

I enabled the facet for the document type 'File'

type an image title

and I change the edit and view layout to display the fields:

type an image title

Back in the JSF UI and after the update, the fields get displayed in the view and edit layouts. However, when I edit the value, they don't get stored.

type an image title

This is the view layout after saving the document. The confirmation message tells me that saving was successful, and values that I enter in other fields get updated just fine. Only the fields of my InvoiceSchema don't get saved.

type an image title

When I export the file as xml, I only see this in it:

<facet>InvoiceFacet</facet>

but I don't see the fields that I defined for my InvoiceSchema (like Amount, InvoiceDate, RecordId) anywhere in the xml.

Interestingly, if I don't use a facet that has my schema assigned, but add the schema directly to the File type, the problem does not exist and the values get saved. Looks like a bug to me?! Unfortunately I don't have a Jira account yet in order to submit it.

type an image title


Update after Betrand's reply:

Hello Bertrand,

thanks for your reply. I understood the explanation you gave above about the registry as well as the xml extension points. Not sure though where I am supposed to define the schema itself (in my case, the 'InvoiceSchema').

Did I do it right via “Studio > Content Model > Schemas” or should I register the schema via “Studio > Settings > Registries > Document Schemas”, or both. When I register the schema via the latter as well (additionally to having it defined under the Content Model > Schemas menu), then I get some validation errors like this:

saying “Invalid name 'InvoiceSchema' for a schema: this schema already exists in the default application”. So I removed the schema from the registry again. (From what I understand, I shouldn't need to register the schema in the registry anyway, since what I define under “Content Model” should be known both by my local Nuxeo instance (since it's part of my package) as well as the Studio.)

So, I assume it's sufficient to just define it under the “Studio > Content Model > Schemas”:

type an image title

I tried it out and deployed that package. But still the properties don't get stored when I save the document.

Looking at my package jar that I deployed, the xml extension and the schema including the properties are all included.

type an image title

Checking the log, I see this:

2017-01-30 18:19:59,277 WARN [http-bio-0.0.0.0-8080-exec-17] [org.nuxeo.ecm.platform.el.DocumentModelResolver] org.nuxeo.ecm.core.api.model.PropertyNotFoundException: InvoiceSchema:InvoiceDate 2017-01-30 18:19:59,277 WARN [http-bio-0.0.0.0-8080-exec-17] [org.nuxeo.ecm.platform.el.DocumentModelResolver] org.nuxeo.ecm.core.api.model.PropertyNotFoundException: InvoiceSchema:Amount 2017-01-30 18:19:59,278 WARN [http-bio-0.0.0.0-8080-exec-17] [org.nuxeo.ecm.platform.el.DocumentModelResolver] org.nuxeo.ecm.core.api.model.PropertyNotFoundException: InvoiceSchema:RecordId

Problem 2: How can I define view layout and edit layout for documents with certain facets?

Let's say I have a facet that is not assigned to all documents (= not as described in problem 1), but only to some, for example when the facet gets assigned dynamically via an automation, and the facet has a schema with some additional property fields assigned. How can I show these fields in the view and edit layout based on whether the document has this facet or not? I cannot find this option in the Studio. In Studio, I can only define the view and edit layouts fixed for a certain document type, but I cannot give any conditions, such as 'if the document has facet x applied'. How to solve this?

0 votes

1 answers

185 views

ANSWER



Hello Mathias,

Problem #1: To add a facet and use it in Studio, there are two things to do:

  1. Add an XML extension so that Nuxeo Platform knows about it
  2. Declare it in the registries so that it becomes visible in Nuxeo Studio

You did step #2. That means Studio will behave as if the facet exists in Nuxeo Platform, which is why everything works smoothly until you deploy your config. But as you are missing step #1, the facet doesn't actually exist in Nuxeo Platform!

To fix this, in Nuxeo Studio you need to declare the facet in the Advanced Settings > XML Extensions menu (make sure to replace with the appropriate facet and schema values of course):

<!-- This makes my facet available in Nuxeo Platform, then I can declare it in the registries -->
<extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
  <facet name="MyFacet">
    <schema name="MySchema"/>
  </facet>
</extension>

The reason Nuxeo Studio does not create the corresponding extension automatically when declaring a facet in the registries is because it could be contributed from somewhere else: another bundle or Studio project for instance. However, an improvement could be to better inform users and / or offer to do it => I'll create a ticket for that.

Problem #2:

In a layout, a widget's mode (edit, read only, hidden) can be changed depending on a custom condition. I may advise you to have a look at the documentation explaining how to control the display mode of a widget.

In your example, the condition to use should be something like:

#{currentDocument.hasFacet('MyFacet') ? 'edit' : 'hidden'}

The currentDocument variable relates to a DocumentModel object, so you can easily add further conditions and not only check for the facet.

– edit – Improvement ticket created: https://jira.nuxeo.com/browse/NXS-3810 Thanks for the feedback! :)

1 votes



Hello Bertrand, thanks for your reply. (I will give it a try, once I resolved some other issues I am having with the update mechanism of Studio, but that's another thing.) I understood the explanation you gave above about the registry as well as the xml extension points. Not sure though where I am supposed to define the schema itself (in my case, the 'InvoiceSchema'). Did I do it right via "Studio > Content Model > Schemas" or should I register the schema via "Studio > Settings > Registries > Document Schemas", or both. When I register the schema via the latter as well (additionally to having it defined under the Content Model > Schemas menu), then I get some validation errors like this: saying "Invalid name 'InvoiceSchema' for a schema: this schema already exists in the default application".
01/30/2017

Bertrand Chauvin I tried it with the xml extension for the facet, but it still does not save the properties. I updated my problem 1 above with a detailed descriptions and debugging information.
01/30/2017

I spawned a new Nuxeo docker container and the problem with the properties of my custom facet not being saved is gone. Basically using the same project configuration from the Studio. Maybe something was broken with the initial instance.
02/08/2017

Bertrand Chauvin Can the solution for problem #2 be achieved via Studio, or would the Studio then not work for this anymore?

Setting the condition in Studio is easy, but the problem is that I did not find a way to select the field / facet property in the first place, if it's not statically assigned to the document type, which it isn't, since I am adding the facet dynamically via automation chain.

Here is a screenshot of the problem:

I would like to add a string field to the 'File' document type layout, which should display the property InvoiceSchema:RecordId, where the InvoiceSchema is not always assigned to a File. The InvoiceSchema is not available in the 'Edit widget field binding' dialog (unless I would assign the schema statically). I was looking for a widget where I could freely type the schema and path, and not having to select it from a dropdown. But also the "Text" widget only offers a dropdown. I guess I could adjust it in the xml source directly, but then I guess the rest of the Studio layout editor cannot be used anymore for the layout configuration of that file type?!

02/08/2017

Nevermind, "Generic" is the correct widget to use… got it working now. Thanks for your help.
02/08/2017