cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve values for Property from allowed values other property

Former Member
0 Kudos

Hello,

We would like to use the allowed values list of a property in a new property. We can't just make a copy, because we want to minimize the maintenance on the allowed values list.

For example we have a property called Subject with values A,B,C. We now created a new property called Subject 1 and we want to use the values from property Subject. Just copying the allowed values in the new property is not an option, nor is the checkbox multivalued.

Does anyone know how we can establish this?

Kind regards,

Joost

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Joost,

I'm afraid that is not possible with configuration, but you could develop your own property renderer which takes the allowed values from the property configuration of the first property and populates the drop-down listbox with these values. You could then set this custom property renderer for the second property. This would garantee that you have the same allowed values for both properties and that changes to the allowed values are effective immediately for both properties.

Martin

Former Member
0 Kudos

Thank you Martin,

Can you tell me where i can find more informatino about how to create your own property renderer?

Thank you in advance.

Kind regards,

Joost

Former Member
0 Kudos

Hello Joost,

unfortunately I can't find a code sample for this. There is some very simple information here: https://www.sdn.sap.com/irj/sdn/thread?threadID=183716

Basically you have to extend the class

com.sapportals.wcm.control.util.AbstractPropertyRenderer

and implement the methods

public Component renderMetaProperty(IMetaName metaName, IMetaContext rendererContext) throws WcmException

and

public IPropertyMap getProperties(IMetaName metaName, IMetaContext rendererContext, DynPage dynPage) throws WcmException

Your renderMetaProperty method needs to get the allowedValues from the PropertyConfigurationService, create a dropdown listbox component, fill it with the allowed values (id and label) and return this component.

Your getProperties method needs to get the dropdown listbox component from the given dynpage, get the selected value, and create a result property map containing the property with the selected value.

Here is some skeleton code for you to start with:


import com.sapportals.wcm.control.util.AbstractPropertyRenderer;

public class MyPropertyRenderer extends AbstractPropertyRenderer {

public Component renderMetaProperty(IMetaName metaName, IMetaContext rendererContext) throws WcmException {
		
  // differentiate the property display modes
  PropertyDisplayMode mode = rendererContext.getDisplayMode();
		
  if (PropertyDisplayMode.CREATE == mode) {
    ...
    // TODO: get the allowedValues from the other property via PropertyConfigurationService
    // TODO: get the labels for the allowedValues from the resource bundle
    // TODO: create a unique id for the dropdown listbox component
    // TODO: determine a default value and a tooltip for the list
    ...
    IProperty prop = rendererContext.getPropertyMap().get(new PropertyName(metaName.getNamespace(), metaName.getName()));
    String preselectedValue = defaultValue;
    if (prop != null) {
      // property value already exists
      preselectedValue = prop.getValueAsString();
    }
    ...
    DropdownListBox ddl = new DropdownListBox(id);
    for (int i = 0; i < allowedValues.size(); i++) {
      ddl.addItem(allowedValueId, allowedValueLabel);
    }
    ddl.setSelection(preselectedValue);
    ddl.setTooltip(tooltip);
    return ddl;
					
  } else {
    
    TextView tv = new TextView(preselectedValue);
    tv.setId(id);
    tv.setTooltip(tooltip);
    return tv;

  }
}

public IPropertyMap getProperties(IMetaName metaName, IMetaContext rendererContext, DynPage dynPage) throws WcmException {
  
  String selection = "";
  if (dynPage != null) {
    Component component = dynPage.getComponentByName(this.createComponentId(metaName.getFullId()));
    if (component != null && component instanceof DropdownListBox) {
      selection = ((DropdownListBox)component).getSelection();
    }
  }

  IProperty currentProperty = new Property(
    new PropertyName(metaName.getNamespace(), metaName.getName()), selection);
	
  IMutablePropertyMap propMap = new MutablePropertyMap();
  propMap.put(currentProperty);
  return propMap.getImmutable();
}
		
}

Please make sure to set up a portal project for KM with a RFServiceWrapper and include the co.xml configuration file for the property renderer!

This should give you a jump start!

Martin

Answers (0)