Skip to main content
1-Visitor
September 1, 2015
Solved

I have created a ComboBox for a soft attribute of WTPart in the create new page. I have done this using data utility.It is showing me the values correctly in the UI screen of Create New WTPart. But the selected value is not getting persisted. Can som

  • September 1, 2015
  • 4 replies
  • 8533 views

public class PartComboBoxUtility extends DefaultDataUtility {
@Override
public Object getDataValue(String component_id, Object datum, ModelContext modelContext) throws WTException {

  // Initialize ComboBox UI Component
  Object object = super.getDataValue(component_id, datum, modelContext);
  System.out.println("component_id 111 4444 = = = = = = = "+component_id);
  Object raw_value = modelContext.getRawValue();
  com.ptc.core.lwc.server.PersistableAdapter  nmObject= new com.ptc.core.lwc.server.PersistableAdapter (new WTPart(), null,java.util.Locale.US, null);
  nmObject.load("Country");
  String o=TgsPropertyHelper.getPropertyValue("Country");
    String[] ab=o.split(",");

  ArrayList<String> displayList = new ArrayList<String>();
        ArrayList<String> internalList = new ArrayList<String>();
  ArrayList<String> selectedValue = new ArrayList<String>();
        internalList.addAll(Arrays.asList(ab));
        displayList.addAll(Arrays.asList(ab));
  selectedValue.add((String)raw_value);
  ComboBox comboBox = new ComboBox(internalList,displayList,selectedValue );
  if (modelContext.getDescriptorMode().equals(ComponentMode.CREATE) || modelContext.getDescriptorMode().equals(ComponentMode.EDIT))
  {
   comboBox.setName(component_id);
   comboBox.setColumnName(AttributeDataUtilityHelper.getColumnName(component_id, datum, modelContext));
   comboBox.setId(component_id);
   comboBox.setInternalValues(internalList);
   //  comboBox.setValues(displayList);
     comboBox.setEnabled(true);

   return comboBox;
  }
   return object;

}
private String getValue(String component_id, Object datum, ModelContext mc) throws WTException {

return UtilityHelper.getStringValue(component_id, datum, mc);
}

}

Best answer by krajan

Hi,

I resolved the issue. The problem was that while setting the id for combo box using the following line , I was directly using the component_id being passed as parameter to getDataValue function. Windchill was not able to recognize it while persisting the data

   comboBox.setId(component_id);


Therefore, i used the following code.  It worked fine. Thanks to all for the suggestions


if(utilityComponent instanceof AttributeInputCompositeComponent){

  AttributeInputCompositeComponent inputComponent =(AttributeInputCompositeComponent)utilityComponent;

  if (inputComponent.getValueInputComponent() instanceof StringInputComponent)

  {

  sic = (StringInputComponent) ((AttributeInputCompositeComponent) inputComponent).getValueInputComponent();

  }

  }

  // For Create Layour

  if(ComponentMode.CREATE.equals(modelContext.getComponentMode(modelContext.getDescriptor())))

  {

  comboBox.setName(sic.getName());

  comboBox.setColumnName(sic.getColumnName());

  comboBox.setId(sic.getId());

  comboBox.setInternalValues(internalValuesList);

  comboBox.setValues(displayValueList);

  comboBox.setEnabled(true);

  return comboBox;

  }


4 replies

16-Pearl
September 2, 2015

Hi Kaveri,

You can additionally create a delegate to persist the information. Add following to your existing file and create a new delegate file

comboBox.addHiddenField(CreateAndEditWizBean.FORM_PROCESSOR_DELEGATE, "ext.AttributeDelegate");

Delegate Example:

package ext;

import java.util.HashMap;

import java.util.List;

import java.util.Locale;

import com.ptc.core.lwc.server.PersistableAdapter;

import com.ptc.core.meta.common.UpdateOperationIdentifier;

import wt.fc.Persistable;

import wt.part.WTPart;

import wt.util.WTException;

import com.ptc.core.components.beans.ObjectBean;

import com.ptc.core.components.forms.DefaultObjectFormProcessorDelegate;

