A few weeks ago, Ted Husted posted the following:
> BTW, I have found that the Javascript generated here does not seem to
> work well with Netscape 4.7 (Windows). It focusses on the field at
> first, but jumps to the browser's "Address" field when you press tab.
> For this browser/platform, it does work correctly when put into the
> <body> tag -- onload="document.logonForm.username.focus();"
I've just run into this as well and I was wondering whether anyone has
come up with a good way to have Struts handle this automatically. I
would ideally prefer to not have to directly include the name of a form
on the page, when it's only defined in an external file
(struts-config.xml). Also, in my current project, we use a single
template for all the pages, and the <body> tag is in the template, so we
can't just name a specific form field in the <body> tag.
What I've come up with (just experimental) is to have onload call an
"initPage" function, which is defined as appropriate in each file that
invokes the template. (That would also allow me to later define some
standard functionality in the template file and still invoke the
page-specific stuff before or after.) If the function is not defined,
nothing happens. (It would work the same without the templates, of
course.)
This function can be defined anywhere on the page, so the <html:form>
tag could generate this function (probably named something less generic,
like "strutsFormSetFocus") instead of the immediate focus call, which
Navigator 4 doesn't like. (F*%^@!# Netscape! :-( ) Even if someone were
to define two forms with focus attributes, it is safe to have more than
one definition of this function. (I don't know enough about JavaScript
to know if this is defined behaviour that can be counted upon or not,
but it appears that JavaScript simply uses the last instance of the
function.)
Unfortunately, the generation of the onload attribute in the <body> tag
is not automatic; maybe a Struts <html:body> tag could take care of it.
I suspect that some will object to having the framework generate more
code, and maybe this isn't a candidate for inclusion, but unfortunately
I see no other solution for those of us who can't realistically outcast
NN4 users. If anyone has any other suggestions, though, I'd love to hear
them.
--
Michael Hackett
Developer, Pictorius Inc.