Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
I tried doing it by using data utility but i am getting runtime exception "callback function is either not defined or there is error in it.unable to set null reference"
I used a data utility to add a user picker to my builder. I had to create a HashMap to contain all of the component properties that would otherwise be in the JCA tags.
HashMap<String,String> map = new HashMap<String,String>();
map.put("pickerId", "userPickerId");
map.put("hiddenId", "userId");
map.put("componentId", "userCompPickerId");
map.put("objectType", "wt.org.WTUser");
map.put("pickedAttributes", "fullName,name");
map.put("defaultValue", displayValue);
map.put("defaultHiddenValue", keyValue);
map.put("readOnlyPickerTextBox", "true");
map.put("pickerCallback", "userPickerCallBack");
map.put("showRoles", "false");
map.put("showSuggestion", "false");
map.put("suggestServiceKey", "userPicker");
map.put("multiSelect", "false");
PickerInputComponent pic = new PickerInputComponent("My User",displayValue, map);
pic.setColumnName(component_id);
pic.setRequired(AttributeDataUtilityHelper.isInputRequired(mc));
return pic;
We have a custom callback and such, but this works.
package com.axtel;
import java.util.HashMap;
import java.util.List;
import wt.inf.container.WTContainerRef;
import wt.util.WTException;
import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.dataUtilities.AttributeDataUtilityHelper;
import com.ptc.core.components.factory.dataUtilities.DefaultPickerDataUtility;
import com.ptc.core.components.factory.dataUtilities.PrincipalDataUtility;
import com.ptc.core.components.rendering.guicomponents.PickerInputComponent;
import com.ptc.windchill.enterprise.change2.dataUtilities.ChangePickerDataUtility;
public class Picker extends DefaultPickerDataUtility {
WTContainerRef containerRef = null;
ChangePickerDataUtility picker;
PrincipalDataUtility pdu;
HashMap<String, String> defaultProps = new HashMap<String, String>();
@Override
public void setModelData(String component_id, List<?> objects, ModelContext mc)throws WTException {
System.out.println("------component id----"+component_id);
System.out.println("-----model context----"+mc.toString());
super.setModelData(component_id, objects, mc);
buildUserPickerConfig(component_id, mc);
}
public void buildUserPickerConfig(final String component_id, final ModelContext mc) throws WTException {
// HashMap<String, Object> defaultProps = new HashMap<String, Object>();
defaultProps.put("pickerId", "testUserPicker");
defaultProps.put("hiddenId", "userId");
defaultProps.put("componentId", "userCompPickerId");
defaultProps.put("objectType", "wt.org.WTUser");
defaultProps.put("pickedAttributes", "fullName,name");
// defaultProps.put("defaultValue", displayValue);
// defaultProps.put("defaultHiddenValue", keyValue);
defaultProps.put("readOnlyPickerTextBox", "true");
defaultProps.put("pickerCallback", "userPickerCallBack");
defaultProps.put("showRoles", "false");
defaultProps.put("showSuggestion", "false");
defaultProps.put("suggestServiceKey", "userPicker");
defaultProps.put("multiSelect", "false");
mc.getDescriptor().setProperties(defaultProps);
}
@Override
public Object getDataValue(String component_id, Object object, ModelContext mc) throws WTException {
Object localObject = null;
if (mc.getRawValue() != null)
{
localObject = mc.getRawValue();
} else
{
localObject = "";
}
PickerInputComponent pic = new PickerInputComponent("My User",localObject.toString(), defaultProps);
pic.setColumnName(component_id);
pic.setRequired(AttributeDataUtilityHelper.isInputRequired(mc));
return pic;
}
}
Above data utility code I have written for user picker but when I seaech for user and click ok,I get exception as shown below.It means that I need to write a call back function.
I created a callback function in a .js file that is included in the .jsp for the action.
function userPickerCallback(objects, pickerID, attr, displayFieldId) {
var pickedObjs = objects.pickedObject;
if (pickedObjs != null) {
var updateHiddenField = document.getElementsByName(pickerID)[0];
var updateDisplayField;
var fields = document.getElementsByTagName("input");
for (p=0;p<fields.length; p++) {
var currInput = fields[p];
if (currInput.name.indexOf("userPickerId")>-1
&& currInput.name.indexOf("textbox___old")<0) {
updateDisplayField = currInput;
}
}
for (var i = 0; i < pickedObjs.length; i++) {
if (pickedObjs[i] != null) {
var userOid = pickedObjs[i].oid;
var displayAttr = eval("pickedObjs[i].fullName");
updateHiddenField.value=userOid;
updateDisplayField.value=displayAttr;
}
}
}
}
I wrote the above mention callback function in custom.js and validate.js file but still it is throwing the same error.