cancel
Showing results for 
Search instead for 
Did you mean: 

Labels in Web Dynpro's

Former Member
0 Kudos
200

Has anybody had any trouble getting labels to display in a view at runtime - I have concluded that this is perhaps a bug, but would like to confirm.  I have checked and rechecked the properties of labels with no luck.

Secondly, I am having a little trouble getting my mind round the API.  How would one get a handle on a label or input at runtime to set it's properties?

Many thanks,

Rowan

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Rowan,

The label can be used like all other UI elements. The ID of the UI element gives you a handle. By using a Cast on the right type you can access and set all properties of this UI element.

Maybe the abstract of the documentation is helpful as well:

Dynamic Modification of a View

Web Dynpro provides the wdDoModifyView Hook method in the controller implementation of the view. The Hook method enables you to overwrite source code at runtime. It allows the application programmer to insert source code, which is used for customizing a Web application, for example. The wdDoModifyView method is called for every view before it is displayed on the screen. All modifications of UI elements that cannot be made using declarative data binding at design time are covered by the Hook method. For example, the Hook method is used if a UI element is to be rendered only at runtime.

/**

  • Hook method called to modify view before rendering. Access to UI elements

  • is via the given view API only!

*/

public void wdDoModifyView(IWDView view)

{

//@@begin wdDoModifyView

//@@end

}

Note that the implementation of the wdDoModifyView method must always be defined between the comment lines //@@begin and //@@end, which is the user coding area. Otherwise, a runtime error occurs.

The interfaces IWDView and IWDViewElement provide the methods required for modifying the UI elements.

· IWDView provides a method for rendering the new UI elements:

IWDButton submitButton = (IWDButton) view.createElement(IWDButton.class, ?submitButton?);

· IWDView provides a method for accessing existing UI elements using the ID:

IWDButton submitButton = (IWDButton) view.getElement(?submitButton?);

By default, a view contains a TransparentContainer UI element, whose ID is RootUIElementContainer. This element is the top UI element in the hierarchy of the UI elements of a view. This condition cannot be changed, modifications can only be defined for the UI element children of this container.

Note that exactly one view is assigned to a UI element. Therefore, it is not possible to separate UI elements from multiple views or transfer them from one view to another.

Former Member
0 Kudos

Hi Karin,

i think, it would be a good idea to generate an (maybe inner) interface class for each view which could be used to identify the view elements, which where created at design time (of course this is not possible for the elements added at runtime). This would increase the maintainability of code significantly.

For example, if i create a view "WorkView" which contains a button "ExitButton" and a checkbox "AdvancedSearch", the framework could generate an interface "IViewElementsWorkView" or inner interface "IPrivateWorkView.IViewElements", containing something like:

public final static String EXIT_BUTTON_ID = "ExitButton";

public final static String ADVANCED_SEARCH_ID = "AdvancedSearch";

...

Then, in the wdDoModifyView method, i could do something like:

if (firstTime) {

  IWDButton exitButton = (IWDButton) view.getElement(IViewElementsWorkView.EXIT_BUTTON_ID);

  IWDCheckBox advSearch = (IWDCheckBox) view.getElement(IViewElementsWorkView.ADVANCED_SEARCH_ID );

}

The compiler will then be able to check, if a view element has been removed or renamed, just like it's possible using the component's messages by the IMessageXXX class. This would be helpful regardless the fact, that the view elements could have been removed or destroyed at runtime.

Best regards,

Stefan

Former Member
0 Kudos

Thanks for the help folks - much appreciated!

-R