Skip to Content
Technical Articles
Author's profile photo Shreshtt Bhatt

SAP Commerce | Enable Default Value of Boolean Field in SmartEdit


Generic Editor  allow us to edit components in the SmartEdit interface. OOTB SmartEdit doesn’t support defaultValue to be display while creating new component.

But OOTB BooleanComponent (AngularJS) has the capability of handling Default Value and expect the below JSON response from CMS Structure API

    cmsStructureType: "Boolean",
    qualifier: "someQualifier",
    i18nKey: 'i18nkeyForSomeQualifier',
    localized: false,
    defaultValue: true

Here we can see that this BooleanComponent accept defaultValue as well and can show toggle button ON/OFF accordingly.

This blog will be based on SAP Commerce 1811.


Some CMS Components have default value true/false (defined in items.xml) for their Boolean type fields but whenever we create these CMS Component in SmartEdit, we can not see toggle button ON/OFF as per their defaultValue.

For Example, All CMS Component has visible boolean field and by default its True, but we can’t see visible toggle ON by default in SmartEdit whenever we create any component.

Although BooleanComponent support defaultValue but OOTB CMS Structure API doesn’t have defaultValue field defined.

We can modify its metadata by extending ComponentTypeAttributeData DTO with defaultValue.



The customization can be done in any extension but i would recommend to create one custom SmartEdit extension and put all kind of SmartEdit customization inside that extension only.

  • Lets first create one custom SmartEdit extension. Please follow these links to setup & create one custom extension e.g. trainingsmartedit.

  • Extend CMS Structure API. Open trainingsmartedit-beans.xml and extend ComponentTypeAttributeData with defaultValue
	<bean class="">
	    <property name="defaultValue" type="Boolean" />
  • Since we added defaultValue only for Boolean type, we need to define one predicate which will allow to populate its value only for Boolean type fields.
  • Create BooleanDefaultValueStructureTypeAttributePredicate in trainingsmartedit -> src folder under relevant package. This will make sure when attribute has default value and its of Boolean type, then only populate defaultValue in Structure API.
public class BooleanDefaultValueStructureTypeAttributePredicate implements Predicate<AttributeDescriptorModel>
	public boolean test(final AttributeDescriptorModel attributeDescriptor)
		return attributeDescriptor.getDefaultValue() != null && attributeDescriptor.getDefaultValue() instanceof Boolean;
  • Create Populator BooleanDefaultValueComponentTypeAttributePopulator to populate defaultValue in ComponentTypeAttributeData
public class BooleanDefaultValueComponentTypeAttributePopulator implements Populator<AttributeDescriptorModel, ComponentTypeAttributeData>
	public void populate(final AttributeDescriptorModel source, final ComponentTypeAttributeData target) throws ConversionException
		if (source.getDefaultValue() instanceof Boolean)
			target.setDefaultValue((Boolean) source.getDefaultValue());
  • Add this populator to cmsAttributePredicatePopulatorListMap. Open trainingsmartedit-sprint.xml and add the below bean definition
	<bean id="booleanDefaultValueComponentTypeAttributePopulator" class="com.hybris.types.populator.BooleanDefaultValueComponentTypeAttributePopulator" />

	<bean depends-on="cmsAttributePredicatePopulatorListMap" parent="mapMergeDirective">
	   <property name="key">
		  <bean class="com.hybris.service.predicate.BooleanDefaultValueStructureTypeAttributePredicate"/>
	   <property name="value">
			<ref bean="booleanDefaultValueComponentTypeAttributePopulator" />
  • Finally, We need to extend ComponentTypeAttributeData from OCC Side as well. We can add this to trainingsmartedit-beans.xml if we don’t have custom occ extension.
	<bean class="">
		    <hint name="wsRelated"/>
		<property name="defaultValue" type="Boolean" />
  • OCC Field level Mapping already defined OOTB in cmswebservices/web/webroot/WEB-INF/config/dto-mapping-spring.xml
	<bean parent="fieldSetLevelMapping">
		<property name="dtoClass"
				  value="" />
		<property name="levelMapping">
				<entry key="BASIC"
					   value="code,i18nKey,name,attributes" />
				<entry key="DEFAULT"
					   value="code,i18nKey,name,attributes" />
				<entry key="FULL"
					   value="code,i18nKey,name,attributes" />


Build Step

Do ant all and server start. Once Server Started, We can check in SmartEdit by adding any CMS Component, defaultValue should be populated for boolean type fields in CMS Structure API, rest BooleanComponent will do their job.

         "cmsStructureType" : "Boolean",
         "collection" : false,
         "defaultValue" : true,
         "editable" : true,
         "i18nKey" : "",
         "localized" : false,
         "paged" : false,
         "qualifier" : "visible",
         "required" : false


Thats how we can work for other type fields as well but for other types, we need to extend its angular component with default value capability.


Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.