WebObjects/Web Applications/Development/Examples/Anchors

From Wikibooks, open books for an open world
< WebObjects
Jump to navigation Jump to search

Put the following in the superclass for your components:

  private String anchor;
  public void appendToResponse(WOResponse response, WOContext context) {
     if (anchor != null) {
        response.setHeader(context.componentActionURL() + "#" + anchor, "location");
        response.setHeader("text/html", "content-type");
        response.setHeader("0", "content-length");
        anchor = null;
     } else {
        super.appendToResponse(response, context);
   } // appendToResponse
   public String getAnchor() {
       return anchor;
   public void setAnchor(String s) {
       anchor = s;

In the component where we want to use an anchor you just put in

 <a name="myanchor"></a>

and something like the following in the code where we want to jump to this anchor:

  protected WOComponent doSometingAndJumpToAnchor() {
     // do something :)
     return null;