I tried this and it does not work. The error and the code follows if
you care to comment...
ERROR FOLLOWS
_0002findex_0002ejspindex_jsp_21.java [175:1] cannot resolve symbol
symbol : variable logonForm
location: class _0002findex_0002ejspindex_jsp_21
_jspx_th_html_form_0.setFocus( logonForm.getFocus() );
^
1 error
Errors compiling index.
CODE FOLLOWS
<%@page contentType="text/html"%>
<%@ taglib uri="/WEB-INF/tld/struts/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tld/struts/struts-bean.tld" prefix="bean" %>
END OF CODE
Thanks. - Dan
-Original Message-
From: AWong [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 16, 2001 4:04 PM
To: struts-user
Cc: AWong
Subject: RE: Setting focus on field with error
Struts' html:form tag takes in an optional "focus" property. If
specified, Struts will generate the neccessary javascript to set the
focus on the specified element.
So, one possibility might be to add a focus attribute to your formbeans
which would allow you to do the following:
Adding the focus property can still be considered consistent with the
responsibilty of the form bean -- to represent html form input, we're
just expanding it to include setting up that form too (in this case
which html input gets the focus on that particular form).
Another way to look at it is, if the jsp page needs to know which form
input needs the focus, which object has that information? In this case,
Actionform seems like the best candidate. It knows which input faile
validation and therefore needs to have the focus set on it.
-Original Message-
From: Assenza, Chris [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 16, 2001 1:21 PM
To: '[EMAIL PROTECTED]'
Subject: RE: Setting focus on field with error
I've just been asked to do the same exact thing in our app (what a
coincidence!!) but I haven't determined exactly what do yet. In our
app,
ActionErrors are added by the name of the form field that had the error
(ie.
field1 is the ActionErrors property and also the html:text property on
the
JSP).
I'm thinking that we can expose the ActionErrors object to the front-end
and
use the messages HashMap or methods inherited from ActionMessages to
identify a property and then use JavaScript to set the focus on that
property. This can probably be done pretty cleanly with a taglib.
Again, this is just speculation on my part and I need to do a lot of
research into ActionErrors and Messages because I haven't dug into the
API
much for them, having had no need to until now. Let me know what you
find
out! :)
Chris
Christopher Assenza
Phone: 412.201.6026
Fax: 412.201.6060
Email: [EMAIL PROTECTED]
ACCESSDATA
Moving Your Business from Point A to Point e.SM
http://www.accessdc.com/
-Original Message-
From: Troy Hart [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 16, 2001 3:56 PM
To: [EMAIL PROTECTED]
Subject: Re: Setting focus on field with error
I could be wrong but I can't think of anything that would be very
convenient.
The only way I could imagine doing it (and I'm not sure it would even
work)
would be to invoke a javascript function every time the page loads. You
could
add a bean with the data needed by the javascript to the request, from
your
action class. NOTE: this would require you to forgo the automatic form
validation and instead trigger validation from your action class. This
is
the
only way to get the bean I talked about into the request (as a request
attribute that is).
Troy
On Thursday 16 August 2001 11:03 am, you wrote:
> Is their a nifty way to have the focus automagically go to the field
with
> the error, on an input form? For example, if I have a form with an
> 'amount' field, and the user enters an invalid amount, causing my
Action
to
> return an appropriate error, keyed in the ActionErrors container with
the
> 'amount' property, is there a slick way to have the focus set to that
field
> on the form? I know how to have the error message display next to the
> offending field, but having the focus go there also would be nice.
>
> Thanks!
>
> Steve Molitor
> [EMAIL PROTECTED]