Wiki source code of Development-Examples-Anchors
Last modified by Pascal Robert on 2010/09/13 00:31
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | Put the following in the superclass for your components: | ||
2 | |||
3 | {{code}} | ||
4 | |||
5 | private String anchor; | ||
6 | |||
7 | public void appendToResponse(WOResponse response, WOContext context) { | ||
8 | |||
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 | ||
19 | |||
20 | public String getAnchor() { | ||
21 | return anchor; | ||
22 | } | ||
23 | public void setAnchor(String s) { | ||
24 | anchor = s; | ||
25 | } | ||
26 | |||
27 | |||
28 | {{/code}} | ||
29 | |||
30 | In the component where we want to use an anchor you just put in | ||
31 | |||
32 | {{code}} | ||
33 | |||
34 | <a name="myanchor"></a> | ||
35 | |||
36 | {{/code}} | ||
37 | |||
38 | and something like the following in the code where we want to jump to this anchor: | ||
39 | |||
40 | {{code}} | ||
41 | |||
42 | protected WOComponent doSometingAndJumpToAnchor() { | ||
43 | // do something :) | ||
44 | setAnchor("myanchor"); | ||
45 | return null; | ||
46 | } | ||
47 | |||
48 | {{/code}} |