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