on 09-05-2013 10:11 AM
Hi Experts,
I had created a Web Dynpro Application in which i want to Hide a Button Dynamically in WDDOMODIFYVIEW Method ? The Button has to disabled based on some condition.
I have Looked into numerous examples but couldn't get it.
Thanks & Regards
Priyesh Shah
Hello Priyesh,
I would recommend you to not to do this in wddomodify view method as this method would be triggered every time you make an action on the view.
Instead based on the logic, you may want to pick a method associated to an action or an event and then change the value of type boolean binded to visible property of a button.
As an alternate you could also create a button dynamically, this you have to do it in wddomodify method only.
Regards
Anurag Chopra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Priyesh,
I am sorry, I could not reply earlier than today.
So what i have understood is that ,,,Say a scenario where you want to hide a button based on which user has logged in ? or whatever external condition,...Is it dynamic or static per session.
if it is static per session, you could do it in wddoinit method
or if it is dynamic per session ,,,,then change in condition must be throwing an event or you create own and fire it and event handler of that method , you could change the value of the boolean attribute which is binded to visibility property.
if this doesnt help, Please explain your scenario in detail.
Regards
Anurag Chopra
Hi Anurag,
As of now i haven't integrated the Web dynpo component in the Net weaver Portal so couldn't say any thing about session.
Also for testing my code i am executing the component through se80. My main intension is that suppose there are two user User A & User B when user is asked for his user id & password it take him to my view "MAIN" here i want to write a condition that if user A is there then Show the button or other UI element & if User B is there then don't show him.
I hope you now understand.
if so possible can you provide me some sample screen shots of your.
Thanks & regards.
Hi Priyesh,
Since you want to show or hide the button based on the user's authorization, you should consider putting your logic into hook method WDDOINIT, which will be executed just once when the view is initialized. If you put your logic into WDDOMODIFYVIEW, the logic will be executed every time the view refreshes, which is unnecessary for an authorization scenario.
As others have mentioned, bind the visible property of your button UI element to a context attribute of type WDUI_VISIBILITY. Then in the view's WDDOINIT method, set the value of this context attribute to either CL_WD_UIELEMENT=>E_VISIBLE-VISIBLE to show the button or CL_WD_UIELEMENT=>E_VISIBLE-NONE to hide the button.
You can check out the fixed values of domain WDUI_VISIBILITY to see what actual values these constants are mapped to.
You can use the code wizard to set the value of the context attribute. Below is an example...
METHOD wddoinit .
DATA lo_nd_mynode TYPE REF TO if_wd_context_node.
DATA lo_el_mynode TYPE REF TO if_wd_context_element.
DATA lv_visible TYPE wd_this->element_mynode-visible.
lo_nd_mynode = wd_context->get_child_node( name = wd_this->wdctx_mynode ).
lo_el_mynode = lo_nd_mynode->get_element( ).
IF user_is_authorized.
lo_el_mynode->set_attribute(
name = `VISIBLE`
value = cl_wd_uielement=>e_visible-visible ).
ELSE.
lo_el_mynode->set_attribute(
name = `VISIBLE`
value = cl_wd_uielement=>e_visible-none ).
ENDIF.
ENDMETHOD.
Cheers,
Amy
As you said you have made a button already, now made a node/attribute. while creating that button there will be a property ENABLED bind that property with newly created attribute. Now based on your condition fill the value of that attribute.
Attribute type- Can be Char1.
Char1- X for make it visible and initial(empty) to make it disable.
make it like this..
enabled = node_name.attribute_name
and based on any condition set value of that attribute.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Priyesh,
Create one attribute say ENABLE of type WDY_BOOLEAN and bind this to button visibility property
In WDDOMODIFYVIEW Method write code to set atrubute to enable.
If scenario 1(your condition)
lo_el_context->set_attribute
EXPORTING
name = 'ENABLE'
value = ABAP_TRUE // for Enable
else.
EXPORTING
name = 'ENABLE'
value = ABAP_FALSE // for Disable
endif.
Hope it might resolve your issue.
Thanks
Katrice
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can also disable the button using below code without creating the attribute of type WDY_BOOLEAN. suppose SENDMAIL is the Button ID in property table in view
DATA lo_button TYPE REF TO cl_wd_button.
lo_button ?= cl_fitv_wd_util=>ui_assert_element( io_view = view iv_id = 'SENDMAIL' ).
cl_fitv_wd_util=>ui_set_enabled( io_view_element = lo_button iv_enabled = abap_false ).
Few more dynamic functionality:
1) To set the text
cl_fitv_wd_util=>ui_set_text( io_view = view iv_id = 'CUSTOMIZING_TEXT' iv_text = 'customizing text' ).
2) To set the UI element's Tool tip text.
cl_fitv_wd_util=>ui_set_tooltip( io_view = view iv_id = 'CUSTOMIZING_TEXT' iv_tooltip = 'Tool_tip_text' ).
3) To set the UI element disable
cl_fitv_wd_util=>ui_set_enabled
( io_view = view iv_id = 'CUSTOMIZING_TEXT' iv_enabled = abap_false ).
4) To set the UI element Invisible
cl_fitv_wd_util=>ui_set_visible( io_view = view iv_id = 'CUSTOMIZING_TEXT' iv_visible = abap_false ).
Hi,
Create an attribute 'visible' of type wdy_boolean in the context and Bind the 'visibility' property of button to the attribute visible.
Now in your method based on your condition set the attribute to abap_true or abap_false to show/hide the button dynamically.
Regards,
Kiran
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
the button you created has attribute "visible". Bind this attribute to an context attribute of type wdy_boolean.
According to your conditions you can set this context attribute (in WDDOMODIFYVIEW) to abap_true or abap_false, and thus your button will be visible or not.
Regards...
ismail
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.