cancel
Showing results for 
Search instead for 
Did you mean: 

Current Date in XML View

0 Kudos

Hi Experts.

I was developing my first view in UI5 a while ago and I did it using JavaScript.

As soon as I was enjoying it I started to look for best practices and patterns and started to develop in XML.

My first view had two fields that were populated by two oDatas, one with months and the other with years and in Javascript I was able to filter it using some functions and populate the two field with the current month and year.


I want to know how to do it in XML.

Thanks,

Accepted Solutions (1)

Accepted Solutions (1)

sebastianraemsch
Active Participant
0 Kudos

Hi,

I also don´t know a way to directly do this in the XML view. I think this it is not possible.

However you can set a model in the controller:


var oModel = new sap.ui.model.json.JSONModel({currentMonth : new Date().getMonth()});

this.getView().setModel(oModel);

and then bind a field in the view to that model:


<Text text="{/currentMonth}"/>

The same you can do for the current year.

This worked for me.

Best regards,

Sebastian

0 Kudos

Hi Sebastian. Thanks for your answer it helped me a lot but unfortunately I still have issues.

I can display in my dropdownbox the current month and year but I want to display all the others years and months too.

I have an OData with them so basically I want to display at first the current date but should be able to change it.

Thanks a lot.

junwu
Active Contributor
0 Kudos

don't know how to use dropdown in xml view?

0 Kudos

I know, my problem is to call an OData with a list of values and show all of them but the first one is the current month or year

junwu
Active Contributor
0 Kudos

i don't see the problem, call the odata in your controller, model binding is done in the xml view.

where you stuck?

0 Kudos

I cant make my view to read my OData on the controller and display it.
It just shows me the current value.

junwu
Active Contributor
0 Kudos

man, code please.

if you load the data in controller, why you view cannot get it?

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

do the same in your controller

it is not in the xml.