Skip to Content

Hi all,

I wrote this document due to following post http://scn.sap.com/thread/3215576.

We want to change the property of an UIElement according to the property of an element of another view. Problem is to delegate the information that the other elements property has been changed, because we have no common context attribute.

I am going to demonstrate it by adapting WDR_TEST_EVENTS. Since we are going to change a standard component (no Z-Component) we are going to use the Enhancement Framework.

Aim of demonstration:

Following picture shows WDR_TEST_EVENTS. The blue shows the main view, while the green square shows the embedded view which is being loaded when clicking the LinkToAction “Button” (red).

Now, we want to change visibility of UIElement (Tray) “Active Component” (red square in main view) according to the checkbox “Enabled” within the embedded view.

Solution:

We are going to do this by triggering an event in the component-controller out of the embedded view. The eventhandler (for this event) in the main view, which we are going to implement too, changes the visibility-property of the UIElement Active Component.

1. Enhance component-controller by event  “Edit_mode” with parameter “IS_EDITMODE”.

To do this got to Events-Tab of component controller and click the spiral. Create enhancement ZENHC_TEST.

After creating the enhancement, you are able to add the new event:

2. Enhance component-controller by method FIRE_EVENT_SET_EDIT, to be able to fire the event from the embedded view.

Go to Methods-Tab of the component-controller and add the method using the same enhancement:

Implement method FIRE_EVENT_SET_EDIT with parameter IS_EDIT. It just fires our event delegating a boolean type parameter.

3. Implement eventhandler in main view:

In the main view we need an eventhandler for event EDIT_MODE of the component-controller. Within this eventhandler we will change the property of the UIElement Active Component. But to change the property, we need a reference to our view controller. This reference we can get by enhancing the WDDOMODIFYVIEW method as a post-exit implementation.

3.1. So first we need to create an attribute where we can store the reference.

Got to attributes-tab of the main view and add reference MAIN_VIEW to the list. (mark it as RefTo and use the same enhancement)

3.2. Enhance WDDOMODIFYVIEW to get the reference.

Go to methods-tab of the main view and enhance WDDOMODIFY view by clicking the Post-Exit button.

Set the MAIN_VIEW reference in here. Do it just at first_time.

3.3. Now we can implement the eventhandler.

Go back to the method list and add eventhandler method SET_EDIT_MODE  for event EDIT_MODE of the component-controller.

Doubleclick the eventhandler and implement it as follows:

– First by using MAIN_VIEW we get the UIElement by its name. After that we have downcast this reference to an object of type cl_wd_tray. (UIElement Active Component is a Tray-UIElement). Using the set_visible method of this class we can change the visibility property of the tray active component according to the parameter IS_EDITMODE.

4. Finally we have to trigger this event out of the embedded view:

4.1. Got to view Button. We can see there that the checkbox implements event OnToggle with action ON_ENABLED_TOGGLE and furthermore that the CHECKED attribute is bound to context attribute ENABLED of the views context.

4.2. Now go to the method list of this view. And implement the Post_exit of method ONACTIONON_ENABLED_TOGGLE.

– First read value of the attribute ENABLED.

– Then call component-controller method FIRE_EVENT_SET_EDIT with this value.

We are finished. Activate and see what happens.

1. Enabled checked:

2. Enabled unchecked:

I hope this is going to help somebody.

Best regards,

ismail

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply