cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any way we can call a view's controller even before the view is rendered?

chirag_maladkar
Explorer
0 Kudos

Hi,

I was trying to implement routing and noticed that the application flow is passed to view's controller only after the view is fully rendered.

What I have done is attached a handleRouteMatched to the view's controller which will be in charge of assigning value to a variable referred in the view according to the route's name.

When the URL with pattern is directly called, it obviously throws error because the variable is not assigned any value at that point in the view.

Is there any way we can have the handleRouteMatched of the controller called even before this view is rendered?

Thanks,

Chirag

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Chirag,

I hope you would have declared an ID for your view.

Consider your view id is "Home" and you want to access handleRouteMatched of the corresponding controller.

Then you can say -


sap.ui.getCore().byId("Home").getController().handleRouteMatched();

Regards,

Sai Vellanki.

chirag_maladkar
Explorer
0 Kudos

Thanks Sai,

Will try it out!

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Chirag,

handleRoutematch is a hook method for the router and will be called automatically by the framework.

any other function inside any initialized or not initialized controller can be accessed using the following code.

sap.ui.controller('controllername').functionName();

Hope this helps.

Regards,

Sachin

Former Member
0 Kudos

if i am not wrong handleRouteMatched  is called in  init method..something like this

init : function()

{

this.orouter.attachRoutePatterMatched(this.handle,this)

}

handle : function()

{

// here your logic

}

So basically in init method you can modify the view before it is displayed to bind event handlers and do other one-time initialization.

chirag_maladkar
Explorer
0 Kudos

Thanks for the reply Indrajith.

If I'm not mistaken, you're talking about onInit function in controller right?

I never tried placing handleRouteMatched in onInit. Will try it out.!

Edit:

Hi Indrajith, That was a good thought, but unfortunately it doesn't work.

Former Member
0 Kudos

How do you call your handleRouteMatched mathod ?

it gets called everytime there is a change in the pattern.

Post your code. Maybe we can understand your question better