You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2024/08/01 09:17:24 UTC
(myfaces) branch 4.1.x updated: MYFACES-4675 also for p:ajax resetValues=true
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch 4.1.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/4.1.x by this push:
new e926f027f MYFACES-4675 also for p:ajax resetValues=true
e926f027f is described below
commit e926f027fb4b0beed15de4c8d801c6c41078dd89
Author: tandraschko <ta...@apache.org>
AuthorDate: Thu Aug 1 11:17:15 2024 +0200
MYFACES-4675 also for p:ajax resetValues=true
---
.../java/jakarta/faces/component/UIViewRoot.java | 79 +-----------
.../myfaces/core/api/shared/ResetValuesUtils.java | 141 +++++++++++++++++++++
.../context/servlet/PartialViewContextImpl.java | 21 +--
3 files changed, 145 insertions(+), 96 deletions(-)
diff --git a/api/src/main/java/jakarta/faces/component/UIViewRoot.java b/api/src/main/java/jakarta/faces/component/UIViewRoot.java
index 8bc397540..e5e19ba48 100644
--- a/api/src/main/java/jakarta/faces/component/UIViewRoot.java
+++ b/api/src/main/java/jakarta/faces/component/UIViewRoot.java
@@ -18,6 +18,7 @@
*/
package jakarta.faces.component;
+import org.apache.myfaces.core.api.shared.ResetValuesUtils;
import org.apache.myfaces.core.api.shared.lang.ClassUtils;
import org.apache.myfaces.core.api.shared.ComponentUtils;
import org.apache.myfaces.core.api.shared.lang.LocaleUtils;
@@ -1462,38 +1463,7 @@ public class UIViewRoot extends UIComponentBase implements UniqueIdVendor
*/
public void resetValues(FacesContext context, java.util.Collection<java.lang.String> clientIds)
{
- if (clientIds == null || clientIds.isEmpty())
- {
- return;
- }
-
- VisitContext visitContext = null;
- ResetInputContextCallback contextCallback = null;
-
- for (String clientId : clientIds)
- {
- if (clientId == null || clientId.isBlank() || "@none".equals(clientId))
- {
- continue;
- }
-
- // lazy init
- if (visitContext == null) {
- visitContext = VisitContext.createVisitContext(context, null, null);
- }
-
- if ("@all".equals(clientId) || PartialResponseWriter.RENDER_ALL_MARKER.equals(clientId)) {
- this.visitTree(visitContext, ResetInputVisitCallback.INSTANCE);
- }
- else {
- // lazy init
- if (contextCallback == null) {
- contextCallback = new ResetInputContextCallback(visitContext);
- }
-
- this.invokeOnComponent(context, clientId, contextCallback);
- }
- }
+ ResetValuesUtils.resetValues(context, this, clientIds);
}
/**
@@ -1958,52 +1928,7 @@ public class UIViewRoot extends UIComponentBase implements UniqueIdVendor
}
}
- public static class ResetInputContextCallback implements ContextCallback {
- private VisitContext visitContext;
-
- /**
- * Constructs a new ResetInputContextCallback with the given {@link VisitContext}.
- *
- * @param visitContext the visit context to be used for visiting component trees
- */
- public ResetInputContextCallback(VisitContext visitContext) {
- this.visitContext = visitContext;
- }
-
- /**
- * Invokes the context callback on the given component. If the component is an instance
- * of {@link EditableValueHolder}, its value is reset. Otherwise, the component's tree
- * is visited using the {@link ResetInputVisitCallback} instance.
- *
- * @param fc the current {@link FacesContext}
- * @param component the component on which to invoke the context callback
- */
- @Override
- public void invokeContextCallback(FacesContext fc, UIComponent component) {
- if (component instanceof EditableValueHolder) {
- ((EditableValueHolder) component).resetValue();
- }
- else {
- component.visitTree(visitContext, ResetInputVisitCallback.INSTANCE);
- }
- }
- }
-
- public static class ResetInputVisitCallback implements VisitCallback {
-
- public static final ResetInputVisitCallback INSTANCE = new ResetInputVisitCallback();
-
- @Override
- public VisitResult visit(VisitContext context, UIComponent target) {
- if (target instanceof EditableValueHolder) {
- EditableValueHolder input = (EditableValueHolder) target;
- input.resetValue();
- }
-
- return VisitResult.ACCEPT;
- }
- }
private void publishException(FacesContext facesContext, Throwable e, PhaseId phaseId, String key)
{
diff --git a/api/src/main/java/org/apache/myfaces/core/api/shared/ResetValuesUtils.java b/api/src/main/java/org/apache/myfaces/core/api/shared/ResetValuesUtils.java
new file mode 100644
index 000000000..9bd1a7cec
--- /dev/null
+++ b/api/src/main/java/org/apache/myfaces/core/api/shared/ResetValuesUtils.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.core.api.shared;
+
+import jakarta.faces.component.ContextCallback;
+import jakarta.faces.component.EditableValueHolder;
+import jakarta.faces.component.UIComponent;
+import jakarta.faces.component.UIViewRoot;
+import jakarta.faces.component.visit.VisitCallback;
+import jakarta.faces.component.visit.VisitContext;
+import jakarta.faces.component.visit.VisitHint;
+import jakarta.faces.component.visit.VisitResult;
+import jakarta.faces.context.FacesContext;
+import jakarta.faces.context.PartialResponseWriter;
+
+import java.util.Collection;
+import java.util.Set;
+
+public class ResetValuesUtils
+{
+ private ResetValuesUtils()
+ {
+
+ }
+
+ public static void resetValues(FacesContext context, UIViewRoot viewRoot,
+ Collection<String> clientIds)
+ {
+ resetValues(context, viewRoot, clientIds, null);
+ }
+
+ public static void resetValues(FacesContext context, UIViewRoot viewRoot,
+ Collection<String> clientIds, Set<VisitHint> visitHints)
+ {
+ if (clientIds == null || clientIds.isEmpty())
+ {
+ return;
+ }
+
+ VisitContext visitContext = null;
+ ResetInputContextCallback contextCallback = null;
+
+ for (String clientId : clientIds)
+ {
+ if (clientId == null || clientId.isBlank() || "@none".equals(clientId))
+ {
+ continue;
+ }
+
+ // lazy init
+ if (visitContext == null)
+ {
+ visitContext = VisitContext.createVisitContext(context, null, visitHints);
+ }
+
+ if ("@all".equals(clientId) || PartialResponseWriter.RENDER_ALL_MARKER.equals(clientId))
+ {
+ viewRoot.visitTree(visitContext, ResetInputVisitCallback.INSTANCE);
+ }
+ else
+ {
+ // lazy init
+ if (contextCallback == null)
+ {
+ contextCallback = new ResetInputContextCallback(visitContext);
+ }
+
+ viewRoot.invokeOnComponent(context, clientId, contextCallback);
+ }
+ }
+ }
+
+ public static class ResetInputContextCallback implements ContextCallback
+ {
+ private VisitContext visitContext;
+
+ /**
+ * Constructs a new ResetInputContextCallback with the given {@link VisitContext}.
+ *
+ * @param visitContext the visit context to be used for visiting component trees
+ */
+ public ResetInputContextCallback(VisitContext visitContext)
+ {
+ this.visitContext = visitContext;
+ }
+
+ /**
+ * Invokes the context callback on the given component. If the component is an instance
+ * of {@link EditableValueHolder}, its value is reset. Otherwise, the component's tree
+ * is visited using the {@link ResetInputVisitCallback} instance.
+ *
+ * @param fc the current {@link FacesContext}
+ * @param component the component on which to invoke the context callback
+ */
+ @Override
+ public void invokeContextCallback(FacesContext fc, UIComponent component)
+ {
+ if (component instanceof EditableValueHolder)
+ {
+ ((EditableValueHolder) component).resetValue();
+ }
+ else
+ {
+ component.visitTree(visitContext, ResetInputVisitCallback.INSTANCE);
+ }
+ }
+ }
+
+ public static class ResetInputVisitCallback implements VisitCallback
+ {
+ public static final ResetInputVisitCallback INSTANCE = new ResetInputVisitCallback();
+
+ @Override
+ public VisitResult visit(VisitContext context, UIComponent target)
+ {
+ if (target instanceof EditableValueHolder)
+ {
+ EditableValueHolder input = (EditableValueHolder) target;
+ input.resetValue();
+ }
+
+ return VisitResult.ACCEPT;
+ }
+ }
+}
diff --git a/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java b/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
index 27f474f76..9e51e579c 100644
--- a/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
@@ -30,7 +30,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import jakarta.faces.FactoryFinder;
-import jakarta.faces.component.EditableValueHolder;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIViewParameter;
import jakarta.faces.component.UIViewRoot;
@@ -55,6 +54,7 @@ import org.apache.myfaces.application.viewstate.StateTokenProcessor;
import org.apache.myfaces.context.PartialResponseWriterImpl;
import org.apache.myfaces.context.RequestViewContext;
+import org.apache.myfaces.core.api.shared.ResetValuesUtils;
import org.apache.myfaces.renderkit.html.HtmlResponseStateManager;
import org.apache.myfaces.renderkit.html.util.ResourceUtils;
import org.apache.myfaces.util.lang.StringUtils;
@@ -73,8 +73,6 @@ public class PartialViewContextImpl extends PartialViewContext
private static final Set<VisitHint> PARTIAL_EXECUTE_HINTS = Collections.unmodifiableSet(
EnumSet.of(VisitHint.EXECUTE_LIFECYCLE, VisitHint.SKIP_UNRENDERED));
- private static final VisitCallback RESET_VALUES_CALLBACK = new ResetValuesCallback();
-
private static final Set<VisitHint> RESET_VALUES_HINTS =
Collections.unmodifiableSet(EnumSet.of(VisitHint.SKIP_UNRENDERED));
@@ -445,9 +443,7 @@ public class PartialViewContextImpl extends PartialViewContext
if (isResetValues())
{
- VisitContext visitContext = VisitContext.createVisitContext(context, getRenderIds(),
- RESET_VALUES_HINTS);
- viewRoot.visitTree(visitContext, RESET_VALUES_CALLBACK);
+ ResetValuesUtils.resetValues(context, viewRoot, getRenderIds(), RESET_VALUES_HINTS);
}
if (pvc.isRenderAll())
@@ -570,19 +566,6 @@ public class PartialViewContextImpl extends PartialViewContext
}
- // same like UIViewRoot#ResetValuesCallback
- private static class ResetValuesCallback implements VisitCallback
- {
- public VisitResult visit(VisitContext context, UIComponent target)
- {
- if (target instanceof EditableValueHolder)
- {
- ((EditableValueHolder)target).resetValue();
- }
- return VisitResult.ACCEPT;
- }
- }
-
private void processRenderResource(FacesContext facesContext, PartialResponseWriter writer, RequestViewContext rvc,
List<UIComponent> updatedComponents, String target) throws IOException
{