cancel
Showing results for 
Search instead for 
Did you mean: 

Focus requesting

Former Member
0 Kudos

Hi All,

I am now having a problem requesting focus on an InputField in a table. The situation is as follows:

I have a table that has a column with a FixedBottomCell containing an InputField. If I click on a button, say a "New" button, I am expecting the cursor and focus to be set on the InputField so that the user can type in the data immediately.

What I did is the following: in wdDoModifyView(), I tried the following code:

input_slName.requestFocus();

which is the single place that requests focus. I tested it, as I click on the button, the focus comes to the input field, but the cursor doesn't, i.e. I have to click on the InputField in order to type in data; and if I set some predefined data in that field, even the focus doesn't come to that field...

After reading the documentation I realized the requestFocus() won't garantee the focus if there are a few calls of this method by different UIElements. But I thought the current visible view should always win --- since other views in the same view assembly are invisible anyway, and most importantly the wdDoModifyView() of each View will be called every request-response cycle no matter the view is visible or not, it makes the focus handling very hard since the invisible views may also require the focus and it doesn't really make sense; as I saw in my App, the behavior is not even consistent -- sometimes it works, sometimes it not.

I want to know if is there a way to know if a View is visible or not -- if not, I can skip the focus request. Or I have to track the visibility information myself?

Best regards,

Ge

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Ge,

Try the following instead of request focus by UI element:

-- remove your "focus-related" code from wdDoModifyView

-- in the action handler(s) add the following:


wdControllerAPI.requestFocus(
wdContext.current<SomeNodeElement>(), 
wdContext.node<SomeNode>().getNodeInfo().getAttribute("AttributeUsedByCellEditor");

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

Hi Valery,

the code solves my problem. Thanks very much!

One more question: why this garantees the focus? I think the event handler is always called before any wdDoModifyView(), does that mean the first call wins?

10 Points rewarded

Best regards,

Ge

Former Member
0 Kudos

Ge,

In fact, action handler is called before wdDoModifyView.

However, the case when several focus requests are made is unspecified in documentation. So this is "unspecified" behavior that should be avoided.

Yet another thing to consider is that table has 2 dimensions and when you are requesting focus just for UI control (cell editor) then it's unclear what row is target. This is true for regular cell editors, but who knows, may be Fixed Cells are affected as well.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Ge,

Do not write the line of code in wdDOModify(),

but in the even handler called by the click of the New button,

<b>Step 1:</b> declare the variable of type IWDInputField

//@@begin others
  static IWDInputField input_slName;
//@@end

<b>Step 2.</b> in wdDoModify()

just take the reference of the input field like:


if(firstTime)
{
   input_slName = (IWDInputField) view.getElement(<field id>);
}

<b>Step 3:</b>in event handler of New Button

input_slName.requestFocus();

Regards

Deepak

Message was edited by:

Deepak Gupta

Former Member
0 Kudos

Deepak,

As it is posted on this forum several hundred times, using static variables leads to dramatic effect in multiuser environment, i.e. hard to find bugs.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

Thanks Deepak, it could be the solution if we can do this consistently throught the application.

Just one unclear point: since according to the specification and other threads in this forum, wdDoModifyView() should be the only place where you can manipulate your UIElements, your suggestion is rather a workaround.

I think maybe the WD team can figure out a better way to handle focus, looking forward to some replies from the team. I think focus handling is an important topic since it makes the end users feel much more comfortable. Thanks in advance!

Btw, points are rewarded, thank you Deepak,

Regards,

Ge

Former Member
0 Kudos

Hi Valery,

the suggestion from Deepak doesn't necessarily require static vars since you can save the button instance in context... But as mentioned in my last post I know it's not recommended to access UI elements outside wdDoModifyView(). The only problem is that the focus handling is then really hard...

Best regards,

Ge

Former Member
0 Kudos

Valery,

Thanks for such an Enthusiastic reply,

Keep it up,

Regards

Deepak