cancel
Showing results for 
Search instead for 
Did you mean: 

How to enable / disable my UI elements.

Former Member
0 Kudos

Hi,

I have 2 UI (Input field) in my layout ,both are set to disabled in properties.

Also i have a button called EDIT,so whenever i click this button during runtime , these inputfields has to get enabled.

How i can get this ?

Please help me.

Regards

Siva

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Siva,

Suman has given you the suggested way of achieving this functionality i.e, binding the "Enabled" property of the input field to an context attribute of type ABAP_BOOL & then manipulating its values in the buttons action handler. If however you are just trying to have a go at dynamic programming in WebDynpro ABAP then this is the way that you can do it. However please note that we are suggested not to follow this approach as it involves modifying the layout in a method other than WDDOMODIFYVIEW. This is a violation of the Web Dynpro Phase Model and is not recommended by SAP. This can lead to problems or inconsistencies down the road for which SAP will not be responsible. All dynamic manipulation must occur in the WDDOMODIFYVIEW.

Regards,

Uday

1) Create 2 input fields in the layout with id's as I1 & I2.

2) Create a button with an action (say by name "Enable") associated with it.

3) Create 2 view level attributes as shown below:

lr_i1 type ref to cl_wd_input_field
lr_i2 type ref to cl_wd_input_field

4) In WDDOMODIFYVIEW save the references of the input fields into the 2 above variables as shown below:

METHOD wddomodifyview .
  check first_time = abap_true.
    wd_this->lr_i1 ?= view->get_element( id = 'I1' ).
    wd_this->lr_i2 ?= view->get_element( id = 'I2' ).
ENDMETHOD.

5) Finally the code to make the input fields as enabled on click of the button:

method ONACTIONENABLE .
  wd_this->lr_i1->set_enabled( value = 'X' ).
  wd_this->lr_i2->set_enabled( value = 'X' ).
endmethod.

Former Member
0 Kudos

let me try all your views..

Please stay in touch and help me.

Thanks

siva

Former Member
0 Kudos

Uday,

I tried with suman's view to get to know how its working,but my inputfields are not visible.

let me explain what i did..

1 created a attribute under a context node wit the type ABAP_BOOL.

2 inside my button EDIT, created an action and used the coding prescribed by suman.

3 finally i assigned that attribute to my inputfield visible property.

but during testing ,am not able to find the inputfield..it has been disappeared.

@Suman,also i need your suggestion over this.

*******************************************************************

method ONACTIONEDIT .

DATA lo_el_context TYPE REF TO if_wd_context_element.

DATA ls_context TYPE wd_this->element_personal_detail.

DATA lv_enable LIKE ls_context-enable.

  • get element via lead selection

lo_el_context = wd_context->get_element( ).

lv_enable = abap_true.

CALL METHOD LO_EL_CONTEXT->SET_ATTRIBUTE

EXPORTING

VALUE = lv_enable

NAME = 'ENABLE'.

endmethod.

*********************************************************************

My context structure

Context

|

-


Customer ( Node )

-


Personal_detail (Node)

-


First_name (attribute)

-


Nationality (attribute)

-


Enable ( attibute of type ABAP_BOOL ).

**********************************************************************

Regards,

Siva ( Beginner in Dynpro)

Edited by: SivaKumar on Oct 16, 2008 11:31 AM

Edited by: SivaKumar on Oct 16, 2008 11:34 AM

uday_gubbala2
Active Contributor
0 Kudos

Hi Siva,

I will try explain you what Suman what intending to convey you. You have 2 input fields in your view and now you need 4 context attributes so that you can use 2 of them for binding the property "Enabled" and the other 2 for binding the property "Value".

1) I create 2 more attributes I1 & I2 of type ABAP_BOOL with a default value of ' ' i.e, leave the default value as it is without writing anything inside it. (I created these 2 attributes under a node PARENT_NODE)

2) I create 2 attributes val1 & val2 of type STRING for using to bind the input fields VALUE property

3) I now place 2 input fields on the view layout & bind their VALUE to val1 & val2 & their ENABLED property to I1 & I2.

4) Now place a button in the layout and create an action for it say ENABLE. Now put the below coding into the ONACTIONENABLE method.

METHOD onactionenable .
  DATA : lr_node TYPE REF TO if_wd_context_node.

  lr_node = wd_context->get_child_node( name = 'PARENT_NODE' ).

  lr_node->set_attribute( EXPORTING name  = 'I1'
                                    value = 'X' ).

  lr_node->set_attribute( EXPORTING name  = 'I2'
                                    value = 'X' ).
ENDMETHOD.

Hope this is clear now.

Regards,

Uday

Former Member
0 Kudos

Hi Siva,

3 finally i assigned that attribute to my inputfield visible property.

Dont bind the context attribute to visible property,bind to enabled property of input fields.

One attribute is enough no need to declare two attributes.

Former Member
0 Kudos

Uday,thanks for your wonderful explanation,

