cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Input and Button UI Element when doing an action

Former Member
0 Kudos

Dear All,

I have a requirement like this, initially i have one button in view, when i click on that button i need to add some group of input fields(say 10) and one button. can we achieve this? any code help pelase..

Thanks and Regards,

Venkat.

Accepted Solutions (1)

Accepted Solutions (1)

gill367
Active Contributor
0 Kudos

Hi

it is very much possible.

You need to write the code in the wddomodifyview method to create the button and the input field.

and create one context attribute and set its value in the event handler and check in the Wddomodify.

and execute the code only for that specific case.

let me know if you need step by step details

thanks

sarb

Former Member
0 Kudos

Hi Sarbjeet

Thanks for your quick reply..

My requirement is like this...

ROW1(input fields and button) -- (ROW )Button (when click on button )

ROW contains sub contains, i.e., if i click on ROW button i need to add one more group of input fields and with one button (ROW2)., if i click ROW2 one more group i have to add.

If i click on ROW again one more group for ROW1. This is the requirement.

When i click on the button i need to add all input fields and button like one row, if i click next time i want to add same like row in next line is it possible?? please tell me how to do this

thanks,

venkat.

Edited by: venkat1011 on Jan 17, 2011 6:31 AM

sahai
Contributor
0 Kudos

hi venkat,

when a layout has to be designed in webdynpro we have to bing the input field or any ui element with the context so that the data flow can be maintained ....remember this.

now talking about the requirement there are two considerations.

consideration1:--- you know that how may rows are to be added ...

in this you can simply bind the enabled property of the input field with a boolean attribute and on action of the button you can make it visible.

consideration 2...... you do not know that how many rows are to be added,...

in this situation you will have to bind the input field dynamically.

let me know if you have any further query on this..

regards,

sahai.s

Former Member
0 Kudos

Hi Sahai,

I want to create 10 input fields and 1 button and these i have to display in one row(same line ) when i click on button. how to do this dynamically, can u have any code.. pelase help

Thanks,

venkat

Edited by: venkat1011 on Jan 17, 2011 8:48 AM

sahai
Contributor
0 Kudos

hi,

you can create the input field required in the layout ....and then in the context add attribute say...enable of type wdy_boolean. now in the layout check the " enabled" property and bind it to the attribute you added i.e enable....and den set that value of attribute to abap_false or abap_true as per the condition checked.....this will let you the input fields enable and disabled dynamically.

IF WA_ZAUTHO-OBJECT = 'AA'.

*   set single attribute
    LO_EL_CONTEXT->SET_ATTRIBUTE(
      NAME =  `ENABLE`
      VALUE = LV_ENABLE ).
*    *     @TODO fill attribute
     lv_enable2 = ABAP_FALSE.
endif.

hope this willhelp you acheive the same.

thanks and regards,

sahai.s

Former Member
0 Kudos

Hi All

Thanks for your replies..

I am using udays code which was posted earlier.. here

method WDDOMODIFYVIEW .

data: lr_node type ref to if_wd_context_node,

lr_node_info type ref to if_wd_context_node_info,

lr_attribute_info TYPE wdr_context_attribute_info,

lv_flag type wd_this->element_test-create_ip_field,

lr_container type ref to cl_wd_uielement_container,

lr_inputfield type ref to cl_wd_input_field,

lv_count type i,

lv_string1 type string,

lv_string2 type string.

lr_container ?= view->get_root_element( ).

cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).

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

lr_node->get_attribute( exporting name = 'CREATE_IP_FIELD'

importing value = lv_flag ).

check lv_flag = 'X'.

" Since the flag is set we need to create input field & an attribute to bind it to

lr_node->get_attribute( exporting name = 'COUNT'

importing value = lv_count ).

lv_count = lv_count + 1.

move lv_count to lv_string1.

concatenate 'ATTR'

lv_string1 into lv_string1.

condense lv_string1 no-gaps.

lr_node->set_attribute( exporting name = 'COUNT'

value = lv_count ).

" Create additional attribute for binding to the input field

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

lr_node_info = lr_node->get_node_info( ).

lr_attribute_info-name = lv_string1.

lr_attribute_info-type_name = 'STRING'.

lr_attribute_info-value_help_mode = '0'.

lr_node_info->add_attribute( EXPORTING attribute_info = lr_attribute_info ).

" lv_string1 would contain the id to be assigned to our input field

lv_string1 = lv_count.

concatenate 'ATTR'

lv_string1 into lv_string1.

condense lv_string1 no-gaps.

" lv_string2 would contain the path of the attribute under our node NODE

concatenate 'NODE.'

lv_string1 into lv_string2.

condense lv_string2 no-gaps.

" Creating new input field & binding it to the above created attribute

lr_inputfield = cl_wd_input_field=>new_input_field( id = lv_string1

bind_value = lv_string2 ).

cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_inputfield ).

lr_container->add_child( the_child = lr_inputfield ).

" Reset the CREATE_IP_FIELD flag variable as we finished with creating the input field

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

