Let's follow up this discussion at the Neptune Community

(this forum will be kept in read-only mode)

Call methods of the Application Class?

 Hi guys, I have another question:

in the NAD, an application class can be used to bind attributes to UI5 elements, but is there also a way to call the public methods of this class directly from the application? For example I have a sap.commons button, which shall trigger a method in the application class. In the "press" event of the button I can add some javascript code, but I have no idea how to call a method from the application class from here?!


The scenario looks like this: a have a selection screen in my application and when the user presses the OK-button, I want to change the data tables in the application class accordingly.


Any help is appreciated.


Thanks!


 I think I just found the solution: in the press-event of the button, call an ajax function which you declared earlier.

There you can send a POST ajax command to the application class, where the HANDLE_ON_AJAX method is called! :)

Hi Klaus,

In SAPUI5 you can add an AJAX_ID and on a press function on a button for instance you can add a javascript like this: getOnline<name of element>();


Use the ajax id in the handle on ajax method.


I made a tutorial video where it should be explained:


http://scn.sap.com/community/mobile/blog/2013/09/09/video-tutorial-sapui5-models-and-navigation-with-neptune


BR

Njål


 Thanks Njål, that was very helpful!

But I have another question, regarding the same application:


so I managed to capture the button click and react to it in the application class, but I'm still having problems with the data transfer between the Neptune application and the application class. I have a form on my application which is similar to a selection screen and with the click of a button, the application class should select the right data.

How do I get the values from the inputfield (in my case: ValueHelpFields) to the application class? I see that I can bind a class-attribute to the "value" attribute of the ValueHelpFields, so I thought I just have to bind a public string attribute to the ValueHelpField element and the data transfers automatically between the application and the application class, but that doesn't seem to work (all attributes are greyed out). Or do I need a specific data element for this?

What DOES work is writing the values from the inputfields (getLiveValue) in the AJAX_VALUE field as a string, but I guess that's not how it's supposed to be done.


Can you please give me a hint, how can I can make the values in the inputfields available in my application class? I'm quite lost here. 


Thanks in advance!

Ok, I see that I can bind a structure to the form itself, and then single elements to the inputfields, but the data transfer does not happen automatically... do I need a POST/PUT ajax command for this to work?

 

Sorry for the late reply, been in meetings all day :-)


Press the button next to the ajax_id on the model binding. You can then select extra models to send from the client to the server.


If you bind this to a structure in the backend and bind the individual fields of the structure to input elements you can use the values in the server logic.


For reference take a look at this app which should be in your system:


NEPTUNE_FLIGHT_UI5_M


Scroll down to the serach button:





Search


Now if you look at the ListBooking list you can see that when that is loaded it is first sending the PageBook1 model which includes the values from the input field:




This is the most difficult thing to understand at the start. But once you get used to it it is really powerful. You just bind data to structures and internal tables and you can use the changed or inserted values directly from the attributes in the application class


BR

Njål



Great, now it works! You're right, the model receive and send part is a bit tricky, but once you figured it out, it makes things so much easier!
Thanks again for your great help.

 

Login or Signup to post a comment