cancel
Showing results for 
Search instead for 
Did you mean: 

Input Focus in WebDynpro UI Elements

Former Member
0 Kudos

Hi.

I need to set input focus in InputField element, how i can do that?

Best Regards,

Andrey Abramov.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I think i find the reason of this problem. When i click on the tab, this tab get input focus and at the same time the input field request input focus (in <i>wdDoModifyView</i> method), but doesn't get it. How this problem can be solved?

Best Regards, Andrey.

former_member182372
Active Contributor
0 Kudos

Hi Andrey,

try do define action for onSelect event for TabStrip control (just empty action handler - without any code inside).

Regards, Maxim R.

Former Member
0 Kudos

Hi Maksim, thank you for help, it works!

Best Regards, Andrey.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Andrey,

You have to write the code in the embeded view (doModify view method).

Regards, Anil

Former Member
0 Kudos

From Javadoc of interface IWDViewController:

public void requestFocus(IWDAction action)

Requests to change the keyboard input focus to the UI element whose primary purpose is to raise an event bound to the given action. If there is more than one such UI element, then it is undefined which UI element is chosen. It is also undefined which focus request wins if there are several ones. The request may silently fail, but is guaranteed not to throw an exception. UI elements (e.g. table) that trigger events (e.g. "onLeadSelect"), but are not primarily used to do so, are probably considered with lower priority or not at all. As a rule of thumb, if disabling the action disables the whole UI element, then that UI element is primarily used to trigger the event bound to that action. Example: If you have a button whose "onAction" event is bound against the action XYZ and no other UI element event is bound against XYZ, then a wdThis.wdGetAPI().requestFocus(wdThis.wdGetXYZAction()) will focus on that button. Note how this allows to keep controller code independent of the UI, even of IDs used for UI elements. If the button in the example above is later replaced by a LinkToAction or some fancy new icon button that lives inside a tray's header, the code to request focus remains unaffected.

requestFocus

public void requestFocus(IWDNodeElement nodeElement,

IWDAttributeInfo attribute)

Requests to change the keyboard input focus to the UI element whose primary use is to edit a property bound to the given attribute. If there is more than one such UI element, then it is undefined which UI element is chosen. It is also undefined which focus request wins if there are several ones. The request may silently fail, but is guaranteed not to throw an exception. UI elements that are read-only or disabled are not considered at all. To identify a given attribute uniquely at runtime, you must specify the node element to which that attribute belongs. This will e.g. identify a specific cell in a given table row. Example: If you have an input field whose "value" property is bound against the attribute abc of node XYZ of this view called MyView and no other UI element property is bound against XYZ.abc, then the following code will focus on that input field.

IWDAttributeInfo attribute

= wdContext.nodeXYZ().getNodeInfo().getAttribute(

IPrivateMyView.IXYZElement.ABC);

wdThis.wdGetAPI().requestFocus(wdContext.currentXYZElement(), attribute);

Note how this allows to keep controller code independent of the UI, even of IDs used for UI elements. If the input field in the example above is later replaced by a DropDownByKey or some fancy new editor with "guess what I want" value help, the code to request focus remains unaffected.

Armin

former_member182372
Active Contributor
0 Kudos

Hi Andrey,

try this:


  public static void wdDoModifyView(IPrivatePOSearchTemplateNameView wdThis, IPrivatePOSearchTemplateNameView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView
    if (firstTime) {
    	IWDInputField input = (IWDInputField)view.getElement("ifTemplateName");
    	input.requestFocus();
    }
    //@@end
  }

best regards, Maxim R.

Former Member
0 Kudos

Hi Maksim,

I try your code, it doesn't work...

I have a TabStrip with 2 tabs, each one contain a view, when i trigger to target tab, the input field has no focus. Maybe this action doesn't fires <i>wdDoModifyView</i>. I also tryed the <i>requestFocus</i> method with context node and attribute info in <i>wdInit</i> method, it doesn't work to.

Best Regards, Andrey.

Former Member
0 Kudos

Sorry, I don't fully understand what you are saying.

You have a tabstrip with 2 tabs. The input field is where? What means "trigger to target tab"?

Further you are saying "each tab contains a view". What does this mean? Do you have embedded the view of a component?

"This action doesn't fires wdDoModifyView". The method wdDoModifyiew() is not fired by actions. It is called in a certain phase of the request-response cycle by the framework for each visible view.

Can you explain your problem more exactly?

Armin

former_member182372
Active Contributor
0 Kudos

Hi Andrey,

let assume we have container with 2 embedded views (2 tabstrips) - view1 and view2. We have following sequence:

1) first load:

container.wdDoModifyView (firstTime=true)

view1.wdDoModifyView (firstTime=true)

2) click on tab 2:

container.wdDoModifyView (firstTime=false)

view2.wdDoModifyView (firstTime=true)

view1.wdDoModifyView (firstTime=false)

3) click on tab 1 (back to initial):

container.wdDoModifyView (firstTime=false)

view2.wdDoModifyView (firstTime=false)

view1.wdDoModifyView (firstTime=false)

so, if you will remove

if(firstTime)

condition from my first posted code it should work (it works for ).

Regards, Maxim R.

Message was edited by: Maksim Rashchynski

Former Member
0 Kudos

Hi, Armin.

I have a main view with TabStrip component. Each tab of this component contains embedded view, one of this view contains label, input field and button . When i select the tab with this view i want to set focus to the input field component. I implement <i>wdDoModifyView</i> method with following code:

IWDInputField input = (IWDInputField) view.getElement("ElementID");
input.requestFocus();

But it doesn't work.

Best Regards, Andrey.

Former Member
0 Kudos

Yes i try this code without

if (firstTime)

And i have no effect.

I agree, this code should work. It is very strange for me.