lr_node->set_attribute( exporting name = 'CREATE_IP_FIELD'

value = '' ).

endmethod.

*This code working fine its creating inputfields dynamycally. Now my requirement is when i click on button i want to create 10 inputfields one by one on single line and one button. total(11 elements). if i click on button again, i want to display again 10 input +1 button on next line...

EX : Button

input1 input2 .......... input10 button1 - if u click this button1

input1 input 2 ............ input10 button2

button3 ... and so on

if u click main button again

input1 input2........... input10 button1. and so on.....

any help regarding this...*

Thanks

venkat.

gill367
Active Contributor
0 Kudos

Hi,

first create two context attribute in the context

named flag and count

FLAG should be of type WDY_BOOLEAN.

COUNT should be of type INT1.

then just copy paste the code it will work .

Use the following code for creating 10 input fields and one button dynamically in one row.

write this code in wddomodify


DATA lo_el_context TYPE REF TO if_wd_context_element.
    DATA ls_context TYPE wd_this->element_context.
    DATA lv_flag LIKE ls_context-flag.
*   get element via lead selection
    lo_el_context = wd_context->get_element(  ).

*   get single attribute
    lo_el_context->get_attribute(
      EXPORTING
        name =  `FLAG`
      IMPORTING
        value = lv_flag ).


  DATA lv_count LIKE ls_context-count.
* get element via lead selection
  lo_el_context = wd_context->get_element(  ).

* get single attribute
  lo_el_context->get_attribute(
    EXPORTING
      name =  `COUNT`
    IMPORTING
      value = lv_count ).
if lv_flag = abap_true.

Data name1 type STRING value 'NODE'.
data COUNT1 type string.
data attr_name type string value 'ATTR'.
data indx type String.
data tr_name type STRING value 'TR'.
data inp_name type string value 'INP'.
count1 = lv_count.
concatenate name1 count1 into name1.
condense name1.
concatenate tr_name count1 into tr_name.
condense tr_name.



data: lr_container type ref to cl_wd_transparent_container.
data: lr_container1 type ref to cl_wd_transparent_container.
data: lr_flow_data type ref to cl_wd_flow_data.
data: lr_matrix type ref to cl_wd_matrix_head_data.
data: lr_matrix1 type ref to cl_wd_matrix_data.
data :lr_button type ref to cl_wd_button.

lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).

lr_button = cl_wd_button=>new_button( text = 'Add' on_action = 'CREATE' id = TR_NAME ).

 data lo_node type ref to if_wd_context_node.
  data lo_node_child type ref to if_wd_context_node.
data lo_node_info type ref to if_wd_context_node_info.
data lo_childnode_info type ref to if_wd_context_node_info.
DATA EL TYPE REF TO IF_WD_CONTEXT_ELEMENT.
data bind_val type String.
lo_node_info = wd_context->get_node_info( ).
lo_node_info->ADD_NEW_CHILD_NODE( name = name1 ).

 lo_node_child = wd_context->get_child_node( name = name1 ).
EL = LO_NODE_CHILD->CREATE_ELEMENT( ).
LO_NODE_CHILD->BIND_ELEMENT( EL ).

lo_childnode_info = lo_node_child->get_node_info( ).
do 10 times.
  data attr type WDR_CONTEXT_ATTRIBUTE_INFO.
  indx = sy-index.
  concatenate attr_name indx into attr_name.
  condense attr_name.
  attr-name = attr_name.
  attr-TYPE_NAME = 'STRING'.
lo_childnode_info->add_attribute( attr ).
concatenate name1 '.' attr_name into bind_val.
condense bind_val.
condense count1.
condense indx.
concatenate inp_name indx count1 into inp_name.
condense inp_name.
data lr_input type ref to CL_WD_INPUT_FIELD.

CALL METHOD CL_WD_INPUT_FIELD=>NEW_INPUT_FIELD
exporting

bind_value =  bind_val
id = inp_name

RECEIVING

CONTROL = lr_INPUT.
IF sy-index = 1.
lr_matrix = cl_wd_matrix_head_data=>new_matrix_head_data( lr_INPUT ).
lr_INPUT->set_layout_data( lr_matrix  ).

else.
lr_matrix1 = cl_wd_matrix_data=>new_matrix_data( lr_INPUT ).
lr_INPUT->set_layout_data( lr_matrix1  ).



endif.


lr_container->add_child( lr_INPUT ).
inp_name = 'INP'.

enddo.
lr_matrix1 = cl_wd_matrix_data=>new_matrix_data( lr_button ).
lr_button->set_layout_data( lr_matrix1  ).
lr_container->add_child( lr_button ).


* get element via lead selection
  lo_el_context = wd_context->get_element(  ).

* get single attribute
  lo_el_context->set_attribute(
    EXPORTING
      name =  `FLAG`

      value = abap_false ).



  endif.


create first button manually and give it an action named 'CREATE'

wirte the following code in the eventhandler of the first button.



DATA lo_el_context TYPE REF TO if_wd_context_element.
    DATA ls_context TYPE wd_this->element_context.
    DATA lv_flag LIKE ls_context-flag.
