cancel
Showing results for 
Search instead for 
Did you mean: 

Format a model attribute

Former Member
0 Kudos

Hi,

I have a problem trying to format an attribute from a model. The model I use is a web service's data model. I have created a simple type "Price" based on the built-in type float (it only adds the symbol "$"). I want to assign this new type to format an attribute from my model (the attribute is a float), but when i try to change the type of the attribute in the context of my component i can't do it because the property "type" is not modifiable.

How can i achieve this?

Thanks in advance.

Pablo

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

You will have to create a value attribute called say "va_price" of type float. At runtime pick the value of model attribute price and then move it to the value attribute "va_price". I think that is the only way you can achieve what you are trying.

hope that was helpful

regards

ravi

Former Member
0 Kudos

I'm facing a similar challenge. The attribute I want to format is part of a table and this whole table is being displayed in a view... I'm afraid I have to copy the whole table to a value node with a similar structure, which is in my opinion plain ugly. Any suggestions?

Former Member
0 Kudos

You could define a calculated attribute in the view context that takes the value from the original attribute and calculates the formatted text.

If you cannot add an attribute to a node directly, add a value sub-node with cardinality 1:1, selection 1:1, and add the calculated attribute to this node.

Armin

Former Member
0 Kudos

This didn't work at first, until I read the part about singleton and non-singleton nodes. Here's the solution for a table that gets it's data from a model:

1. Create a model node with proper model binding in the controller context

2. Add a value node to the node that will supply the table with values

3. Set this node's cardinality to 1:1

4. Set this node's singleton property to false.

5. Set this node's selection to 1:1 (maybe not necessary)

6. Create an attribute inside this value node

7. Set this attribute's calculated property to true

8. Save metadata

9. Implement the generated getCalculated<attributename>() method in the controller Implementation

10. Create a model node in the view's context and perform context mapping to the controller's model node.

11. Create a table element in the layout of the view

12. Select Create Binding... from the context menu of the table element

13. Select the attributes of the standard node that you want to display

14. Create extra columns or reuse existing columns and change the text property of their _editor elements to point to the attribute of the value node you added

Answers (2)

Answers (2)

Former Member
0 Kudos

Thank you all for your answers. I've applied Armin's solution and it worked.

Pablo

Former Member
0 Kudos

Hi Pablo,

As you have mapped context attribute to the model, you can't change any propertyies of this attribute in your controller context or in view context.

Ravi's suggesion is right. There is no other method to do this.

Regards,

Bhavik