You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Coble <Ji...@duke.edu> on 2005/04/21 23:16:55 UTC

Possible to go to named anchor via ActionForward?

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: jim.coble@duke.edu
Voice: 919-660-5974  Fax: 919-660-5923
Box 90198, Duke University
Durham, NC 27708-0198
==================================


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Possible to go to named anchor via ActionForward?

Posted by Joe Germuska <Jo...@Germuska.com>.
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: jim.coble@duke.edu
>Voice: 919-660-5974  Fax: 919-660-5923
>Box 90198, Duke University
>Durham, NC 27708-0198
>==================================
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org


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

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


AW: Possible to go to named anchor via ActionForward?

Posted by Leon Rosenberg <st...@anotheria.net>.
Aehm, 
<script>
document.location.href = document.location.href+'#errors'; 
</script>
At the bottom of your document?

I mean, you should remind yourself, that an anchor in your document has
nothing to do with the forward.
It's like renaming the class file if you need to call method B() of the
object instead of method A().

The jsp always contains the whole html source, an anchor is only a directive
for the browser, where to position it's viewport.
Another possibility is to send a redirect instead of adding a javascript
one-liner (haven't tested this one line, but it should work).

Regards
Leon


> -----Ursprüngliche Nachricht-----
> Von: Jim Coble [mailto:Jim.Coble@duke.edu] 
> Gesendet: Donnerstag, 21. April 2005 23:17
> An: user@struts.apache.org
> Betreff: Possible to go to named anchor via ActionForward?
> 
> 
> 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: jim.coble@duke.edu
> Voice: 919-660-5974  Fax: 919-660-5923
> Box 90198, Duke University
> Durham, NC 27708-0198
> ==================================
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Possible to go to named anchor via ActionForward?

Posted by Je...@bcbstx.com.



Jim, I have used:
<a href="myActionName.do#tabSet">TabTitle</a>
in the jsp succesfully to position action output with anchors.

I have not tried it but possibly something like:
</forward>
<forward name="failure" path="/myfunctionDisplay.do#errors">
</forward>

Hope this helps.

-Jeff


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






------------------------------------------------------------------------------
**********
The information contained in this communication is confidential, private, proprietary, or otherwise privileged and is intended only for the use of the addressee.  Unauthorized use, disclosure, distribution or copying is strictly prohibited and may be unlawful.  If you have received this communication in error, please notify the sender immediately at (312)653-6000 in Illinois; (972)766-6900 in Texas; or (800)835-8699 in New Mexico.
**********
==============================================================================


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org