cancel
Showing results for 
Search instead for 
Did you mean: 

How to access attribute inside a method

Former Member
0 Kudos

Hi,

I have defined an attribute under Attribute tab of Component controller. How to access this inside WDDOINIT of component controller or inside any custom method of any of my view.

Rgds

Sudhanshu

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

For Comp controller:

WD_THIS->ATTR

For View:

WD_COMP_CONTROLLER->ATTR

Answers (1)

Answers (1)

bjorn-henrik_zink
Active Participant
0 Kudos

Hi sudhanshu sharma,

please search the forum before posting your question, I believe there are many answers to your question out there.

Anyway, here you have an example of how to access a context attribute from within your component controller:

wd_this->attribute_name.

Hope it helps

Former Member
0 Kudos

For accessing the attribute from view also check that the attribute visibility is marked as PUBLIC

bjorn-henrik_zink
Active Participant
0 Kudos

From a design point of view I would adwise not to directly access the component controller attributes. Instead, use set and get methods for accessing the attributes.

Former Member
0 Kudos

Hi,

Can you please let me know pros and cons of direct accessing of component controller attribute.

Rgds

Sudhanshu

Former Member
0 Kudos

Hi Sudhanshu,

You can directly access the context attribute by set and get methods.

bjorn-henrik_zink
Active Participant
0 Kudos

Hi,

I was thinking about the advantages of encapsulation. In my last post, I forgot to mention that this applies for the scenario where you get the attribute value from your view.

It seems that you have some data in your component controller which you want to access in the view. Perhaps you should consider using context binding instead of attributes?

/Björn-Henrik

Former Member
0 Kudos

Hi,

You made a good point however my requirement doesn't make any impact on design. All i wanted was a boolean flag to check whether my itab is initial or not and then need to perform some action in diffrent methods of same view. Im currently using component attribute and it is fine for me now. Thank you so much Sanket, Elvez and all bloggers.

Rgds

Sudhanshu

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>It seems that you have some data in your component controller which you want to access in the view. Perhaps you should consider using context binding instead of attributes?

Why suggest that you should use the context instead? The context should only be used if you need to data bind into the UI elements. Otherwise it is advisable from a performance standpoint to not use the context. The context comes with a considerable memory and processing overhead. Never use the context unless absolutely necessary for data binding. Otherwise use attributes of the controllers themselves or use some external class (like the assistance class) to hold such data.

bjorn-henrik_zink
Active Participant
0 Kudos

Hi Thomas,

I fully agree with you. In my previous post I did not recommend using a context attribute for all cases (I did use the word "perhaps"). However, if it is bound to a UI element and used acrossed various views, I would probably go for a context attribute. This is not the case in this thread and therefore a context attribute should not be used.

/Björn-Henrik