Wiki source code of Programming__WebObjects-Web Applications-Development-Examples-Anchors
Version 1.1 by smmccraw on 2007/07/08 09:45
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | Put the following in the superclass for your components: | ||
| 2 | |||
| 3 | {{panel}} | ||
| 4 | |||
| 5 | private String anchor; | ||
| 6 | |||
| 7 | public void appendToResponse(WOResponse response, WOContext context) { | ||
| 8 | if (anchor != null) { | ||
| 9 | response.setHeader(context.componentActionURL() + "#" + anchor, "location"); | ||
| 10 | response.setHeader("text/html", "content-type"); | ||
| 11 | response.setHeader("0", "content-length"); | ||
| 12 | response.setStatus(302); | ||
| 13 | anchor = null; | ||
| 14 | } else { | ||
| 15 | super.appendToResponse(response, context); | ||
| 16 | } | ||
| 17 | } // appendToResponse | ||
| 18 | |||
| 19 | {{/panel}} | ||
| 20 | |||
| 21 | public String getAnchor() { | ||
| 22 | |||
| 23 | {{panel}} | ||
| 24 | |||
| 25 | return anchor; | ||
| 26 | } | ||
| 27 | |||
| 28 | public void setAnchor(String s) { | ||
| 29 | anchor = s; | ||
| 30 | } | ||
| 31 | |||
| 32 | {{/panel}} | ||
| 33 | |||
| 34 | In the component where we want to use an anchor you just put in | ||
| 35 | |||
| 36 | {{panel}} | ||
| 37 | |||
| 38 | <a name="myanchor"></a> | ||
| 39 | |||
| 40 | {{/panel}} | ||
| 41 | |||
| 42 | and something like the following in the code where we want to jump to this anchor: | ||
| 43 | |||
| 44 | {{panel}} | ||
| 45 | |||
| 46 | protected WOComponent doSometingAndJumpToAnchor() { | ||
| 47 | // do something :) | ||
| 48 | setAnchor("myanchor"); | ||
| 49 | return null; | ||
| 50 | } | ||
| 51 | |||
| 52 | {{/panel}} | ||
| 53 | |||
| 54 | Category:WebObjects |