cancel
Showing results for 
Search instead for 
Did you mean: 

Changing the text of the button dynamically

Former Member
0 Kudos

hi..

i hv the same requirement of changing the text of the button dynamically when i click it ...

so in the event handler of that button i want to change the text for that button and change its functionality as well..

Can u help me out..

and also how to display popups ...

jagruti..

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Jagruti,

The simplest way to change the text of the button dynamically is to bind the text property to a context attribute. Then, simply change the context attribute to the new text and automatically the button text will change to the new value.

As for the functionality, you can bind only one event handler to a button. So, inside the event handler, have the logic based on the button text. For ex:

case button_text.
 when 'ONE'.
   "do processing required when button text is ONE.
 when 'TWO'.
   "do processing required when button text is TWO.
endcase.

Hope this solves your problem.

Regards,

Ram

Former Member
0 Kudos

hi...

thanx for quick response..

case button_text.

when 'ONE'.

"do processing required when button text is ONE.

when 'TWO'.

"do processing required when button text is TWO.

endcase.

wht is button_text here.

jagruti

Former Member
0 Kudos

Hi,

The

button_text

here refers to the actual text that is set for the button.

What you need to do is as follows:

1. Read the context attribute that you have bound to the button's text property into a variable called

button_text

.

2. Use this variable for the

case

statement.

Please post back in case you have further issues.

Regards,

Ram

Former Member
0 Kudos

hi Ram..

thnx for ur response..changing the text of the button works fine...

Can u help me out with the popups..

I want an inputfield and a ok buttton in the popup..

and when i say ok in the popup i should b able to read the value entered by the user...

Code Snipet will b appreciated.

Jagruti..

Former Member
0 Kudos

Hi,

AFAIK, the standard set of popups do not allow an input field with a button. In that case, I think you can define a view with an input field and an ok button. This view should be embedded in a window and can be launched as a popup window. In the onAction event of the button, you can read the context to get the value entered in the input field.

If you want to perform any operation in your calling view (main view) based on this value, you can declare it in the component controller. Hope this helps.

Regards,

Nithya

mohammed_anzys
Contributor
0 Kudos

Hi Jagruti,

I have put this code in the controller and calling it in my view.

Data:l_cmp_api type ref to if_wd_component,

l_window_manager type ref to if_wd_window_manager,

l_comp_info type ref to IF_WD_RR_COMPONENT,

l_final_window type ref to IF_WD_WINDOW.

l_cmp_api = wd_this->wd_get_api( ).

CALL METHOD L_CMP_API->GET_COMPONENT_INFO

RECEIVING

COMPONENT_INFO = l_comp_info

.

  • CALL METHOD L_COMP_INFO->GET_WINDOW

  • EXPORTING

  • WINDOW_NAME = 'W_POPUP

  • RECEIVING

  • RESULT = l_com_window

  • .

l_window_manager = l_cmp_api->get_window_manager( ).

CALL METHOD L_WINDOW_MANAGER->CREATE_WINDOW

EXPORTING

  • MODAL = ABAP_TRUE

WINDOW_NAME = 'W_POPUP

  • TITLE =

  • CLOSE_BUTTON = ABAP_TRUE

  • BUTTON_KIND =

  • MESSAGE_TYPE = IF_WD_WINDOW=>CO_MSG_TYPE_NONE

  • CLOSE_IN_ANY_CASE = ABAP_TRUE

  • MESSAGE_DISPLAY_MODE =

  • DEFAULT_BUTTON =

RECEIVING

WINDOW = l_final_window

.

wd_this->LO_POPUP = L_FINAL_WINDOW.

CALL METHOD L_FINAL_WINDOW->OPEN

.

The window name provided is the name of the window that you created , where you embedded the views for the pop up.

I have saved the instance in the controller to close the window in future.You could also go to this blog

/people/mohammed.anzys/blog/2007/06/10/webdynpro-abap-controlling-external-windows

Thanks

Anzy

reward points for useful answers.

Former Member
0 Kudos

Hi Jagruti,

Here are the steps to achieve your functionality:

1. Create a new view (say, view_input) and place your input field there. In fact, you can design this view just like any other view - with any number of controls. Do not place the 'OK' button inside this view - the 'OK' button will be present automatically when you create the popup window!

2. Map the relevant context attributes to this view and to the inputfield in the view.

2. Create a new window (say, win_pop) and embed the above view into it.

