cancel
Showing results for 
Search instead for 
Did you mean: 

Add your own vocabulary

Dalal_
Confirmed Champ
Confirmed Champ

I'm writing a layout contribution, I added a suggestOneDirectory widget named city but I don't know where can I change/add my own directoryName (instead of l10ncoverage) that contains the vocabulary of cities to be shown on the list.

     <widget name="city" type="suggestOneDirectory">
        <labels>
          <label mode="any">City :</label>
        </labels>
        <translated>true</translated>
        <fields>
          <field>adr:city</field>
        </fields>
        <properties mode="any">
          <property name="width">300</property>
          <property name="labelFieldName">label_{lang}</property>
          <property name="dbl10n">true</property>
          <property name="minChars">0</property>
          <property name="hideHelpLabel">true</property>
          <property name="directoryName">l10ncoverage</property>
          <property name="keySeparator">/</property>
          <property name="placeholder">Ville</property>
          <property name="documentSchemas">dublincore,layout_demo_schema</property>
          <property name="repository">default</property>
        </properties>
        <controls mode="any">
          <!-- enable ajax submit on change/click/select on demo application -->
          <control name="supportInsideInputWidgetEffects">true</control>
        </controls>
      </widget>

I'm not using Nuxeo Studio.

1 ACCEPTED ANSWER

Antoine_Cordier
Star Contributor
Star Contributor

Hi,

A csv file can be used as a source to define your own vocabulary

First specify the vocabulary in a file, for example "my-vocabulary.csv":

"id","label","obsolete","ordering"

"now","now","0","0"

"later","later","0","0"

"never","never","0","0"

Add this file to your project in the "resources" folder:

resources:

+-- data
    +-- schemas
    +-- my-schema.xsd
    +-- vocabularies
        +-- my-vocabulary.csv

Then use this extension point to source the csv file and update the model:

<extension target="org.nuxeo.ecm.directory.sql.SQLDirectoryFactory"
	point="directories">
	<directory name="my_business_purpose">
		<schema>vocabulary</schema>
		<dataSource>java:/nxsqldirectory</dataSource>
		<cacheTimeout>3600</cacheTimeout>
		<cacheMaxSize>1000</cacheMaxSize>
		<idField>id</idField>
		<autoincrementIdField>false</autoincrementIdField>
		<createTablePolicy>on_missing_columns</createTablePolicy>
		<table>my_business_purpose</table>
		<dataFile>data/vocabularies/my-vocabulary.csv</dataFile>
	</directory>
</extension>

View answer in original post

2 REPLIES 2

Antoine_Cordier
Star Contributor
Star Contributor

Hi,

A csv file can be used as a source to define your own vocabulary

First specify the vocabulary in a file, for example "my-vocabulary.csv":

"id","label","obsolete","ordering"

"now","now","0","0"

"later","later","0","0"

"never","never","0","0"

Add this file to your project in the "resources" folder:

resources:

+-- data
    +-- schemas
    +-- my-schema.xsd
    +-- vocabularies
        +-- my-vocabulary.csv

Then use this extension point to source the csv file and update the model:

<extension target="org.nuxeo.ecm.directory.sql.SQLDirectoryFactory"
	point="directories">
	<directory name="my_business_purpose">
		<schema>vocabulary</schema>
		<dataSource>java:/nxsqldirectory</dataSource>
		<cacheTimeout>3600</cacheTimeout>
		<cacheMaxSize>1000</cacheMaxSize>
		<idField>id</idField>
		<autoincrementIdField>false</autoincrementIdField>
		<createTablePolicy>on_missing_columns</createTablePolicy>
		<table>my_business_purpose</table>
		<dataFile>data/vocabularies/my-vocabulary.csv</dataFile>
	</directory>
</extension>

It's working, and don't forget to add the schema for the new vocabulary.