import com.ptc.core.components.forms.FormProcessingStatus;

import com.ptc.core.components.forms.FormResult;

import com.ptc.netmarkets.util.beans.NmCommandBean;

public class AttributeDelegate extends DefaultObjectFormProcessorDelegate

{

  @Override

  public FormResult postProcess(NmCommandBean clientData, List<ObjectBean> objectList) throws WTException

  {

  String AttributeName="MYAttributeID";

  FormResult result = new FormResult(FormProcessingStatus.SUCCESS);

  for (ObjectBean thisBean : objectList)

  {

  Persistable context = (Persistable)thisBean.getObject();

  if (context instanceof WTPart)

  {

  PersistableAdapter lwcObject = new PersistableAdapter(context, null, Locale.US, new UpdateOperationIdentifier());

  lwcObject.load(AttributeName);

  HashMap comboBoxMap =clientData.getComboBox();

  List<?> selectedComboBoxEntries = (List<?>)comboBoxMap.get(AttributeName+"!~objectHandle~partHandle~!");

  if(selectedComboBoxEntries != null && selectedComboBoxEntries.size() > 0){

  String value = (String)selectedComboBoxEntries.get(0);

  if(value != null) {

  lwcObject.set(AttributeName, value);

  lwcObject.apply();

  lwcObject.persist();

  }

  }

  }

  else

  {

  result.setStatus(FormProcessingStatus.NON_FATAL_ERROR);

  }

  }

  return result;

  }

}

Let me know if this helps in persisting the values.

Regards,

Bhushan

1-Visitor
January 5, 2018

Hello Bhushan

 

I tried this approach. I've registered the delegate in the datautility. But  for some reason, the delegate is not getting called. What actually is the following line supposed to do ::

 

preferableComboBox.addHiddenField(CreateAndEditWizBean.FORM_PROCESSOR_DELEGATE,
                    "ext.whirlpool.partgovernance.delegates.PreferableAttributeDelegate");

 

This tells the framework that this is the form processor delegate to call, correct? Is there anything I'm missing here that the delegate is not being called?

2-Explorer
September 2, 2015

You need to have a form processor delegate to process the value correctly and persist it on your object.  When you use a Data Utility on an attribute, the form variable name is not the same format as the ootb variable names, so you need to write processor code to find it and persist it on your newly created object. See the reply above for an example.

16-Pearl
September 14, 2015

Hi Kaveri,

Did the above example help to resolve your issue?

Regards,

Bhushan

krajan1-VisitorAuthorAnswer
1-Visitor
September 14, 2015

Hi,

I resolved the issue. The problem was that while setting the id for combo box using the following line , I was directly using the component_id being passed as parameter to getDataValue function. Windchill was not able to recognize it while persisting the data

   comboBox.setId(component_id);


Therefore, i used the following code.  It worked fine. Thanks to all for the suggestions


if(utilityComponent instanceof AttributeInputCompositeComponent){

  AttributeInputCompositeComponent inputComponent =(AttributeInputCompositeComponent)utilityComponent;

  if (inputComponent.getValueInputComponent() instanceof StringInputComponent)

  {

  sic = (StringInputComponent) ((AttributeInputCompositeComponent) inputComponent).getValueInputComponent();

  }

  }

  // For Create Layour

  if(ComponentMode.CREATE.equals(modelContext.getComponentMode(modelContext.getDescriptor())))

  {

  comboBox.setName(sic.getName());

  comboBox.setColumnName(sic.getColumnName());

  comboBox.setId(sic.getId());

  comboBox.setInternalValues(internalValuesList);

  comboBox.setValues(displayValueList);

  comboBox.setEnabled(true);

  return comboBox;

  }


1-Visitor
July 12, 2022

Hi krajan,

 

how did you get utilityComponent ? Can you share that?

1-Visitor
December 1, 2016

REMOVE

comboBox.setName(component_id);

  comboBox.setId(component_id);

RETAIN

comboBox.setColumnName(AttributeDataUtilityHelper.getColumnName(component_id, datum, mc));

5-Regular Member
February 14, 2018

Wonderful Solution !