3. Now, in your main view, the place where you want to call the popup window, use the following code:


  data lo_window_manager type ref to if_wd_window_manager.
  data lo_api_component  type ref to if_wd_component.
  data lo_window         type ref to if_wd_window.

  lo_api_component  = wd_comp_controller->wd_get_api( ).
  lo_window_manager = lo_api_component->get_window_manager( ).
  lo_window         = lo_window_manager->create_window(
                     window_name            = 'WIN_POP'
*                    title                  =
*                    close_in_any_case      = abap_true
                     message_display_mode   = if_wd_window=>co_msg_display_mode_selected
*                    close_button           = abap_true
                     button_kind            = if_wd_window=>co_buttons_ok
                     message_type           = if_wd_window=>co_msg_type_none
                     default_button         = if_wd_window=>co_button_ok
                     ).
  lo_window->subscribe_to_button_event(
               button            = if_wd_window=>co_button_ok
               action_name       = 'ON_OK_POPUP'
               action_view       = wd_this->wd_get_api( )
               is_default_button = abap_true ).

  lo_window->open( ).

4. In the above, 'On_OK_POPUP' is an action that is called when the user clicks on the 'OK' button in the popup window. For this, you have to create an action with this name in the Main view. Whatever you want to do after the popup window is closed, you have to put the code inside this method. To read the value entered in the popup window, just read the context attribute to which it was bound.

You are done.! Please post back in case you have further issues.

Regards,

Ram

Former Member
0 Kudos

hi ram..

lo_window->subscribe_to_button_event(

button = if_wd_window=>co_button_ok

action_name = 'ON_OK_POPUP'

action_view = wd_this->wd_get_api( )

is_default_button = abap_true ).

at action_view im getting an error....

field wd_get_api( ) is unknow...

jagruti..

Former Member
0 Kudos

Hi Jagruti,

In the attribute section of the view, you have to make the following declaration:

Attrribute: wd_this

Ref to: check this checkbox

associated type: IF_VIEW_NAME (replace view_name with your view name. i think it should be IF_ACTION_VIEW in your case).

Please post back if this solves your problem.

Regards,

Ram

mohammed_anzys
Contributor
0 Kudos

Hi

Wd_this will be automatically created, you dont have to manually create it.Please check where you are writring the code in the controller or something.

please write the code in the view.

Thanks

Anzy

Former Member
0 Kudos

no its not allowing to create wd_this as a parameter

wht exactly shud action_view have..

Former Member
0 Kudos

You should not create it as a parameter. It is an attribute that you will find in the attributes section of your view. Like Anzy mentioned, this is created automatically.

Please verify that you are writing the code inside a method/action in you <b>view</b> and not anywhere else.

Regards,

Ram

mohammed_anzys
Contributor
0 Kudos

Hi

if you are creating the method in the view , you will be able to get wd_this->wd_get_api( ).

Recheck your code.

Tahnks

Anzy

Former Member
0 Kudos

yes im writing it in my view's method only...

mohammed_anzys
Contributor
0 Kudos

Hi jagruti,

Can you please post some of your code , so that i could try to recreate your issue and solve it

Thanks

Anzy

Answers (2)

Answers (2)

Former Member
0 Kudos

In the modifyview method, get the reference of your button by passing the ID of the UI element.

lr_button type ref to cl_wd_button.

lr_button ?= view->get_element( 'ID' ).

now you can do a lr_button->set_text, bind_action etc.

For creating popups, get a reference to your window manager by calling the following:

lr_comp_api = wd_comp_controller->wd_get_api( ).

window_manager = lr_comp_api->get_window_manager( ).

Now call method create_popup_to_confirm which will return you a window object. Call method window->open to open the popup.

Hope this helps.

Regards,

Nithya

Former Member
0 Kudos

Hi Jagruti,

You can use the WebdynPro code wizard (Ctrl + F7) to create a popup window. But, before using the codewizard, create a window and embed whatever views you want to show in a popup window.

However, if you are want to just show a message in a popup, you can use the following code to do it:

  DATA: l_cmp_api          TYPE REF TO if_wd_component,
        l_window_manager   TYPE REF TO if_wd_window_manager,
        l_popup            TYPE REF TO if_wd_window,
        l_text             TYPE string_table,
        l_api              TYPE REF TO if_wd_view_controller.
  DATA message type string.

  l_cmp_api        = wd_comp_controller->wd_get_api( ).
  l_window_manager = l_cmp_api->get_window_manager( ).

  Message = 'Your message here.!'.
  append message to l_text.

  l_popup = l_window_manager->create_popup_to_confirm(
                TEXT            = l_text
                button_kind     = if_wd_window=>co_buttons_ok
                message_type    = if_wd_window=>co_msg_type_information
                window_title    = 'Information'
                window_position = if_wd_window=>co_center ).

  l_popup->open( ).

Hope this helps. I will get back with the way to change button text.

Regards,

Ram