Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
PageClientPropertyPersistenceScope |
|
| 1.6666666666666667;1.667 |
1 | // Copyright 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | ||
15 | package org.apache.tapestry.record; |
|
16 | ||
17 | import org.apache.tapestry.IPage; |
|
18 | import org.apache.tapestry.IRequestCycle; |
|
19 | import org.apache.tapestry.engine.ServiceEncoding; |
|
20 | ||
21 | /** |
|
22 | * Defines the 'page' scope for persisting client properties. Persist the properties only if the |
|
23 | * current page name is the same as that of the property. |
|
24 | * |
|
25 | * @author Mindbridge |
|
26 | * @since 4.0 |
|
27 | * @see org.apache.tapestry.record.ClientPropertyPersistenceScope |
|
28 | */ |
|
29 | public class PageClientPropertyPersistenceScope extends |
|
30 | AbstractPrefixedClientPropertyPersistenceScope |
|
31 | { |
|
32 | private IRequestCycle _requestCycle; |
|
33 | ||
34 | public PageClientPropertyPersistenceScope() |
|
35 | { |
|
36 | 7 | super("state:"); |
37 | 7 | } |
38 | ||
39 | /** |
|
40 | * Returns true if the active page name matches the page for this property. This means that |
|
41 | * <em>after a new page has been activated</em>, the state is discarded. |
|
42 | */ |
|
43 | ||
44 | public boolean shouldEncodeState(ServiceEncoding encoding, String pageName, |
|
45 | PersistentPropertyData data) |
|
46 | { |
|
47 | 5 | IPage page = _requestCycle.getPage(); |
48 | ||
49 | // TAPESTRY-701: if you try to generate a link using, say, page or external service, |
|
50 | // from inside PageValidateListener.pageValidate(), then there may not be an active |
|
51 | // page yet. Seems like the right thing to do is hold onto any properties until |
|
52 | // we know what the active page is. I know this one is going to cause a fight |
|
53 | // since its not clear whether keeping or discarding is the right way to go. |
|
54 | ||
55 | 5 | if (page == null) |
56 | 1 | return true; |
57 | ||
58 | 4 | return pageName.equals(page.getPageName()); |
59 | } |
|
60 | ||
61 | public void setRequestCycle(IRequestCycle requestCycle) |
|
62 | { |
|
63 | 4 | _requestCycle = requestCycle; |
64 | 4 | } |
65 | ||
66 | } |