Skip to content

Commit 337706e

Browse files
committed
primefaces#3058 clenaup deprecated methods
1 parent d11d66f commit 337706e

File tree

6 files changed

+69
-513
lines changed

6 files changed

+69
-513
lines changed

src/main/java/org/primefaces/component/tree/TreeRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import javax.faces.component.UINamingContainer;
2828
import javax.faces.context.FacesContext;
2929
import javax.faces.context.ResponseWriter;
30+
import org.primefaces.PrimeFaces;
3031
import org.primefaces.component.api.UITree;
31-
import org.primefaces.context.RequestContext;
3232

3333
import org.primefaces.model.TreeNode;
3434
import org.primefaces.model.filter.FilterConstraint;
@@ -120,7 +120,7 @@ public void decodeSelection(FacesContext context, Tree tree) {
120120
}
121121
}
122122

123-
RequestContext.getCurrentInstance(context).addCallbackParam("descendantRowKeys", sb.toString());
123+
PrimeFaces.current().ajax().addCallbackParam("descendantRowKeys", sb.toString());
124124
sb.setLength(0);
125125
descendantRowKeys = null;
126126
}

src/main/java/org/primefaces/context/DefaultRequestContext.java

Lines changed: 16 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.lang.reflect.Method;
1919
import java.util.ArrayList;
20-
import java.util.Collection;
2120
import java.util.HashMap;
2221
import java.util.List;
2322
import java.util.Map;
@@ -26,24 +25,12 @@
2625
import javax.el.ELContext;
2726
import javax.el.ExpressionFactory;
2827
import javax.el.ValueExpression;
29-
import javax.faces.application.FacesMessage;
30-
import javax.faces.application.ProjectStage;
31-
import javax.faces.component.UIComponent;
32-
import javax.faces.component.UIViewRoot;
33-
import javax.faces.component.visit.VisitContext;
3428
import javax.faces.context.FacesContext;
3529
import javax.servlet.http.HttpServletRequest;
36-
import org.primefaces.component.datatable.TableState;
37-
import org.primefaces.expression.ComponentNotFoundException;
38-
39-
import org.primefaces.expression.SearchExpressionFacade;
4030
import org.primefaces.util.AjaxRequestBuilder;
4131
import org.primefaces.util.CSVBuilder;
42-
import org.primefaces.util.ComponentUtils;
4332
import org.primefaces.util.Constants;
44-
import org.primefaces.util.StringEncrypter;
4533
import org.primefaces.util.WidgetBuilder;
46-
import org.primefaces.visit.ResetInputVisitCallback;
4734

