cancel
Showing results for 
Search instead for 
Did you mean: 

Call a componetnt from a view in an eventhandler of the view

Former Member
0 Kudos

Hello,

im new in WebDynpro and i have a (simple) question. Is it possible to call a property of an component in the code of an eventhandler?

I have a View with a button and a TextBox (input box) and a label. In the eventhandler of the Button _ Click i want to read the TextBox value and put it into the label. (I know the Context. But thats not the way I want to use / try)

An other question is: How I can set components visible/ or not visible? (in the eventhandler of my action button)

THX at all

regards Michael

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Micheal,

As per my understanding UI element Property can be accessed in doModifyView Method of the View as it has a IWDView view as an input parameter through which we can retrieve any UI element and Then set or get its properties.

You can do one thing that you can declare a variable of IWDView or a particular UI element and Initialize the same in the doModifyView method as it is a hook method it will be called automatically at start of the Initialization of the view. You can also the use the firstTime input parameter in the method to initialize it only once. After that the same variable can be used in any method or the event handler. Here is a same Code.

Globally declared variable

 
private IWDLabel label1;

In doModify Method


if(firstTime)
{
   label1= (IWDLabel) view.getElement("FieldName");
}

In the Event Handler:


label1.setText(wdContext.currentContext.getInputFieldContextAttribute);

Hope this works. If any query revert back.

Regards,

Ardhendu

Former Member
0 Kudos

Hy,

That was something I thought.

I was thinking of the paralle. NET programming. In the code behind directly access the UI and edit the event handlers. Maybe I just do not see the parallel.

I will try your way. How would you show or hide an view?

I have a ViewSet T - Layout. left a view, right a view and in the top a view with 2 buttons. "search" and "admin" If I want "search" click open the left view and when I click "admin" only the right view should be visible.

regards

Micha.

Former Member
0 Kudos

Yes, you can do anything what the compiler allows and ignore the Web Dynpro programming model altogether. Who needs data binding and all this nonsense?

Armin

Former Member
0 Kudos

It was a simple question. I want to understand the Webdynpro programming.

so the way is: Always work with the conext and the mapping / binding?

Edited by: Michael Rudolph on Nov 3, 2009 11:43 AM

Former Member
0 Kudos

Use view navigation. From the different action handlers call the corresponding outbound-plug methods (firePlugXXX).

Armin

Former Member
0 Kudos

Yes, always when appropriate. Accessing the view elements should not be done just for getting or setting their property values.

Armin

Former Member
0 Kudos

THX,

just for getting or setting their property values

--> this is something i want to do fpr example set enable or disable.

But i can create a new Context valuennode "visiblityOfButton" with the corresponding UI Visiblity type an map the visiblity to the context.. is this the right way?

Former Member
0 Kudos

Yes, that works for all bindable properties the same way.

Please note that view element properties can only be bound to context attributes that have a dictionary type (binding to Java native types is not possible, at least not in earlier releases, and in newer ones only with restrictions).

That means to bind the "visible" property, you first need to define a context attribute of dictionary type "Visibility" (Dictionaries -> Local Dictionary -> com.sap.ide.webdynpro.uielementdefinitions.Visibilty). Then you can bind the "visible" property of one or many view elements to that context attribute.

To set these view elements to visible, you then set the context attribute value to WDVisibility.VISIBLE, to hide it use WDVisibility.NONE.

Armin

Former Member
0 Kudos

Wow thanx.. i will try it. Thx for the explanation.

Is this also the way to make single vies of a viewset visible by button click?

Former Member
0 Kudos

The normal way of making views visible or invisible is to define a suitable navigation structure between the views (using the Window modeler) and navigating along the defined navigation links.

Viewsets have certain drawbacks regarding layout flexibility, personally I don't use them. A more flexible way is to use plain views with ViewContainerUIElement instances. In that case you can also use the visibility of the ViewContainerUIElement to show/hide the contained view.

Armin

Former Member
0 Kudos

Cool... this is an very helpful tip. thx... sry for these simple questions but i will learn webdynpro for java. I only programming .NET / C# before and now I'm only a portal admin. But i want back to development. So 2 SAP boks are on my desk and the JA300. But still tehre are so many questions

Former Member
0 Kudos

You are welcome.

Armin

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello Armin,

I totally agree with you. I just forgot that it was a static method. Thanks again for giving a clear explanation about it.

Regards,

Ardhendu

Former Member
0 Kudos

Hello Micheal,

First of all sorry I gave you the previous solution as I is not correct as per the Web Dynpro Programming Model.

You had said that you wanted solution other than Context so I just thought of it.

As a best practice you should always bind a property value of a UI element to a Context Attribute of the required type and then change its value using that attibute. You can Attibute value to WdVisibility type and bind the same to property value for your visibility problem.

Regards,

Ardhendu

Former Member
0 Kudos

Sorry for my somewhat rude answer, but apart from violating the Web Dynpro programming model, your solution with storing view elements in view controller references will not work because wdDoModifyView() is a static method (and that was exactly the reason to make it static as its Javadoc clearly expresses) and second, if one would use a static controller reference that would make be even worse as has been explained in this forum several times.

Armin