cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic value for @title annotation - is it possible?

daniellelyle
Participant

Hello SAP Community,

I'm really hoping someone here can help us out with an issue we're having. We have a CAP application with a Fiori Elements List Report/Object Page frontend interface. The question I have is about the @Common.Label or @title annotation.

Most commonly, the value here points to the i18n model; for example:

country @title: '{i18n>country}'

This updates the text shown for the "country" label everywhere it is seen:

  • The filter bar
  • The table column header
  • All p13n menus (adapt filters and table settings)

Our application requires this label to be dynamic, however. We have tried a few different approaches, but the most straightforward option appears to be using JSONModel to set the value we need.

The implementation then looks like the following.

In my labels.cds file:

country @title '{json>/country}'

In my controller extension for the List Report:

onInit: function () {
const json = new sap.ui.model.json.JSONModel({country: 'Country',});
this.base.getAppComponent().setModel(json, 'json');
},

This seems to work ONLY for the filter bar. The table column header and p13n menu entries for this property only display the path as a string; for example, '{json>/country}'. Please note I have also tried this with a JSONModel that is instantiated in the manifest.json and given static values from a json file with the same results.

I'm wondering if this has something to do with model instantiation, or is it a limitation of the @title annotation (does it only support paths to resource models)? Is there a different approach you recommend in order to make this happen with Fiori Elements? For such a small feature we would like to avoid ui5 freestyle or adding a bunch of custom fragments to the page.

I hope I've explained this well, but please let me know if any clarification is needed. We've been really scratching our heads on this one, so your help is very much appreciated. Thanks so much in advance!

former_member300741
Discoverer
0 Kudos

Hi Danielle,

Could you try adding the i18n model in the manifest instead of setting it through the onInit method?

You can check the following documentation for the same

https://sapui5.hana.ondemand.com/#/topic/b8cb649973534f08a6047692f8c6830d

Let me know if this works out for you.

Thanks & Regards,

Ishpreet

daniellelyle
Participant
0 Kudos

Hi ishpreet,

Thanks for your response. I am actually not using the i18n model here, I am attempting to use a JSONModel.

I have already tried adding the model in the manifest as I mentioned in the post, but the results are the same.

This works (i18n):

country @title: '{i18n>country}'

But this does not work (JSONModel):

country @title: '{json>/country}'

I need the second approach to work, because our application requires the labels for certain fields to be updatable by the user. As I mentioned in my post, it does seem to work in the filter bar, but table columns and p13n menus do not get updated and instead display the path as a string.

What I'm wondering is if what I'm trying to do is possible using the @title annotation or if I need to try a different approach.

Thanks,

Danielle

View Entire Topic
SugguSandeep
Active Participant
0 Kudos

Hi daniellelyle,

Check out the below video will solve your problem:

https://youtu.be/KjqenYC6itY

Thank You,
Suggu Sandeep.

daniellelyle
Participant

Hi sandeepsuggu - thanks for your response, I appreciate you reaching out. I'm not sure I'm understanding, what I need is not to change the language but to have a label that is editable by the user. I don't believe it is possible to do this using the i18n model, which is why I am trying to use a JSONModel instead.

SugguSandeep
Active Participant
0 Kudos

Hi daniellelyle,

We got a requirement while building of an SAPUI5 Application that
Translation of language should happen based on user selection from different Countries,

So i18n is the only solution we found, in that i18n file each and every language translation words also need to be attached...
As worked on 3 languages we added each language manually....

Thank You,
Suggu Sandeep.