06-16-2015 08:16 AM
How can I set a default value "0" in a text field on create mode. Here's what I've tried:
<widget name="obsolete" type="text">
<labels>
<label mode="any">Obsolete</label>
</labels>
<translated>false</translated>
<fields>
<field>bc:obsolete</field>
</fields>
<widgetModes>
<mode value="any">hidden</mode>
</widgetModes>
</widget>
07-24-2015 07:44 AM
Static default values can be declared in the schema:
<xs:element name="obsolete" type="xs:int" default="0">
If you need to setup a dynamic value, you can create a listener like this:
@Name("MyCustomListener")
public class MyCustomListener implements EventListener {
public void handleEvent(Event event) throws ClientException {
DocumentEventContext docCtx = (DocumentEventContext) ctx;
DocumentModel doc = docCtx.getSourceDocument();
if (doc != null) {
if ("myCustomType".equals(doc.getType())) {
doc.setPropertyValue("bc:obsolete", "myCustomValue");
}
[...]
}
}
}
<extension target="org.nuxeo.ecm.core.event.EventServiceComponent" point="listener">
<listener name="myCustomListener" async="false" postCommit="false"
class="org.my.custom.package.myCustomListener">
<event>emptyDocumentModelCreated</event>
</listener>
</extension>
As an alternative, you can also try using a custom widget property with name "defaultValue":
<widget name="obsolete" type="text">
<labels>
<label mode="any">Obsolete</label>
</labels>
<translated>false</translated>
<fields>
<field>bc:obsolete</field>
</fields>
<properties mode="any">
<property name="defaultValue">0</property>
</properties>
</widget>
07-24-2015 07:44 AM
Static default values can be declared in the schema:
<xs:element name="obsolete" type="xs:int" default="0">
If you need to setup a dynamic value, you can create a listener like this:
@Name("MyCustomListener")
public class MyCustomListener implements EventListener {
public void handleEvent(Event event) throws ClientException {
DocumentEventContext docCtx = (DocumentEventContext) ctx;
DocumentModel doc = docCtx.getSourceDocument();
if (doc != null) {
if ("myCustomType".equals(doc.getType())) {
doc.setPropertyValue("bc:obsolete", "myCustomValue");
}
[...]
}
}
}
<extension target="org.nuxeo.ecm.core.event.EventServiceComponent" point="listener">
<listener name="myCustomListener" async="false" postCommit="false"
class="org.my.custom.package.myCustomListener">
<event>emptyDocumentModelCreated</event>
</listener>
</extension>
As an alternative, you can also try using a custom widget property with name "defaultValue":
<widget name="obsolete" type="text">
<labels>
<label mode="any">Obsolete</label>
</labels>
<translated>false</translated>
<fields>
<field>bc:obsolete</field>
</fields>
<properties mode="any">
<property name="defaultValue">0</property>
</properties>
</widget>
07-24-2015 11:41 AM
Note that this configuration is equivalent to not having any contribution since the widget mode always resolves to "hidden".
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.