1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.view.facelets.tag.jstl.core; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
|
23 | |
import javax.el.ELException; |
24 | |
import javax.faces.FacesException; |
25 | |
import javax.faces.application.StateManager; |
26 | |
import javax.faces.component.UIComponent; |
27 | |
import javax.faces.event.PhaseId; |
28 | |
import javax.faces.view.facelets.FaceletContext; |
29 | |
import javax.faces.view.facelets.TagAttribute; |
30 | |
import javax.faces.view.facelets.TagConfig; |
31 | |
import javax.faces.view.facelets.TagHandler; |
32 | |
|
33 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletAttribute; |
34 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag; |
35 | |
import org.apache.myfaces.view.facelets.AbstractFaceletContext; |
36 | |
import org.apache.myfaces.view.facelets.FaceletCompositionContext; |
37 | |
import org.apache.myfaces.view.facelets.tag.ComponentContainerHandler; |
38 | |
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
@JSFFaceletTag(name="c:if") |
49 | |
@JSFFaceletAttribute( |
50 | |
name="scope", |
51 | |
className="java.lang.String", |
52 | |
longDescription="Scope for var.") |
53 | |
public final class IfHandler extends TagHandler implements ComponentContainerHandler |
54 | |
{ |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
@JSFFaceletAttribute(className="boolean", required=true) |
61 | |
private final TagAttribute test; |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
@JSFFaceletAttribute(className="java.lang.String") |
69 | |
private final TagAttribute var; |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public IfHandler(TagConfig config) |
75 | |
{ |
76 | 0 | super(config); |
77 | 0 | this.test = this.getRequiredAttribute("test"); |
78 | 0 | this.var = this.getAttribute("var"); |
79 | 0 | } |
80 | |
|
81 | |
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, ELException |
82 | |
{ |
83 | 0 | FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(ctx); |
84 | 0 | AbstractFaceletContext actx = (AbstractFaceletContext) ctx; |
85 | 0 | String uniqueId = actx.generateUniqueFaceletTagId( |
86 | |
fcc.startComponentUniqueIdSection(), tagId); |
87 | 0 | Boolean restoredValue = (Boolean) ComponentSupport.restoreInitialTagState(ctx, fcc, parent, uniqueId); |
88 | 0 | boolean b = false; |
89 | 0 | boolean markInitialState = false; |
90 | |
try |
91 | |
{ |
92 | 0 | if (restoredValue != null) |
93 | |
{ |
94 | 0 | if (!PhaseId.RESTORE_VIEW.equals(ctx.getFacesContext().getCurrentPhaseId())) |
95 | |
{ |
96 | 0 | b = this.test.getBoolean(ctx); |
97 | 0 | if (!restoredValue.equals(b)) |
98 | |
{ |
99 | 0 | markInitialState = true; |
100 | |
} |
101 | |
} |
102 | |
else |
103 | |
{ |
104 | 0 | b = restoredValue; |
105 | |
} |
106 | |
} |
107 | |
else |
108 | |
{ |
109 | |
|
110 | 0 | b = this.test.getBoolean(ctx); |
111 | |
} |
112 | |
|
113 | 0 | if (this.var != null) |
114 | |
{ |
115 | 0 | ctx.setAttribute(var.getValue(ctx), Boolean.valueOf(b)); |
116 | |
} |
117 | 0 | if (b) |
118 | |
{ |
119 | 0 | boolean oldMarkInitialState = false; |
120 | 0 | Boolean isBuildingInitialState = null; |
121 | |
try |
122 | |
{ |
123 | 0 | if (markInitialState) |
124 | |
{ |
125 | |
|
126 | 0 | oldMarkInitialState = fcc.isMarkInitialState(); |
127 | 0 | fcc.setMarkInitialState(true); |
128 | 0 | isBuildingInitialState = (Boolean) ctx.getFacesContext().getAttributes().put( |
129 | |
StateManager.IS_BUILDING_INITIAL_STATE, Boolean.TRUE); |
130 | |
} |
131 | 0 | this.nextHandler.apply(ctx, parent); |
132 | |
} |
133 | |
finally |
134 | |
{ |
135 | 0 | if (markInitialState) |
136 | |
{ |
137 | |
|
138 | 0 | if (isBuildingInitialState == null) |
139 | |
{ |
140 | 0 | ctx.getFacesContext().getAttributes().remove( |
141 | |
StateManager.IS_BUILDING_INITIAL_STATE); |
142 | |
} |
143 | |
else |
144 | |
{ |
145 | 0 | ctx.getFacesContext().getAttributes().put( |
146 | |
StateManager.IS_BUILDING_INITIAL_STATE, isBuildingInitialState); |
147 | |
} |
148 | 0 | fcc.setMarkInitialState(oldMarkInitialState); |
149 | |
} |
150 | |
} |
151 | |
} |
152 | |
} |
153 | |
finally |
154 | |
{ |
155 | 0 | fcc.endComponentUniqueIdSection(); |
156 | 0 | } |
157 | |
|
158 | 0 | ComponentSupport.saveInitialTagState(ctx, fcc, parent, uniqueId, b); |
159 | 0 | if (fcc.isUsingPSSOnThisView() && fcc.isRefreshTransientBuildOnPSS() && !fcc.isRefreshingTransientBuild()) |
160 | |
{ |
161 | |
|
162 | 0 | ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent); |
163 | |
} |
164 | 0 | if (fcc.isDynamicComponentSection()) |
165 | |
{ |
166 | 0 | ComponentSupport.markComponentToRefreshDynamically(ctx.getFacesContext(), parent); |
167 | |
} |
168 | 0 | } |
169 | |
} |