cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

how to display custom user picker value

CZ_9645217
15-Moonstone

how to display custom user picker value

Dears,

I wrote a customized User Picker according to the Demo, it is working fine under the Creat and Edit modes, but it can't show the selected property value, I think I should need to write some code under the getDataValue method for the ComponentMode.VIEW, how can I make writing this part of the code to be able to display it on the VIEW under getDataValue method. Thank you.

 

 

	@Override
	public Object getDataValue(String component_id, Object object, ModelContext mc) throws WTException {
		String attributeId = component_id;
		Object obj = null;
		GUIComponentArray guiArray = new GUIComponentArray();
		if (ComponentMode.CREATE.equals(mode) || ComponentMode.EDIT.equals(mode)) {
			obj = super.getDataValue(attributeId, object, mc);
			if (obj instanceof PickerInputComponent) {
				PickerInputComponent pickerComponent = (PickerInputComponent) obj;
				guiArray.addGUIComponent(pickerComponent);
			}
		} else if (ComponentMode.VIEW.equals(mode)) {
//TODO
		}

		return obj;

	}

 

 

 

ACCEPTED SOLUTION

Accepted Solutions

Hi @CZ_9645217 

You can use Lable (com.ptc.core.components.rendering.guicomponents.Lable)

 

Label nameComponent = new Label("");
nameComponent.setColumnName(AttributeDataUtilityHelper.getColumnName(component_id, obj, modelContext));
nameComponent.setId(component_id);
nameComponent.setValue(pickerComponent.getValue());

 PetrH

View solution in original post

8 REPLIES 8

Hi @CZ_9645217 

You can use Lable (com.ptc.core.components.rendering.guicomponents.Lable)

 

Label nameComponent = new Label("");
nameComponent.setColumnName(AttributeDataUtilityHelper.getColumnName(component_id, obj, modelContext));
nameComponent.setId(component_id);
nameComponent.setValue(pickerComponent.getValue());

 PetrH

Hi @HelesicPetr 

Thank you very much for your prompt reply, it solved my problem!

 

 

Hi @CZ_9645217,

 

Could you share your getDataValue method after you were able to get working?   I have spent a couple of days trying to get this to work but I have been unsuccessful.  Thank you.

 

 

HelesicPetr
22-Sapphire I
(To:tspain)

Hi @tspain 

What is your issue? 

Can you get the right value from your attribute? 

 

here is the easiest example:

public Object getDataValue(String component_id, Object object, ModelContext modelContext) throws WTException
{
Label nameComponent = new Label("My attribute Value");
nameComponent.setColumnName(AttributeDataUtilityHelper.getColumnName(component_id, obj, modelContext));
nameComponent.setId(component_id);
nameComponent.setValue("My attribute Value");
return nameComponent;
}

PetrH 

Hi @HelesicPetr,

 

Thanks for responding.   My attribute for UID was showing blank on the info page.   I tried your code example and now I am getting UID for the value instead of the actual value. 

 

I noticed in your code that you reference obj instead of object.  How is obj instantiated for ComponentMode.VIEW.  I just used object for my test.

 

2024-03-06 08_04_28-Jump List for Google Chrome.jpg

HelesicPetr
22-Sapphire I
(To:tspain)

Hi @tspain 

obj = object 

You need to read the attribute value from the object. So you need to write code that retrieves the value of the attribute. 

PetrH

 

Hi @HelesicPetr,

 
Thanks again for your help.  I am now able to see the attribute value on the info page.  Below is my code in case it may help someone else.   Also reference CS347200.
 
 
else if (ComponentMode.VIEW.equals(mode))
{
Object value = mc.getRawValue();
Label nameComponent = new Label("UID");
nameComponent.setColumnName(AttributeDataUtilityHelper.getColumnName(component_id, object, mc));
nameComponent.setId(component_id);
nameComponent.setValue(value.toString());
return nameComponent;
}
HelesicPetr
22-Sapphire I
(To:tspain)

Hi @tspain 

Does your value has a string value? if not then the getRawValue does not work as you expect 

 

use 

Object value = mc.getRawValue();
Label nameComponent = new Label(value );
 
PetrH
Announcements

Top Tags