on 05-14-2009 10:56 AM
Hi!
I have a Caption in a View's Layout and i'd like to change its text properties when a user click on a button.
Now i have created the OnAction Event for the button, but i don't know how to point to that Caption!
How can i navigate through ROOTUIELEMENTCONTAINER to this Caption ID ?
Thanks.
Hi Fabio,
The best way for you would be to bind your Captions "text" property to an context attribute & specify your original value over there. By using this approach you can then simply code within your buttons action handler to modify the text by modifying the context attribute using a simple set_attribute( ). This would be the suggested & easy manner.
However am just explaining for your reference as to how you can achieve the same using the dynamic class methods. First obtain & save the reference of your caption into a view level attribute of type ref to CL_WD_CAPTION.
So withing your WDDOMODIFYVIEW you pass your Captions id & obtain its reference:
wd_this->lr_caption = view->get_element( id = 'CAP1' ).
So now within your buttons action handler you can change the text by saying as:
wd_this->lr_caption->set_text( value = 'My new text!' ).
However just please keep it in mind that we are not supposed to save & use the reference of ui elements like in the 2nd approach. We are supposed to modify our layout only within WDDOMODIFYVIEW & SAP wouldn't support any problems that we might run into while following this latter approach.
Regards,
Uday
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fabio,
Sorry for missing out on this. I usually copy & paste out real working code from my sandbox so that no one faces any problem with the code snippets. This time the server was down and so I had typed it out from my mind. You now know as to why its wrong!
Well you just need to make use of casting and it would work fine. Just correct the earlier code in WDDOMODIFYVIEW & say as:
method WDDOMODIFYVIEW .
check first_time = abap_true.
wd_this->lr_caption ?= view->get_element( id = 'CAP1' ).
endmethod.
Below is my buttons action handler method:
method ONACTIONCHANGE_CAPTION .
wd_this->lr_caption->set_text( value = 'My new text!' ).
endmethod.
So now on click of the button my captions text would change to "My new text!".
My Caption's id is CAP1 & I have defined an attribute lr_caption as type ref to cl_wd_caption in my views Attributes tab... Dont worry this code snippet would work!
Regards,
Uday
Context-->Attribute + set_attribute
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Create a context attribute of type string and bind it with the text property of caption.
And onaction of button set that attribute using code wizard(cntrl+F7). i.e Pass your text at run time.
I hope it helps.
Regards,
Rohit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
If you want to set a property of the UI element during the dynamic creation, pass the values when you create the element. To enhance the above example with a text on the button to be created (the text has been created before in the Online Text Repository):
data: MY_TEXT type string.
MY_TEXT = CL_WD_UTILITIES=>GET_OTR_TEXT_BY_ALIAS( 'MY_TEXT_ALIAS' ).
LR_BUTTON = CL_WD_BUTTON=>NEW_BUTTON( text = MY_TEXT ).
Refer the link also:
http://help.sap.com/saphelp_nw04s/helpdata/EN/77/3545415ea6f523e10000000a155106/frameset.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Bind the properties of the Caption which you want to change to context attributes of appropriate type. For binding any property just click on the box next to the property and a pop up will open where you can choose the context attribute. Now in the event handler method just set the context attributes to the values you want and the properties of Caption are set to the value of the context attribute.
Edited by: Pooja Patodia on May 14, 2009 12:01 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.