Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Struts Wiki" for change 
notification.

The following page has been changed by FrankZammetti:
http://wiki.apache.org/struts/StrutsSolutions

------------------------------------------------------------------------------
  
  7. A plug & play solution to adding a "please wait" page to any Struts 
action: [StrutsPleaseWait]
  
+ 8. How do I include an anchor name when forwarding from an Action? (i.e., how 
can I make the page returned to the browser jump to a specific section out of 
an Action?)
+ 
  == DISCUSSION OF PROBLEMS (What Is The Problem?) ==
  
  4. In an application I was architect and lead developer for last year, I was 
asked to expose certain pieces of functionality of the system as Web Services.  
This request was made AFTER the application was complete and deployed in 
production.  I did not want to spend a lot of time on this (in fact, COULDN'T) 
and wanted to change as little code as possible, ideally none.
  
  5. I've seen this question asked numerous times on the Struts User's mailing 
list, so I thought an entry somewhere on the Wiki might be a good idea.  The 
question is usually asked something like "How can I open a new window from an 
Action?"  It's a little vague, but it's along the lines of how can you submit a 
form and have the response appear in a new window.  Usually it's asked within 
the context of doing it variably, that is, sometimes returning in a new window, 
sometimes not.
+ 
+ 8. If you name an anchor in your page (<a name="something">) and you want the 
browser to jump to that specific anchor when it is rendered, you would 
generally do something like <a href="mypage.htm#something"> if you were doing 
it from a link.  Or, from a servlet, you might attach #something to the end of 
the page name when using a dispatcher to forward.  If you try to append 
#something to the end of a forward name from an Action though (return 
mapping.findForward("myForward#something");) you will find that Struts throws 
an exception about not being able to find the forward.  That is because it is 
looking for a forward that is literally "myForward#something" and won't find it.
  
  == DISCUSSION OF SOLUTIONS (What Is The Solution?) ==
  
@@ -150, +154 @@

  
  The bottom-line here is this: There is no way to direct the browser to open 
the response in a new window from an Action.  You either have to indicate you 
want this behavior when the form is submitted, or make it happen with scripting 
once the response is back at the browser.  At least, this is true within the 
confines of plain old HTML... You could always pull an applet out and do 
something like this!
  
+ 8. In theory at least (can someone verify this, I'm being lazy!) you could 
actually name your forward "myForward#something", and it should work.  However, 
this ties your page design a little too much to your Struts config, and that's 
probably not a good idea.  The better solution is to use a little snippet of 
Javascript on the client like so:
+ 
+ {{{
+ <head>
+ <script>
+   function jumpToAnchor() {
+     <% if (request.getAttribute("hash") != null) { %>
+       location.hash = "<%=request.getAttribute("hash")%>";
+     <% } %>
+   }
+ </script>
+ </head>
+ <body onLoad="jumpToAnchor();">
+ }}}
+ 
+ Then, all you need to do is add an attribute named "hash" to the request 
right before you return the forward from your Action.  The value of the 
attribute is simply the name of the anchor you wish to jump to.  Voila, all set!
+ 
  = THE END =
  

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

Reply via email to