4835
public class DefaultRequestContext extends RequestContext {
4936

@@ -56,7 +43,6 @@ public class DefaultRequestContext extends RequestContext {
5643
private AjaxRequestBuilder ajaxRequestBuilder;
5744
private CSVBuilder csvBuilder;
5845
private FacesContext context;
59-
private StringEncrypter encrypter;
6046
private ApplicationContext applicationContext;
6147
private Boolean ignoreAutoUpdate;
6248
private Boolean rtl;
@@ -65,37 +51,32 @@ public DefaultRequestContext(FacesContext context) {
6551
this.context = context;
6652
}
6753

68-
@Override
69-
public boolean isAjaxRequest() {
70-
return context.getPartialViewContext().isAjaxRequest();
71-
}
72-
73-
@Override
74-
public void addCallbackParam(String name, Object value) {
75-
getCallbackParams().put(name, value);
76-
}
77-
78-
@Override
79-
public void execute(String script) {
80-
getScriptsToExecute().add(script);
81-
}
82-
8354
@Override
8455
@SuppressWarnings("unchecked")
8556
public Map<String, Object> getCallbackParams() {
86-
if (getAttributes().get(CALLBACK_PARAMS_KEY) == null) {
87-
getAttributes().put(CALLBACK_PARAMS_KEY, new HashMap<String, Object>());
57+
Map<String, Object> callbackParams =
58+
(Map<String, Object>) context.getAttributes().get(CALLBACK_PARAMS_KEY);
59+
60+
if (callbackParams == null) {
61+
callbackParams = new HashMap<String, Object>();
62+
context.getAttributes().put(CALLBACK_PARAMS_KEY, callbackParams);
8863
}
89-
return (Map<String, Object>) getAttributes().get(CALLBACK_PARAMS_KEY);
64+
65+
return callbackParams;
9066
}
9167

9268
@Override
9369
@SuppressWarnings("unchecked")
9470
public List<String> getScriptsToExecute() {
95-
if (getAttributes().get(EXECUTE_SCRIPT_KEY) == null) {
96-
getAttributes().put(EXECUTE_SCRIPT_KEY, new ArrayList<String>());
71+
List<String> scriptsToExecute =
72+
(List<String>) context.getAttributes().get(EXECUTE_SCRIPT_KEY);
73+
74+
if (scriptsToExecute == null) {
75+
scriptsToExecute = new ArrayList<String>();
76+
context.getAttributes().put(EXECUTE_SCRIPT_KEY, scriptsToExecute);
9777
}
98-
return (List<String>) getAttributes().get(EXECUTE_SCRIPT_KEY);
78+
79+
return scriptsToExecute;
9980
}
10081

10182
@Override
@@ -125,141 +106,12 @@ public CSVBuilder getCSVBuilder() {
125106
return csvBuilder;
126107
}
127108

128-
@Override
129-
public void scrollTo(String clientId) {
130-
this.execute("PrimeFaces.scrollTo('" + clientId + "');");
131-
}
132-
133-
@Override
134-
public void update(String clientId) {
135-
// call SEF to validate if a component with the clientId exists
136-
if (context.isProjectStage(ProjectStage.Development)) {
137-
try {
138-
SearchExpressionFacade.resolveClientId(context, context.getViewRoot(), clientId);
139-
}
140-
catch (ComponentNotFoundException e) {
141-
LOG.severe(e.getMessage());
142-
}
143-
}
144-
145-
context.getPartialViewContext().getRenderIds().add(clientId);
146-
}
147-
148-
@Override
149-
public void update(Collection<String> clientIds) {
150-
151-
// call SEF to validate if a component with the clientId exists
152-
if (context.isProjectStage(ProjectStage.Development)) {
153-
if (clientIds != null) {
154-
for (String clientId : clientIds) {
155-
try {
156-
SearchExpressionFacade.resolveClientId(context, context.getViewRoot(), clientId);
157-
}
158-
catch (ComponentNotFoundException e) {
159-
LOG.severe(e.getMessage());
160-
}
161-
}
162-
}
163-
}
164-
165-
context.getPartialViewContext().getRenderIds().addAll(clientIds);
166-
}
167-
168-
@Override
169-
public void reset(Collection<String> expressions) {
170-
VisitContext visitContext = VisitContext.createVisitContext(context, null, ComponentUtils.VISIT_HINTS_SKIP_UNRENDERED);
171-
172-
for (String expression : expressions) {
173-
reset(visitContext, expression);
174-
}
175-
}
176-
177-
@Override
178-
public void reset(String... expressions) {
179-
if (expressions == null) {
180-
return;
181-
}
182-
183-
VisitContext visitContext = VisitContext.createVisitContext(context, null, ComponentUtils.VISIT_HINTS_SKIP_UNRENDERED);
184-
185-
for (String expression : expressions) {
186-
reset(visitContext, expression);
187-
}
188-
}
189-
190-
@Override
191-
public void reset(String expressions) {
192-
VisitContext visitContext = VisitContext.createVisitContext(context, null, ComponentUtils.VISIT_HINTS_SKIP_UNRENDERED);
193-
194-
reset(visitContext, expressions);
195-
}
196-
197-
private void reset(VisitContext visitContext, String expressions) {
198-
UIViewRoot root = context.getViewRoot();
199-
200-
List<UIComponent> components = SearchExpressionFacade.resolveComponents(context, root, expressions);
201-
for (UIComponent component : components) {
202-
component.visitTree(visitContext, ResetInputVisitCallback.INSTANCE);
203-
}
204-
}
205-
206-
@Override
207-
public void openDialog(String outcome) {
208-
context.getAttributes().put(Constants.DIALOG_FRAMEWORK.OUTCOME, outcome);
209-
}
210-
211-
@Override
212-
public void openDialog(String outcome, Map<String, Object> options, Map<String, List<String>> params) {
213-
context.getAttributes().put(Constants.DIALOG_FRAMEWORK.OUTCOME, outcome);
214-
215-
if (options != null) {
216-
context.getAttributes().put(Constants.DIALOG_FRAMEWORK.OPTIONS, options);
217-
}
218-
219-
if (params != null) {
220-
context.getAttributes().put(Constants.DIALOG_FRAMEWORK.PARAMS, params);
221-
}
222-
}
223-
224-
@Override
225-
public void closeDialog(Object data) {
226-
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
227-
String pfdlgcid = params.get(Constants.DIALOG_FRAMEWORK.CONVERSATION_PARAM);
228-
229-
if (data != null) {
230-
Map<String, Object> session = context.getExternalContext().getSessionMap();
231-
session.put(pfdlgcid, data);
232-
}
233-
234-
this.execute("PrimeFaces.closeDialog({pfdlgcid:'" + pfdlgcid + "'});");
235-
}
236-
237-
@Override
238-
public void showMessageInDialog(FacesMessage message) {
239-
240-
String summary = ComponentUtils.escapeText(message.getSummary());
241-
summary = ComponentUtils.replaceNewLineWithHtml(summary);
242-
243-
String detail = ComponentUtils.escapeText(message.getDetail());
244-
detail = ComponentUtils.replaceNewLineWithHtml(detail);
245-
246-
this.execute("PrimeFaces.showMessageInDialog({severity:\"" + message.getSeverity()
247-
+ "\",summary:\"" + summary
248-
+ "\",detail:\"" + detail + "\"});");
249-
}
250-
251109
@Override
252110
public void release() {
253111
widgetBuilder = null;
254112
ajaxRequestBuilder = null;
255113
context = null;
256114
applicationContext = null;
257-
encrypter = null;
258-
}
259-
260-
@Override
261-
public Map<Object, Object> getAttributes() {
262-
return context.getAttributes();
263115
}
264116

265117
@Override
@@ -275,17 +127,6 @@ public ApplicationContext getApplicationContext() {
275127
return applicationContext;
276128
}
277129

278-
@Override
279-
public StringEncrypter getEncrypter() {
280-
// lazy init, it's not required for all pages
281-
if (encrypter == null) {
282-
// we can't store it in the ApplicationMap, as Cipher isn't thread safe
283-
encrypter = new StringEncrypter(getApplicationContext().getConfig().getSecretKey());
284-
}
285-
286-
return encrypter;
287-
}
288-
289130
@Override
290131
public boolean isSecure() {
291132
Object request = context.getExternalContext().getRequest();
@@ -333,18 +174,4 @@ public boolean isRTL() {
333174

334175
return rtl;
335176
}
336-
337-
@Override
338-
public void clearTableStates() {
339-
this.context.getExternalContext().getSessionMap().remove(Constants.TABLE_STATE);
340-
}
341-
342-
@Override
343-
public void clearTableState(String key) {
344-
Map<String, Object> sessionMap = this.context.getExternalContext().getSessionMap();
345-
Map<String, TableState> dtState = (Map) sessionMap.get(Constants.TABLE_STATE);
346-
if (dtState != null) {
347-
dtState.remove(key);
348-
}
349-
}
350177
}

src/main/java/org/primefaces/context/PrimePartialResponseWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void endDocument() throws IOException {
9090
if (requestContext != null) {
9191
try {
9292
if (context.isValidationFailed()) {
93-
requestContext.addCallbackParam("validationFailed", true);
93+
requestContext.getCallbackParams().put("validationFailed", true);
9494
}
9595

9696
encodeCallbackParams(requestContext.getCallbackParams());

0 commit comments

Comments
 (0)