i tried with your explanation but my fields are still in disabled mode after clicking the EDIT button,only the value 'X' are being passed into those fields.

siva

uday_gubbala2
Active Contributor
0 Kudos

Hi Siva,

You aren't getting the desired output coz you have bound the input fields to the wrong attributes. In order to make your input fields enabled from disabled mode you are modifying the attribute (of type ABAP_BOOL) value to X from the default ' '. If you had bound this attribute to the ENABLED property of your input field the field would have got enabled as how desired. But you have mistakenly bound this attribute to the VALUE property of the input field. Because of this the field remains as disabled and then displays a value of X inside it after pressing on the button. I hope that you have understood what I have explained. Just check & correct which properties you have bound your attributes to.

Regards,

Uday

Former Member
0 Kudos

Thanks Uday...thanks a lot,its working.. its bcos am a begginer,its difficult to understand.. but now i got it.. thanks a lot.. assigned points to all my saviours.. thanks ..

Answers (3)

Answers (3)

Former Member
0 Kudos

hi,

Its very simple!!!!!!! You can do the same this way also:

1) Create a context attribute named "ENBL" type WDY_BOOLEAN (Do not check the read only property of context attribute).

2) Now bind this context to ENABLE or READ ONLY property of your input box UI element.

Initially the fields will be disabled or in read only mode when you try to run your application.

3)On the action of push button write the following code:

wd_context->set_attribute( name = 'ENBL' value = 'X' ).

This will enable the input box ready for input.

hope, this will help you.

Thanks,

Sumit

Former Member
0 Kudos

Hi Sumit,also i tried in your way of doing ..

i changed my context attribute ENABLE frm ABAP_BOOL to WDY_BOOLEAN ,then assigned to ENABLED property of my UI element in layout and coded as the same way you mentioned,but the inputfields are still in display mode and getting only 'X' in my fields ( same result as what i tried with UDAYs method ).

Please tell me whether i did anyother mistakes

SIva

Former Member
0 Kudos

Hi Siva,

Still your problem is not solved, though we gave complete code to you tell me what is your problem and what you are getting output.

Are you following the procedure as it is what we gave you.just try once again properly and let us know still your problem is not solved

Edited by: suman kumar chinnam on Oct 16, 2008 11:21 AM

Former Member
0 Kudos

Yes suman..

i followed exactly what you all explained but my problem is not solved..

i created the attribute ENABLE with type ABAP_BOOL and assigned this to my input field enable property .

then in my button action event ,i have written the code as you suggested.

DATA : lr_node TYPE REF TO if_wd_context_node.

lr_node = wd_context->get_child_node( name = 'PERSONAL_DETAIL' ).

lr_node->set_attribute( EXPORTING name = 'FIRST_NAME'

value = 'X' ).

___________________________________________________

but in the output ,after clicking the edit button am getting the inputfields in disabled mode oly with jus oly the value x has been passed

Former Member
0 Kudos

Hi Siva,

the mistake is name change name to ENABLE instead of FIRST_NAME

lr_node->set_attribute( EXPORTING name = 'FIRST_NAME'
value = 'X' ).

check this code and do in this way.

DATA: lo_nd_person TYPE REF TO if_wd_context_node,
    lo_el_person TYPE REF TO if_wd_context_element,
   ls_person TYPE wd_this->element_person.
* navigate from <CONTEXT> to <PERSON> via lead selection
  lo_nd_person = wd_context->get_child_node( name = wd_this->wdctx_person ).

ls_person-enable = abap_true.
CALL METHOD LO_ND_PERSON->SET_ATTRIBUTE
  EXPORTING
*    INDEX  = USE_LEAD_SELECTION
    VALUE  = ls_person-enable
    NAME   = 'ENABLE'

.

Edited by: suman kumar chinnam on Oct 16, 2008 11:40 AM

Former Member
0 Kudos

Hi,

The enabled property takes the abap_bool type flag.

So you define an abap_bool object calle dvisibility with default val = '-' and bind this with Enabled property of input field.

And later on click of the button change it to 'X'.

I hope it helps.

Regards,

Sumit Oberoi

Former Member
0 Kudos

Hi siva,

Create a context attribute enable of type abap_bool.

populate this attribute in the eventhandler method of button with abap_true.

bind this attribute to the visible property of your input field in the layout.

thats all you will the input fields with enable.

check this code.

DATA lo_el_context TYPE REF TO if_wd_context_element.
  DATA ls_context TYPE wd_this->element_context.
  DATA lv_enable LIKE ls_context-enable.
* get element via lead selection
  lo_el_context = wd_context->get_element(  ).
  
  lv_enable = abap_true.
  CALL METHOD LO_EL_CONTEXT->SET_ATTRIBUTE
    EXPORTING
      VALUE  = lv_enable
      NAME   = 'ENABLE'

.

Edited by: suman kumar chinnam on Oct 16, 2008 6:16 AM

Edited by: suman kumar chinnam on Oct 16, 2008 6:28 AM