The only thing that occurs to me is: are anchors guaranteed to be at the end of the URL? I.e. is this valid: http://.../myAction.do#anchor?query=...

Come to think of it, it may not make any difference; is the 'name' argument to findForward pre-processed to strip request parameters?

L.

Frank W. Zammetti wrote:

Moved to the dev list, I think it's more appropriate there now...

Hmm... interesting... seems like there might be more than one related
issue here.

Trying to tackle just the issue of being able to do in an Action:

mapping.findForward("myForward#myAnchor");

I can't seem to check out from SVN from my current location, so I can't
test any of this... here's what I *think* could be done to allow this
though...

(1) In ActionMapping, change the findForward() method to this:

  public ActionForward findForward(String name) {
    String anchor = "";
    int hashLoc = name.indexOf("#");
    if (name != null && hashLoc != -1) {
      anchor = name.substring(hashLoc, name.length());
      name = name.substring(0, hashLoc);
    }
    ForwardConfig config = findForwardConfig(name);
    if (config == null) {
      config = getModuleConfig().findForwardConfig(name);
    }
    if (config == null) {
      if (log.isWarnEnabled()) {
        log.warn("Unable to find '" + name + "' forward.");
      }
    }
    ActionForward af = null;
    if (config != null) {
      ActionForward af = new ActionForward((ActionForward)config);
      if (name != null}{
        af.setAnchor(anchor);
      }
    }
    return af;
  }

(2) In RequestProcessor, right before the line:

  if (forward.getRedirect()) {

... in the processForwardConfig() method, add:

  uri += ((ActionForward)forward).getAnchor();

(3) In ActionForward, add the following:

  private String anchor;
  public void setAnchor(String anchor) {
    this.anchor = anchor;
  }
  public String getAnchor() {
    return this.anchor;
  }

Quick explanation:

In ActionMapping.findForward(), we check if there is a hash mark in the
requested forward name.  If there is we grab everything to the right of
it, which is the named anchor, and we set the name to everything to the
left of it, which is the forward name.  The forward should then be found
correctly.

Then, we essentially make a clone of the ForwardConfig we found so that we
can call setAnchor() on it without affecting anything outside the current
request (ForwardConfigs are shared and generally immutable after
creation).

Lastly, in RequestProcessor, we tack the anchor on to the URI before
forwarding or redirecting.  If there was no anchor, no harm is done.

Can anyone check me on this?  Does it look reasonable?  If anyone could
even test-compile, that'd be fantastic, otherwise I'll do it when I get
home and have access.  I'll submit the patch tonight unless anyone sees an
insurmountable problem that I've missed.



--
Laurie, Open Source advocate, Java geek and novice blogger:
http://www.holoweb.net/laurie


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

Reply via email to