cancel
Showing results for 
Search instead for 
Did you mean: 

Field to make uneditable only for the current/selected row

Former Member
0 Kudos

I have a web dynpro application and I wanted to make some fields uneditable and for this I have done the following:

I bound a context attribute to the readOnly property of all the fields you want to control. Then in the onEnter event of the main field, I set the value of this bound context attribute to ABAP_TRUE to change the state of the corresponding UI elements.

I have written the following in the onenter event of the main field:

DATA lo_el_context TYPE REF TO if_wd_context_element.
   DATA ls_context TYPE wd_this->element_context.
   DATA lv_editable TYPE wd_this->element_context-editable.
 
*  get element via lead selection
   lo_el_context = wd_context->get_element( ).
 
*  @TODO handle not set lead selection
   IF lo_el_context IS INITIAL.
   ENDIF.
 
*  @TODO fill attribute
*  lv_editable = 1.
 
*  set single attribute
   lo_el_context->set_attribute(
     name =  `EDITABLE`
     value = 'ABAP_TRUE' ).

Now the issue is that when I hit enter on the main field all other fields gray out/uneditable for all the rows, what I want is the other fields should be greyed out only for the row where I am entering the main field and hit enter.

Can you please tell me how can I do that?

Thanks,

Rajat

Accepted Solutions (1)

Accepted Solutions (1)

gill367
Active Contributor
0 Kudos

hi

You need to add one attribute of type wdy_boolean to the node used as the data source for the table.

and then bind the read only property of the desired cell editors to this property.

now in the on enter event .

get the of the element from which the event was fired.

and change the attribute controlling the read only property for this element.

then only this row will get the changes.

some sample code.

data el type ref to if_wd_context_element.
el = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).
"now set the read only property for the attribute for this element
el->set_attribute( 
name = '<name of the attribute>'
value = abap_true
)

thanks

sarbjeet singh

Former Member
0 Kudos

Thanks for the reply...

The node that has the table... is a table of standard BAPI which i called using service call and it didn't allow me to add the attribute within that. SO i have created an attribute under the context itself.

and I have written the following code:

lo_el_context = wd_context->get_element( ).

    lo_el_context->set_attribute(
      name =  `EDIT`
    value = 'ABAP_TRUE' ).

but it's just graying out all the rows.

Former Member
0 Kudos

Hi Raj,

You are not getting it. When you have only one context attribute and bind that to all the rows/columns of the table then everything will be enabled or disabled.

In your case, create a local node with cardinality 1:1 inside the node you already have.

Write a supply a function for this node.

Add a attribute read_only of type wdy_boolean.

bind this attribute to the read_only property of the table columns.

in the supply function based on the element conditions you might have enable this attribute of disable.

supply function method already has the necessary code , you only need to enable the commented lines and put your if ..end if code around it.

See a example.

* General Notes
* =============
* A common scenario for a supply method is to aquire key
* informations from the parameter <parent_element> and then
* to invoke a data provider.
* A free navigation thru the context, especially to nodes on
* the same or deeper hierachical level is strongly discouraged,
* because such a strategy may easily lead to unresolvable
* situations!!

*  if necessary, get static attributes of parent element
  DATA ls_parent_attributes TYPE wd_this->element_sflight.
  parent_element->get_static_attributes(
    IMPORTING
      static_attributes = ls_parent_attributes ).

*
** data declaration
  DATA ls_prop TYPE wd_this->element_prop.
** @TODO compute values
** e.g. call a data providing FuBa
  IF ls_parent_attributes-carrid <> 'LH'  .
    ls_prop-read_only = abap_true.
  ELSE.
    ls_prop-read_only = abap_false.
  ENDIF.

** bind a single element
  node->bind_structure(
    new_item             =  ls_prop
    set_initial_elements = abap_true ).
*

Former Member
0 Kudos

Hi Baskaaran,

It resolved the issue, actually earlier I was trying to insert the node in the view and not at the component controller. As soon as I made this chnage it started working... but I am still not sure how come it's working .. can you please explain me a little bit on this as I am pretty new to webdynpro.

Former Member
0 Kudos

Hi,

first tell me which solution is working for you ? i shall explain after that based on the answer.

Former Member
0 Kudos

I created an anttribute under a node and it worked fine... earlier I created an attribute only.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi rajatg,

Quite easy in fact.

Your context field for read-only should be included in the table to be set on a line basis.

So for each line you will decide if it is read only or not and then bind the whole table.

Regards,

Mathieu.

Edited by: Mathieu Chenu on Mar 2, 2011 4:25 PM

Former Member
0 Kudos

Hi Maitheu,

Thanks fo rthe reply... I didn;t see anywhere where I can set on a line basis, can you please tell me where can I find that.

Former Member
0 Kudos

Hi,

You need to approach this as of you are doing coloring of the table columns.

You need a context attribute read_only as one of the attribute in the node which you binded for the table.

See this example to get some idea.

[http://wiki.sdn.sap.com/wiki/display/Snippets/CreatingaColorLegendinaTableinWebDynpro|http://wiki.sdn.sap.com/wiki/display/Snippets/CreatingaColorLegendinaTableinWebDynpro]

Former Member
0 Kudos

You should get the Lead Selection Element for that particular row and set the context attribute for that row only,.

Thanks,

Shikhil

Former Member
0 Kudos

Hi Shikhil,

Thanks for the reply... can you please explain this in a lilttle detail...