Showing results for 
Search instead for 
Did you mean: 

Set Focus in a dynamic component's view element

Former Member
0 Kudos

Hi All.

I am embedding components dynamically inside my main application.

Then from my main application, i call the interface method check_data(). This interface is implemented by all components and hence, they all have this method.

Now, if there is an error, I am able to correctly show it inside my main application.

But i show it using REPORT_ERROR_MESSAGE instead of REPORT_ATTRIBUTE_ERROR_MESSAGE simply because the attribute is in the view which is embedded dynamically and hence it is not visible inside the main application.

Now, how can I set focus on this attribute? Somehow, I need to call the check_data method inside the view of the embedded components, so that they can then call the REPORT_ATTRIBUTE_ERROR_MESSAGE and set focus appropriately.

Any clues please?

Thanks in adv.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Aishi,

Can you try this code to capture the error message and then use it to display the attribute.

*   get message manager



revert back if any issues

Reward pts if found usefull



Answers (2)

Answers (2)

Former Member
0 Kudos

In the used component, have an interface method set_focus with importing parameter as a string. When you want to set focus, call this method from the using component, with the element name. The used component should then set the focus in its view.

This can also be done with an interface node. I havent tried such a thing, but I think one of these approaches should work.



Former Member
0 Kudos

Thanks Nithya and Phil.

Actually I want to set focus inside the called component only, but don't know how to do it.

Let me tell the scenario:

Main component : CO_MAIIN.

Dyanmically embedded components: CO_1, CO_2... CO_n.

Dynamic ViewContainerUI elements created for inserting these components: UI_1,UI_2... UI_n.

Now after showing everything, when user presses on a button in CO_MAIN's view, it calls a method : check_data for all components CO_1...CO_n one by one (interface method).

If any of the components has an error, it should show the error.

So far I have always shown/called the message controller only inside a view. I don't know how to call it inside the component controlers.

Let's say error is in CO_5. It has a view V0. Ideally V0 should give the error : REPORT_ATTRIBUTE_ERROR_MESSAGE.

So let me know rephrase my question. Can I issue this method inside a component controller and set focus also? If so, how?

Thanks again.

Former Member
0 Kudos

Use the wizard to generate the Message call. From within a method in comp controller.

Of course With Attribute version or error message to highlight the field that is the issue.

You will need to have the element that is at fault.

If View and comp controller shared mapped context, then should work no problem at all.

Otherwise the view will need to pass element ref to comp controller.

Why not pass the element to the check data method ?



Former Member
0 Kudos

Thanks Phil.

View and Comp controlle context is mapped. That's not an issue.

Actually i was thinking that to generate "Attribute error" message, you need to be inside the view - that is, you need to give it from within the view.

You mean to say inside my component controller, I can give an error on a UI element in View V0 ?

Can you send me the code how to do that?

Thanks again!

Former Member
0 Kudos

Hi Aishi,

To report errors on a UI element, you should use the methods report_attribute_error_message or report_attribute_exception, in the message manager interface. Refer if_wd_message_manager for the method signatures. The error will be shown on the UI element bound to the context attribute.



Former Member
0 Kudos

When you issue the message you should still use the REPORT_ATTRIBUTE_ERROR_MESSAGE.

From an MVC view it is questionable behaviour

that a component should issue error messages for a component it has embedded ?

It is still possible, if the component passes you a pointer to the element in question.

Otherwise the set focus which works from the view...

  DATA: lr_elem TYPE REF TO if_wd_view_element.
lr_elem = view->get_element( wd_this->field ).
if lr_elem is BOUND.
 view->request_focus_on_view_elem( lr_elem ).

Ah but it is in another view....

Did someone say MVC ? I repeated myself, sorry.

Can you call the embedded component.

Ask it to set focus.