cancel
Showing results for 
Search instead for 
Did you mean: 

View should call another view's function to create an if-else statement but doesnt work..

Former Member
0 Kudos

Hello,

As I 'm developing my app, I have a page which is included 3 buttons. I created a view has included 1 table which is following on second button but right now, I need when I press the third button view should come but one of the view's table's column shouldn't appear which should come unvisible.

In my opinion, Exactly I should create if-else statement on this view. But how can I create an if else statement referred another view's buttons. ?


button:function(){

     

  app.to("page5");    

     

  }

This is a part of button's view.controller.

Can you help me how can I call from another view this function and do if else statement for I need ?

Thanks,

Ogulcan G.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

If you still want to use an if else you could try one of the following options:

Option 1: Use browser storage. Of button is pressed then store value. In the other view's controller you just get the item again with the specified key.

     jQuery.sap.require("jquery.sap.storage");

     //set data

     this.storage.put("key", "show"));

     //get data

     this.storage = window.localStorage ? jQuery.sap.storage(jQuery.sap.storage.Type.local) : jQuery.sap.storage(jQuery.sap.storage.Type.session);

     var data = this.storage.get("key");

Option 2: Using events. Go ahead and have a look at eventBusses (sap.ui.core.EventBus) for communication between views.

saivellanki
Active Contributor
0 Kudos

Hi Ogulcan,

You wanted to call another view's function? If you have the button view id available with you, then try


var oView = sap.ui.getCore().byId("oButtonView");          //Your View ID where the button is placed.

oView.buttonFunction();               //Your Button function

Regards,

Sai Vellanki.

Former Member
0 Kudos

According to your recommend I can fix my problem I will try it when I develop again.

And Sai please can you check my this problem also:

?

Because this situation is much big a problem for me.

Thank you for your answer,

Ogulcan G.

former_member182372
Active Contributor
0 Kudos

i would recommend to use eventing for inter views communication

Former Member
0 Kudos

Hi again,

No couldn't find any solution for me. I tried with your code Sai, but doesnt effect it. And it should have a problem on calling the function I think. If I defined global variable, would it be best solution ? How can I define global variable for it do u have any recommend it?

Thanks,

Ogulcan G.

former_member182372
Active Contributor
0 Kudos

eventing allows you to attach data to event (3rd parameter in publish method)

saivellanki
Active Contributor
0 Kudos

Hi Ogulcan,

Will this help? Plunker


If you click on First Button, you will get an alert to select Second/Third Button.

If you click on Second Button,it will navigate to second page which consists of three columns in table (With Availability column Visible).

If you click on Third Button, it will navigate to second page which consists of two columns in table (With Availability column Invisible).

I have written comments to the code, hope you will get clear with it. If not, please let me know your questions. Also, If this is not what you're expecting then elaborate your requirement.


Regards,

Sai Vellanki.

Former Member
0 Kudos

Thanks Sai it worked for me! But right now I couldn't manage that problem also.

I have this page :

and when I press these buttons Bar's label come like this:

But I want that label should change according to what button that I press.

My example code of button's view:

     var omButton4 = new sap.m.Button({

         text: "3. Departmandan gelen iade-902",

         press: function(){

           sap.ui.getCore().byId("Label01").mProperties.text = "902";

       

           app.to("page7");

         }

  });

  var omButton6 = new sap.m.Button({

         text: "5. Departmandan gelen iade-905",

         press: function(){

           sap.ui.getCore().byId("Label01").mProperties.text = "905";

           app.to("page7");

         }

  });

It changes just once! Just one time it changes but not everytime.

Can you help me for this please?

Regards,

Ogulcan G.

saivellanki
Active Contributor
0 Kudos

Hi Ogulcan,

Bind model property to your page title. Plunk Edited: Plunker

Click on Second Button, it will navigate to second page showing title as 'Second Button'. Click on Third Button it will show as 'Third Button'. So, depending on the button selection made the selected button title appears in the second view.

You can check the changes made to get this at -

FirstPage.controller.js: Line #7 where I am setting a model property '/oTitle' with selected button text.

SecondPage.view.js: Line#8 where I have have bound the title property with '/oTitle' property that I have set in the firstpage controller.

Regards,

Sai Vellanki.

Former Member
0 Kudos

Hello Sai,

Thanks it works! But when its works, my table has no data also. I think there is a problem on my modelling. Table model hasnt seen by app I think.

When i write this code also for set my model, title doesnt change.

       

sap.ui.getCore().byId("page7").setModel(sap.ui.getCore().getModel());

Could you pls send a message and you can show me if there is a problem on my models by teamviewer if its possible?

Thanks,

Ogulcan G.

saivellanki
Active Contributor
0 Kudos

Hi Ogulcan,

Don't overwrite the whole model, If you see the sample that I had provided earlier, I was just overwriting a property that is set it to the model, which is bound to my page title.

If possible, can you create a plunk of your code here? Plunker


P.S - Make sure you don't just copy and paste the full code as it might be having some confidential information, just create a look-alike sample code on what you have been trying.


Thank you!


Regards,

Sai Vellanki.



Former Member
0 Kudos

Hi Sai,

I add all of my project because there are some problems with model. My just problem is right now only modelling. I couldnt understand I think , thats why could you check my code also:

http://plnkr.co/edit/USFhNQ16NBk696Dji4ca

On "mddepgeliade.view.js" line 993 I have a comment pls check.

If you have so many comments about my project just write me pls:

ogulcangogceloglu@gmail.com

If I solve this problem "modelling" I will finish my project pls just help me for this solution.

Thanks for everything expert,

Ogulcan G.

saivellanki
Active Contributor
0 Kudos

Hi Ogulcan,

That's pretty huge application!

I have made few changes to the code, now both page title and table model are working fine. Check the sample here: Plunker

I have done changes in promdepo.view.js file and mddepgeliade.view.js.

In promdepo.view.js, on press event of 201 and 202 buttons, I am setting the title property - Line #35 and #48

In mddepgeliade.view.js, I have used a named model in order to get rid of confusion. Line#984 and Line#985

I also commented Line#993 code, that is not required now.

Regards,

Sai Vellanki.

Former Member
0 Kudos

Hi Sai,

Thank you for your supporting. That was really great changes. As you said thats really big application and this is my first experience with SAPUI5 thats why have so many problems. I hope it will finish as soon

So, right now I did some changes (connect with ABAP rep.) and again page's title didn't appear too. My changes on the mdetiketbasma.view and mddepgeliade.view also.

And when I open my Combobox code my table which has values from SAP are gone. Thats why I cant use my combobox too (Logon.view)

http://plnkr.co/edit/USFhNQ16NBk696Dji4ca?p=info

These are my last problems. You 're really great supporter and if you support one more time I will really appricate for it.

THANK YOU FRIEND SAI,

Ogulcan G.