It's all about the answers!

Ask a question

Set Value on Custom Attribute


derry davis (23221916) | asked Aug 24 '09, 10:01 p.m.
Hi All,
We've created a custom presentation for a custom workflow by following the tutorial provided on the wiki (https://jazz.net/wiki/bin/view/Main/RtcSdk20). The presentation displays a custom list box control (aka drop-down) with custom values instead of a button. The problem we are having is the form is not being flagged dirty when the control value is changed. The code where we set the value doesn't seem to quite be working. Here's the line:
fWorkingCopy.getWorkItem().setValue(getAttribute(),txtExposure.isEnabled())
I'm not quite sure how to get this to work for types other than boolean. Any suggestions?
Thanks in advance,
-Derry

7 answers



permanent link
Patrick Streule (4.9k21) | answered Aug 28 '09, 3:16 p.m.
JAZZ DEVELOPER
I have added an additonal example on how to create an attribute
presentation to the Wiki:
https://jazz.net/wiki/bin/view/Main/CalculatedAttributePresentation

--
Regards,
Patrick
Jazz Work Item Team

permanent link
derry davis (23221916) | answered Aug 26 '09, 4:06 p.m.
Thanks Patrick. That's exactly what I needed. I've got things working now.

permanent link
Patrick Streule (4.9k21) | answered Aug 26 '09, 10:47 a.m.
JAZZ DEVELOPER
So I've begun implementing something like option 2. I've created a
hidden field on the form and use it as my data store for the
component. When a value changes on one of the controls it loops
through the custom attributes and updates the value on the desired
attribute.

The usual approach would be
- define a custom attribute for the desired work item type
- bind your presentation to it in the Editor Presentation configuration

The presentation would then read and write this attribute (which
automatically dirties the editor).

To get the IAttribute, you can do something like this:

WorkItemUIWorkingCopy uiWorkingCopy= (WorkItemUIWorkingCopy)
workingCopy.getAdapter(IWorkItemUIWorkingCopy.class);
IAttribute attribute=
uiWorkingCopy.getResolvedWorkItem().findAttribute(fAttribute.getIdentifier());

Now the interesting part is that it doesn't have any problems when I
create the initial form. But when I open the form a 2nd item I begin to get Class Cast Exceptions and an error message of
"com.ibm.team.workitem.common.internal.model.impl.AttributeHandleImpl
incompatible with com.ibm.team.workitem.common.model.IAttribute"
when looping over the workitem object custom attributes. Any
suggestions?

If you use workitem.getCustomAttributes(), you can only assume that you
get handles back. To get the resolved attributes, you would use the
resolved work item, as in the code snippet above.

If you are already doing this, you may see
https://jazz.net/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/89167,
which was recently fixed.

--
Regards,
Patrick
Jazz Work Item Team

permanent link
derry davis (23221916) | answered Aug 26 '09, 12:12 a.m.
Ok I see that the initialization of the form actually provides proxies to the custom attributes instead of the attribute handle. This is causing the behavior I'm seeing. How can I use the attribute handle object to read / write to a custom attribute?

permanent link
derry davis (23221916) | answered Aug 25 '09, 11:45 p.m.
So I've begun implementing something like option 2. I've created a hidden field on the form and use it as my data store for the component. When a value changes on one of the controls it loops through the custom attributes and updates the value on the desired attribute.
Now the interesting part is that it doesn't have any problems when I create the initial form. But when I open the form a 2nd item I begin to get Class Cast Exceptions and an error message of "com.ibm.team.workitem.common.internal.model.impl.AttributeHandleImpl incompatible with com.ibm.team.workitem.common.model.IAttribute"
when looping over the workitem object custom attributes. Any suggestions?

permanent link
derry davis (23221916) | answered Aug 25 '09, 4:35 p.m.
So our custom presentation actually behaves more like a component than a single attribute. It is built to display 3 separate controls, 2 combo boxes and a text box. What we're struggling with is to have the controls updates programmatically and flag the form dirty. We can get the controls to update but the form doesn't get dirty and the values are not saved.
So do we 1.) 'addCustomAttribute' to the form and read data to and from these attribute?
2.) have hidden attributes on the form that we read and write to/from?
I think it's the 2 item. Other thoughts? Thanks in advance.

permanent link
Patrick Streule (4.9k21) | answered Aug 25 '09, 3:28 a.m.
JAZZ DEVELOPER
we set the value doesn't seem to quite be working. Here's the line:
fWorkingCopy.getWorkItem().setValue(getAttribute(),txtExposure.isEnabled())
I'm not quite sure how to get this to work for types other than
boolean. Any suggestions?

Setting the value works analogously for types other than boolean. E.g. for
a string based attribute type:

fWorkingCopy.getWorkItem().setValue(getAttribute(), myStringValue)

This should automatically dirty the editor.

--
Regards,
Patrick
Jazz Work Item Team

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.