*   get element via lead selection
    lo_el_context = wd_context->get_element(  ).

*   get single attribute
    lo_el_context->set_attribute(

        name =  `FLAG`

        value = abap_true ).




  DATA lv_count LIKE ls_context-count.
* get element via lead selection
  lo_el_context = wd_context->get_element(  ).

* get single attribute
  lo_el_context->get_attribute(
    EXPORTING
      name =  `COUNT`
    IMPORTING
      value = lv_count ).
lv_count = lv_count + 1.
 lo_el_context->set_attribute(
    EXPORTING
      name =  `COUNT`

      value = lv_count ).

let me know if you need further assistance

thanks

sarbjeet singh

Edited by: sarbjeet singh on Jan 17, 2011 4:23 PM

Former Member
0 Kudos

thanks sarbjeet

u seems greate..

Thanks and regards,

venkat

Former Member
0 Kudos

Hi Sarbjeet,

I am tring to add labels to all input fields like name1,name2...name10. i want these labels at top and one time only.

EX : now application is like this input1 input2....input10 button.

now my requirement is..

name1 name2 ... name10

input1 input2...... input10 button.

i added some code to this code but its giving error.

can u tell me how to add label to this???

Thanks,

venkat.

Edited by: venkat1011 on Jan 18, 2011 1:50 PM

Answers (3)

Answers (3)

Former Member
0 Kudos

open again

sahai
Contributor
0 Kudos

hi,

check out sarbjeets's reply .

regards,

sahai.s

gill367
Active Contributor
0 Kudos

add the following things..

data lbl_name type string value 'LBL'.          "added for label
data lbl_txt type String value 'TEXT'.         "added for label

the following code in the sy index condition at the end

IF sy-index = 1.
  do 10 times.
    indx1 = sy-index.
    condense indx1.
concatenate lbl_name indx1 count1 into lbl_name. " added for label
condense lbl_name.                               "added for label
concatenate lbl_txt  count1 into lbl_txt.      " added for label
condense lbl_txt.                               "added for label
data lr_label type ref to cl_wd_label.            "added for label
lr_label = cl_wd_label=>new_label(                                "added for label
id = lbl_name                                                              "added for label
label_for = inp_name                                                     "added for label
text = lbl_txt       ).
lbl_name = 'LBL'.
lbl_txt = 'TEXT'.
IF sy-index = 1.

lr_matrix = cl_wd_matrix_head_data=>new_matrix_head_data( lr_label ).
lr_label->set_layout_data( lr_matrix ).

else.

lr_matrix1 = cl_wd_matrix_data=>new_matrix_data( lr_label ).
lr_label->set_layout_data( lr_matrix1 ).


endif.
   lr_container->add_child( lr_label ).
   enddo.

lr_matrix = cl_wd_matrix_head_data=>new_matrix_head_data( lr_INPUT ).
lr_INPUT->set_layout_data( lr_matrix  ).
*lr_matrix = cl_wd_matrix_head_data=>new_matrix_head_data( lr_label ).
*lr_label->set_layout_data( lr_matrix ).
*lr_container->add_child( lr_label ).
lr_container->add_child( lr_INPUT ).
else.


lr_matrix1 = cl_wd_matrix_data=>new_matrix_data( lr_INPUT ).
lr_INPUT->set_layout_data( lr_matrix1  ).
*lr_matrix1 = cl_wd_matrix_data=>new_matrix_data( lr_label ).
*lr_label->set_layout_data( lr_matrix1 ).
concatenate lbl_name indx count1 into lbl_name.
lr_container->add_child( lr_INPUT ).
*zlbl ?= view->get_element( lbl_name ).
*zlbl->SET_LABEL_FOR( inp_name ).

endif.

Edited by: sarbjeet singh on Jan 18, 2011 9:55 PM

Former Member
0 Kudos

Hallo Venkat,

when i see your requirement, i think of the rowrepater UI element as possible solution for you. You do not have to do lot of dynamic programming , you have to bind the row repeater to the context node. on click of the button,add one more element to the context node, Row repeater will add the element to view.

see help here [http://help.sap.com/saphelp_nw70ehp1/helpdata/en/44/93d3792e8c60d6e10000000a114a6b/content.htm|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/44/93d3792e8c60d6e10000000a114a6b/content.htm]

Former Member
0 Kudos

Hi,

All the possible methods are provided in the reply. So just another suggestion from me:

Use WD select_option component to complete your scenario. It will give you flexibility, less coding effort and stable solution.

Thanks and regards,

Pradip

Former Member
0 Kudos

Hi Venkat,

There are two ways of looking at ur requirement.

One way - When you are Designing the View,Place all the Groups ROW( Input Feilds and a Button ), ROW1( Input Feilds and a Button ),,ROW2( Input Feilds and a Button ), in differnet Transaparent Containers and u can assign Visible Propery of all the Transparent Containers dynamically.

Other way - Dynamically adding the all Groups ROW,ROW1and ROW2 with Dynamically Programming

Thanks,

Naga Prakash