Bonjour,
Je commence avec tapestry 5.1 et je n'arrive pas à comprendre la difference entre block et zone.
A quoi servent-ils?
Merci par avance
Version imprimable
Bonjour,
Je commence avec tapestry 5.1 et je n'arrive pas à comprendre la difference entre block et zone.
A quoi servent-ils?
Merci par avance
Ayant eu un peu d'info sur le net, je souhaite afficher ou masquer un div qui sert de cache par dessus la page principale si l'utilisateur est identifié ou non.
Je me sers du layout qui, si je ne trompe pas sert de "template" commun à toutes les pages du site.
Le truc c'est qu'il ne s'affiche pas et que je ne comprends pas pourquoi.
J'utilise tapestry 5.1.0.5
Layout.tml
Layout.javaCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter"> [...] <!-- start cache --> <t:zone t:id="cacheZone"> <t:delegate to="cacheBlock"/> </t:zone> <t:block id="cacheBlock"> <div id="cache" style="width:100%;height:100%;z-index:150;background:#333333;opacity:0.5;filter:alpha(opacity=50);position:absolute;top:0;left:0; "/> </t:block> <!-- end cache --> [...] </html>
La page d'index au cas ou mais j'ai pas de soucis avecCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 /** * Layout component for pages of application test. */ @IncludeStylesheet("context:layout/style.css") @IncludeJavaScriptLibrary("context:javascript/resolution.js") public class Layout { /** The page title, for the <title> element and the <h1> element. */ @Property @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL) private String title; @Property private String menuItem; @Property @Parameter(defaultPrefix = BindingConstants.LITERAL) private Zone cacheZone; @Parameter(defaultPrefix = BindingConstants.LITERAL) private Block cacheBlock; @Inject private ComponentResources resources; public List<String> getMenu() { List<String> liste = new ArrayList<String>(); //ajout du menu ok return liste; } public String getMenuIcone() { //pour afficher les icones du menu ok return ""; } public Block getCacheBlock(){ return cacheBlock; } public void setCacheBlock(Block cacheBlock){ this.cacheBlock = cacheBlock; } }
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 <html t:type="layout" title="Agenda" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter"> <!-- Most of the page content, including <head>, <body>, etc. tags, comes from Layout.tml --> <!-- start sidebar --> <div id="sidebar"> <div>Changement de date</div> <div>Calendrier</div> <t:zone t:id="sharedRes" id="sharedRes"> Shared res </t:zone> </div> <!-- end sidebar --> <!-- start content --> <t:zone t:id="content" id="content" > Content </t:zone> <!-- end content --> </html>
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13 public class Index { @Property @Parameter(defaultPrefix = BindingConstants.LITERAL) private Zone sharedRes; @Property @Parameter(defaultPrefix = BindingConstants.LITERAL) private Zone content; }
Pour ceux que ça intéresse, j'ai trouvé comment faire:
Layout.tml
layout.javaCode:
1
2
3
4
5
6 <t:delegate to="showCache"/> <t:block id="cacheBlock"> <div id="cache" style="width:100%;height:100%;z-index:150;background:#333333;opacity:0.5;filter:alpha(opacity=50);position:absolute;top:0;left:0; "/> </t:block>
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class Layout { /** The page title, for the <title> element and the <h1> element. */ @Property @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL) private String title; @Property private String menuItem; @Inject private Block cacheBlock; @Inject private ComponentResources resources; public List<String> getMenu() { List<String> liste = new ArrayList<String>(); //ajout du menu ok return liste; } public String getMenuIcone() { //pour afficher les icones du menu ok return ""; } public Object getShowCache(){ if (...) return cacheBlock; else return null; } }