|
|
Re: How to set the focus on a specific field? [message #939128 is a reply to message #932602] |
Wed, 10 October 2012 13:00 |
|
A. Del. wrote on Thu, 04 October 2012 04:59Is there a way to set the focus on a specific field?
For instance, when a validation returns an error, I would like to set the focus on the field the user has to correct, so the user could start typing right away.
Check out the method AbstractForm.validateForm(). There is already code that displays an error message when a field is invalid and sets the focus to the first field with a validation error. Use the various execValidate... methods to throw a VetoException or use setErrorStatus() to set a processing status. Maybe this mechanism could help you in your application.
Beat
|
|
|
|
Re: How to set the focus on a specific field? [message #947640 is a reply to message #947588] |
Wed, 17 October 2012 09:19 |
|
A. Del. wrote on Wed, 17 October 2012 04:13I tried to use the method requestFocus() on IFormField. Sometimes it works and somtimes it doesn't.
Like the name states, the method requestFocus() does not _set_ the focus. It's a _request_ to the UI layer to set the focus. This request may be denied or ignored by the UI layer for several reasons. The field has to be ready and visible on screen. Or, for example, while a message box is shown, the focus cannot be set to a field on a dialog in the background.
The Scout UI layer delegates the request to the underlying UI field (e.g. a JTextField in Swing). Note that this does still not guarantee that the focus is now on the desired field, because the UI itself may deny the request for some reason.
If the behaviour is "random", then you see to have run into a race condition (sometimes the UI is ready, sometimes it's not). Try to synchronize your focus request, e.g. by wrapping it into a ClientSyncJob.
Regards,
Beat
|
|
|
|
Re: How to set the focus on a specific field? [message #948057 is a reply to message #948044] |
Wed, 17 October 2012 18:12 |
|
A. Del. wrote on Wed, 17 October 2012 13:54In my code the method requestFocus() doesn't work on fields of type AbstractIntegerField.
But it works for AbstractStringField or also AbstractSmartField (I use the swt ui.)
Could this be a bug or am I missing something?
This is a bug, indeed! I could reproduce the problem exactly as you describe it.
A short analysis showed that it is a SWT only problem. While string fields are rendered als "StyledTextEx" components, integer fields are rendered as "TextEx" components. The class TextEx overrides the method requestFocus() like this:
@Override
public boolean setFocus() {
return getEditable();
}
This does not seem correct to me, so I would encourage you to file a bug (https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Scout).
Thank you very much for reporting the issue!
Regards,
Beat
|
|
|
|
Powered by
FUDForum. Page generated in 0.03679 seconds