If you are returning a "redirecting" action forward, it shoul be no problem to append an anchor -- but if your ActionForward results in a RequestDispatcher forward (as in the default case), then the anchor would probably cause the dispatcher to choke.

The problem is that errors are normally saved in request scope, and a redirect would cause a new request scope to be created.

It is now possible to save errors to session scope, but I don't think anyone has done anything so that you could rig up the framework to do the validation for you and have that happen. But if you move the validation into your action, I think you can get where you're trying to go.

Another thing you might try would be to do it on the client side:


<logic:messagesPresent >
<a name="errors">You have errors</a> <br>
<html:messages id="msg"><div class="error"><c:out value="${msg}" /></div></html:messages>
</logic:messagesPresent >


and then way down at the bottom of your page...
<logic:messagesPresent >
<script>
        location.hash='errors';
</script>
</logic:messagesPresent >

(I've never actually used location.hash, but a quick check of the JS/DHTML cookbook suggests that its the right syntax. Note that you are explicitly intended to leave out the "#" mark in the value to location.hash.)

Joe

At 5:16 PM -0400 4/21/05, Jim Coble wrote:
I have a JSP page in my application that consists of several lines of
explanatory text (a screen's worth or so) followed by a form.  When the
user submits the form, the ActionForm validate method is called and, if
there are errors, the user is returned to the same JSP page where
html:errors displays the relevant error messages between the initial
explanatory text and the beginning of the form.  All this works fine.
However, when the JSP page redisplays in this validation error scenario,
I'd like the browser page to jump to the error messages.

Here is what I tried that did not work.
Within the JSP page ...
<a name="errors"><html:errors/></a>
In struts-config action mapping, for the "input" attribute of the "action"
element ...
input="/flts/reservationlab.jsp#errors"

When I submit the form with a required field missing, I get ...
The requested resource (/flts/reservationlab.jsp#errors) is not available.

Is there any way I can set up an action mapping so that, if control is
redirected back to the "input" JSP page, I can make it so that the browser
jumps to a named anchor tag ("errors" in this particular case)?

Thanks.
--Jim

==================================
Jim Coble
Senior Technology Specialist
Center for Instructional Technology
Email: [EMAIL PROTECTED]
Voice: 919-660-5974  Fax: 919-660-5923
Box 90198, Duke University
Durham, NC 27708-0198
==================================


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--
Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "Narrow minds are weapons made for mass destruction" -The Ex


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to