cancel
Showing results for 
Search instead for 
Did you mean: 

Hidden default value in text field

Dalal_
Confirmed Champ
Confirmed Champ

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>
1 ACCEPTED ANSWER

JVent_
Confirmed Champ
Confirmed Champ

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>

View answer in original post

2 REPLIES 2

JVent_
Confirmed Champ
Confirmed Champ

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>

Anahide_Tchertc
Elite Collaborator
Elite Collaborator

Note that this configuration is equivalent to not having any contribution since the widget mode always resolves to "hidden".

Getting started

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.