cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically Retrieving the names of the elements in a view

josh_close
Discoverer
0 Kudos

Hello,

I am trying to retrieve the names of all the user elements in a view at runtime within the wdDoModifyView method of that view. Does anyone have suggestions on how to accomplish this?

Thanks

Josh

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi...

if want to retrieve element name from view then you have to some piece of code has to follow..

view==it is available in your doModifyview as parameter

public static void wdDoModifyView(IPrivateChildView wdThis, IPrivateChildView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

IWDViewElement ele=(IWDViewElement)view.getElement("id");

IWDInputField elin=(IWDInputField)view.getElement("id of i put");

IWDDropDownByKey dr=(IWDDropDownByKey)view.getElement("id of drop down");

//if get element any othe method...

view=view;

}

if you want to declare any other method you have to asign view parameter to gobal declarartion

like--- static IWDview view=null

just start search with IWD....(elementname)//you will get element name...

Thanks

Sjati

josh_close
Discoverer
0 Kudos

Hello,

Thank you for your answers. Here is what I am trying to do. I need to look through a view and enable and disable elements based upon permissions I have from a backend source. Rather than binding each elements enabled property to a context on everyview and setting it that way, it would be more effecient to do it programmatically and bind this property at run time. Does anyone have any sample code on how do to the reflection? Unfortunatly I do not have the book readily available.

Josh

pravesh_verma
Active Contributor
0 Kudos

Hi Josh,

If you have to do it dynamically at runtime, then you have to anyways access the UI element object.

There is no other alternative. And if you are accessing the Ui element then you can use this code:


//For  Input field
((IWDInputField)view.getElement("InputField_ID")).setEnabled(true);

// For Table
((IWDTable)view.getElement("Table_ID")).setEnabled(true);

// For CheckBoxes
((IWDCheckBox)view.getElement("CheckBox_ID")).setEnabled(true);

// For TextView
((IWDTextView)view.getElement("TextView_ID")).setEnabled(true);

Similarly you can do it for otehr UI elements. If you want any other help please let me know.

Thanks and Regards

Pravesh

Former Member
0 Kudos

Why would it "more effecient to do it programmatically and bind this property at run time."?

Armin

Former Member
0 Kudos

What is the use case?

In Chris Whealy's book "Inside Web Dynpro for Java" you can find an algorithm to traverse any UI element hierarchy using reflection.

Armin

former_member185086
Active Contributor
0 Kudos

Hi Josh

Please clear it what u want to retrieve : UI Element or All Logged in User ?

As definition of the weDoModify Hook Method

This method conceptually belongs to the view itself, not to the

* controller (cf. MVC pattern). The Web Dynpro programming model recommends that UI elements can only be accessed by code executed within the call to this hook method.

	 * 
	 * @param view
	 *            The view's generic API, as provided by Web Dynpro. Provides
	 *            access to UI elements.
	 * @param firstTime
	 *            Indicates whether the hook is called for the first time during
	 *            the lifetime of the view.
	 */

So this method is good for Dynamic generation of the UI Element and binding of the class to the context which is there for complete life cycle like TableSorter and TableFilter.

What u want to achieve? Explain the scenario .

Best Regards

Satish Kumar

pravesh_verma
Active Contributor
0 Kudos

Hi Josh,

You can use following code for getting the arraylist of all Ui elements under the parent UI container.


IWDUIElement[] uiElementList = ((IWDTransparentContainer)view.getElement("RootElement")).getChildren();

Please note that I have used "RootElement". Here by default the Root UI element will have this name.

However If you change the name of the root UI element then you have to use that particular name of Root UI Transparent container in this code snippet.

I hope this will solve your issue. Please revert back if you have any issues.

Thanks and Regards,

Pravesh