cancel
Showing results for 
Search instead for 
Did you mean: 

How an UI element can be accessed in code so its property can be changed.

Former Member
0 Kudos

Actually I have made a simple form which has 4 input fields Firstname, Lastname, Begindate and EndDate. and I have two buttons on the from Initialize and clear. The function of Initialize button is to initialize the four field of form and function of clear is to reset the form. Initially the button clear is invisible.

Now my question is that how to make the button clear visible when we press the Initialize button and form is initialize with initial value.

Accepted Solutions (1)

Accepted Solutions (1)

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi,

Create one context attribute of data type VISIBILITY, from dictionary as

(com.sap.ide.webdynpro.uielementdefinitions.Visibility),

for button clear set its ViSIBLE property to the context attribute.

in init() if you dont wish to show that button make it invisible by

wdContext.currentContextElement().set<context attribute>(WDVisibility.NONE);

now on action of initialise button, write this code

wdContext.currentContextElement().set<context attribute>(WDVisibility.VISIBLE);

also go through thid tutorial for dynamic UI maipulation

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/74cda090-0201-0010-6b91-f85b2489...

regards

Message was edited by:

Abhijeet

Former Member
0 Kudos

Hi Abhijeet,

How to make button clear as current context element in side onActionInitilize() method, as by now initialize button will be current element.

wdContext.currentContextElement().setClear(WDVisibility.NONE);

set<context attribute> is not displaying in the list of methods which pops up after

wdContext.currentContextElement().

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi Sandeep,

set<context attribute> : means replace <context attribute> with whichever value attribute yuo have defined in your program.

regarding making other attribute as current element(UI element cant be refered as currentElement), you need not worry about that, web dynpro takes that care...as long as attribute is direct descendant of root node .

follow these steps

1)define one attribute whose type is visibility(path i gave above), lets say it is ShowBut

2)in button's properties , bind its Visible property to the above value attribute.

3)in init(), you need to write this code so as to make the button initialy invisible,(if your program wants so)

wdContext.currentContextElement().setShowbut(WDVisibility.NONE);

4) then when you call action , ie. when you want to show the button simply write this code there

wdContext.currentContextElement().setShowbut(WDVisibility.VISIBLE);

i hope it will clear your doubt .

let me know if you are in doubt

regards

Former Member
0 Kudos

Hi Abhijit,

I understood what u told me, now I am getting the method setClear also, but it is telling WDVisiblity can not be resolved. Is it needed to be define.

former_member189631
Active Contributor
0 Kudos

Hi,

Did you set you context attribute (For Visibility) id the type "Visibility" ?

Regards,

<b>Ramganesan K</b>

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi,

is Clear , context attribute is of type VISIBILITY, in its datatype(in properties) click on search icon,

go to Dictionary Simple type-> expand Local dictionary->choose com.sap.ide.webdynpro.uielementdefinitions-> here choose <b>Visiblity</b>

hope it helps

regards

Former Member
0 Kudos

Thanks a lot Abhijeet,

Regards

Sandeep

Answers (4)

Answers (4)

Former Member
0 Kudos

As the people before point out, it's possible to change a context attribute with the type WDVisibility in an action.

It is also possible to change attributes in the wdDoModify method right before a page is rendered to the user.

Hoverer in my experience, I think that it's easier to follow code that uses calculated context attribute fields.

If you create a context attribute of type WDVisibility and set it to calculated=true and read-only=false, a get method for accessing the value is created where you can determine the state of the attribute (or the visibility of a button).

After determining the state you simply return a WDVisibility.NONE or a WDVisibility.VISIBLE.

By doing this, you will collect all logic concerning the state of one single button in one place rather than spreading it out in different init or action methods.

When someone else would read your code and wanted to determine exactly when the button is visible and not, he or she would only need to read one method.

Usually the states are determined by some value in a context node. A model node or a value node connected to a structure can't be modified. Instead it's possible to create a child node with cardinality 1..1. Then it's possible to access any value in the parent node via element.node().getParentElement().getAttributeValue("");

By using calculated attributes in the context, I guess you would loose performance somehow, however the code is much easier to read and maintain. It's also easier to cope with new demands on the application's ui behaviours.

Former Member
0 Kudos

Hi Sandeep,

refer to the following code, [ <i>in the wdDoModifyView() method of the view</i> ]

if(firstTime)
{
    	IWDButton btn_clear = (IWDButton)view.getElement("id of the button u defined");
}

Now anywhere in the view, in any method, u can access the properties of the button,like

btn_clear.setVisible(WDVisibility.VISIBLE);

I hope this will help you,

Regards,

Deepak

Former Member
0 Kudos

Hi Deepak,

I have done everything as suggested by you, I have wrote the code wdDOModifyView, but how btn_clear variable can be called from other methods. It is defined in the method wdDOModifyView.

on writing "btn_clear.setVisible(WDVisibility.VISIBLE);" inside method onActionInitialize() btn_clear is not resolved.

Can you suggest me why it is happening so

Former Member
0 Kudos

wdDoModifyView is a static method and the only time you have access to the ui elements (via the view parameter).

onActionInitialize can't access any ui elements.

If btn_clear where a static instance attribute to your class and not a local variable in wdDoModifyView you would be able to access it. However it would make no sense since it would be a static variable shared with all instances of your web dynpro application and this is not what you want in this case. (check for information on the use of static in java)

You will have to create a context attribute and do mapping from the ui element to that attribute and then manipulate the attribute's value. I suggest you create a calculated attribute, but you could also use a normal attribute and set the value in the onAction method.

abhijeet_mukkawar
Active Contributor
0 Kudos

hi,

yeah thats right, also in your program you should take minimum use of UI elements setter method. as wdmodify is static method other method i.e istance method wont be available.

for you problem follow the solution i suggested in above post

hope it helps

let me know if you face any problem

regards

former_member189631
Active Contributor
0 Kudos

Hi Sandeep,

You can chanege the UI element Propertie by coding itself.

One way is,

*Some of the UI element properties are Bindable so you can have context attributes for the corresponding binding data type.

*Please go through this Link to see the binable UI element properties.

http://help.sap.com/saphelp_nw04/helpdata/en/5c/1b76bc3da0504e8b535cf3e154eaa7/content.htm

*And also i suggest you to go through the quiz Application Tutorial for details.

Regards,

Ram.

Former Member
0 Kudos

Hi Sandeep

In implementation write the following code for the Action Initialize button

onActionInitialize()

{

wdContext.currentContextElement.setClear(WDVisibility.VISIBLE);

}

Clear attribute >go to properties>type-->select visible in uielement definations.

regards

ambica

Message was edited by:

ambica sony