cancel
Showing results for 
Search instead for 
Did you mean: 

Creating new UI5 Control with controller logic

Former Member
0 Kudos

hi

I need to create new UI5 Control that other can use via new command,my question is when I use the extend

where I should put the controller logic?

Assume that I've already control with controller logic which I want to provide out of the box when using the new control via new command....

Example will be very helpful!

~Miley

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Miley,

Check this sample: JS Bin - Collaborative JavaScript Debugging from which is an extended version of sap.m.Button. Where there is an extended property bgImg and method available for custom control as .getBgImg() by doing so you can fetch the URL of background image, also you can set a new URL using .setBgImg(). Is this what you are expecting?


Regards,

Sai Vellanki.

Former Member
0 Kudos

HI Sai,

Lets say that this control is implemented part of MVC project,and I've additional functionality

part of the controller which is related to this control where should I put it can you provide example?


Regards,

Miley

former_member182862
Active Contributor
0 Kudos

Hi Miley

can you elaborate on the additional functionality in the controller?
This functionality should not be in the Control for sure.

Thanks

-D

Former Member
0 Kudos

Hi Dennis,

Take a look at the following very simple example on check box

In the controller there is a method handleCheckBoxChange ,this is proper controller method.

Assume that I want to extend this checkBox and provide this ability  (handleCheckBoxChange) as part of my new control,How its recommended to do it ?I mean to embed this functionality in the new checkBox control which extend native checkBox

JS Bin - Collaborative JavaScript Debugging

Thank you,

Miley

former_member182862
Active Contributor
0 Kudos

something like this?

JS Bin - Collaborative JavaScript Debugging

Thanks

-D

Former Member
0 Kudos

HI Dennis,

Well, Lets say that in the same code you extend the checkBox where do you put the handleCheckBoxChange code?

Thanks

Miley

former_member182862
Active Contributor
0 Kudos

so sorry, I provide you the wrong JSBin (embarrassing)

here it is

http://jsbin.com/hizabe/edit?js,output

Former Member
0 Kudos

Hi Dennis,

I saw That you put the controller method inside the new control(cb), this is recommended approach?

Regards,

Miley

former_member182862
Active Contributor
0 Kudos

No, I do not recommend it. There are always way to do this kind of things. But I do not advocate it. For this reason, I kept asking for clarification

-D

Former Member
0 Kudos

HI Dennis,

Im a bit confused ,in your example you put the control logic which was in the controller in the controller inside on extend of the new control.this is not recommended ?

Miley

former_member182862
Active Contributor
0 Kudos

It depends on that JSON.stringify thing is a controller or a control logic. Remember control is meant to be reusable. We are good if the JSON.stringify is a control logic.

This JSON.stringify is not a really use case, hence i cannot tell

Former Member
0 Kudos

HI Dennis,

Lets say I need to create new UI5 control(via extend) from existing control which I've,and I want to encapsulate the control code to the new control,the control is using view code and controller code,In case I want to create the new control where should I put the code which was in the controller?there is  example?

I want at the end that the user will use this control via new myCB and have minimum  things to do in order to use it...How its recommended?

Thanks,

Miley

former_member182862
Active Contributor
0 Kudos

Sorry Miley

I do not have any recommendation for this.

bottomline, it is that you can put it anywhere you wish but not in the control.

Maybe other people may want to chime in.

-D

Former Member
0 Kudos

Hi Dennis,

This is my last question on this. I dont want to bother...

you said bottomline, it is that you can put it anywhere you wish but not in the control.

Can you please provide an example for this in case you have this dependency and how you consume this control?


Many Thanks!

Miley

former_member182862
Active Contributor
0 Kudos

Hi Miley

Back to your original JSBin, you can create a common util class

JS Bin - Collaborative JavaScript Debugging

Former Member
0 Kudos

Thanks again

But how you combine it with the new extend control?

Miley

former_member182862
Active Contributor
0 Kudos

and you have mentioned "last question" 🙂

You should not combine with new control. As I said. "nothing to do with control". It is a helper function for your controller.

Please stop. this thread is going too long

Answers (1)

Answers (1)

karthikarjun
Active Contributor
0 Kudos

Hi Miley,

Check with dennis content. He is the master of extending new controls in SAPUI5.

Thanks,

Karthik A

Former Member
0 Kudos

HI Karthik,

Can you refer me to specific implantation which can assist?

Regards,

Miley