From adc8cb2f785a870816ef47467df8874d65630e15 Mon Sep 17 00:00:00 2001 From: Udo Schnurpfeil Date: Tue, 17 Dec 2024 14:47:27 +0100 Subject: [PATCH] optimize code: use constants --- .../internal/component/AbstractUIPage.java | 5 ++- .../internal/component/AbstractUISheet.java | 3 +- .../renderer/DecodingCommandRendererBase.java | 4 +- .../renderkit/renderer/PageRenderer.java | 23 ++++++----- .../renderkit/renderer/PaginatorRenderer.java | 3 +- .../renderkit/renderer/ReloadRenderer.java | 4 +- .../renderkit/renderer/SheetRenderer.java | 4 +- .../renderer/SplitLayoutRenderer.java | 4 +- .../tobago/internal/util/RenderUtils.java | 4 +- .../tobago/renderkit/RendererBase.java | 40 +++++++++---------- 10 files changed, 53 insertions(+), 41 deletions(-) diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java index 3a9b2be4e5..4260327e36 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIPage.java @@ -26,9 +26,9 @@ import jakarta.faces.component.UIComponent; import jakarta.faces.component.UIViewRoot; +import jakarta.faces.component.behavior.ClientBehaviorContext; import jakarta.faces.component.behavior.ClientBehaviorHolder; import jakarta.faces.context.FacesContext; - import java.lang.invoke.MethodHandles; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -83,7 +83,8 @@ public void markSubmittedForm(final FacesContext facesContext) { // reset old submitted state setSubmitted(false); - String sourceId = facesContext.getExternalContext().getRequestParameterMap().get("jakarta.faces.source"); + String sourceId = facesContext.getExternalContext().getRequestParameterMap() + .get(ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME); UIComponent command = null; if (sourceId != null) { if (LOG.isDebugEnabled()) { diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java index 2cc6dc2665..32507c0b21 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java @@ -692,7 +692,8 @@ private int getRowIndexFromSubtreeId(String sourceId, char separatorChar, int cl } public boolean isLazyUpdate(FacesContext facesContext) { - final String sourceId = facesContext.getExternalContext().getRequestParameterMap().get("jakarta.faces.source"); + final String sourceId = facesContext.getExternalContext().getRequestParameterMap() + .get(ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME); final String clientId = getClientId(facesContext); final String sheetClientIdWithAction = diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/DecodingCommandRendererBase.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/DecodingCommandRendererBase.java index ca68d93caa..8e78a93658 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/DecodingCommandRendererBase.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/DecodingCommandRendererBase.java @@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory; import jakarta.faces.component.UIComponent; +import jakarta.faces.component.behavior.ClientBehaviorContext; import jakarta.faces.context.FacesContext; import jakarta.faces.event.ActionEvent; @@ -42,7 +43,8 @@ public void decodeInternal(final FacesContext facesContext, final T component) { && ((AbstractUICommandBase) component).isDisabled()) { return; } - final String sourceId = facesContext.getExternalContext().getRequestParameterMap().get("jakarta.faces.source"); + final String sourceId = facesContext.getExternalContext().getRequestParameterMap() + .get(ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME); final String clientId = component.getClientId(facesContext); if (LOG.isDebugEnabled()) { LOG.debug("sourceId = '{}", sourceId); diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java index 7d16e0a323..73937e1843 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PageRenderer.java @@ -19,15 +19,6 @@ package org.apache.myfaces.tobago.internal.renderkit.renderer; -import jakarta.faces.application.Application; -import jakarta.faces.application.ProjectStage; -import jakarta.faces.application.ViewHandler; -import jakarta.faces.component.UIComponent; -import jakarta.faces.component.UIOutput; -import jakarta.faces.component.UIViewRoot; -import jakarta.faces.context.ExternalContext; -import jakarta.faces.context.FacesContext; -import jakarta.faces.context.PartialViewContext; import org.apache.myfaces.tobago.component.Attributes; import org.apache.myfaces.tobago.component.RendererTypes; import org.apache.myfaces.tobago.component.Tags; @@ -61,6 +52,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import jakarta.faces.application.Application; +import jakarta.faces.application.ProjectStage; +import jakarta.faces.application.ViewHandler; +import jakarta.faces.component.UIComponent; +import jakarta.faces.component.UIOutput; +import jakarta.faces.component.UIViewRoot; +import jakarta.faces.component.behavior.ClientBehaviorContext; +import jakarta.faces.context.ExternalContext; +import jakarta.faces.context.FacesContext; +import jakarta.faces.context.PartialViewContext; import java.io.IOException; import java.lang.invoke.MethodHandles; import java.util.ArrayList; @@ -195,8 +196,8 @@ public void encodeBeginInternal(final FacesContext facesContext, final T compone writer.startElement(HtmlElements.INPUT); writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN); - writer.writeNameAttribute("jakarta.faces.source"); - writer.writeIdAttribute("jakarta.faces.source"); + writer.writeNameAttribute(ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME); + writer.writeIdAttribute(ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME); writer.writeAttribute(HtmlAttributes.DISABLED, true); writer.endElement(HtmlElements.INPUT); diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PaginatorRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PaginatorRenderer.java index 1312a4e968..88e9959d19 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PaginatorRenderer.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PaginatorRenderer.java @@ -36,6 +36,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import jakarta.faces.component.behavior.ClientBehaviorContext; import jakarta.faces.context.FacesContext; import java.io.IOException; import java.lang.invoke.MethodHandles; @@ -50,7 +51,7 @@ public abstract class PaginatorRenderer extends R @Override public void decodeInternal(final FacesContext facesContext, final T paginator) { final Map requestParameterMap = facesContext.getExternalContext().getRequestParameterMap(); - final String sourceId = requestParameterMap.get("jakarta.faces.source"); + final String sourceId = requestParameterMap.get(ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME); final String clientId = paginator.getClientId(facesContext); if (LOG.isDebugEnabled()) { LOG.debug("clientId {}", clientId); diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ReloadRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ReloadRenderer.java index 4d5dee6caa..4211fc2f41 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ReloadRenderer.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/ReloadRenderer.java @@ -28,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import jakarta.faces.component.behavior.ClientBehaviorContext; import jakarta.faces.context.FacesContext; import jakarta.faces.context.PartialViewContext; @@ -41,7 +42,8 @@ public class ReloadRenderer extends RendererBase @Override public void decodeInternal(final FacesContext facesContext, final T component) { - final String sourceId = facesContext.getExternalContext().getRequestParameterMap().get("jakarta.faces.source"); + final String sourceId = facesContext.getExternalContext().getRequestParameterMap() + .get(ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME); final String clientId = component.getClientId(facesContext); if (clientId.equals(sourceId)) { if (LOG.isDebugEnabled()) { diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java index fe86f94939..e1cecf5a9d 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java @@ -79,6 +79,7 @@ import jakarta.faces.component.UIComponent; import jakarta.faces.component.UIData; import jakarta.faces.component.behavior.AjaxBehavior; +import jakarta.faces.component.behavior.ClientBehaviorContext; import jakarta.faces.context.FacesContext; import java.io.IOException; import java.lang.invoke.MethodHandles; @@ -165,7 +166,8 @@ private void decodeColumnAction(final FacesContext facesContext, final List extends Render @Override public void decodeInternal(final FacesContext facesContext, final T component) { - final String sourceId = facesContext.getExternalContext().getRequestParameterMap().get("jakarta.faces.source"); + final String sourceId = facesContext.getExternalContext().getRequestParameterMap() + .get(ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME); final String clientId = component.getClientId() + SUFFIX_SIZES; if (clientId.equals(sourceId)) { // only decode and update layout at resize request diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/RenderUtils.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/RenderUtils.java index 65216b0f10..bc00a7afd9 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/RenderUtils.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/RenderUtils.java @@ -392,11 +392,11 @@ public static void decodeClientBehaviors(final FacesContext facesContext, final final Map> clientBehaviors = clientBehaviorHolder.getClientBehaviors(); if (clientBehaviors != null && !clientBehaviors.isEmpty()) { final Map paramMap = facesContext.getExternalContext().getRequestParameterMap(); - final String behaviorEventName = paramMap.get("jakarta.faces.behavior.event"); + final String behaviorEventName = paramMap.get(ClientBehaviorContext.BEHAVIOR_EVENT_PARAM_NAME); if (behaviorEventName != null) { final List clientBehaviorList = clientBehaviors.get(behaviorEventName); if (clientBehaviorList != null && !clientBehaviorList.isEmpty()) { - final String clientId = paramMap.get("jakarta.faces.source"); + final String clientId = paramMap.get(ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME); if (component.getClientId(facesContext).equals(clientId)) { for (final ClientBehavior clientBehavior : clientBehaviorList) { clientBehavior.decode(facesContext, component); diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java index c8d76fb4dd..682e767ff1 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/RendererBase.java @@ -19,24 +19,6 @@ package org.apache.myfaces.tobago.renderkit; -import jakarta.el.ValueExpression; -import jakarta.faces.component.EditableValueHolder; -import jakarta.faces.component.UIComponent; -import jakarta.faces.component.UIInput; -import jakarta.faces.component.ValueHolder; -import jakarta.faces.component.behavior.AjaxBehavior; -import jakarta.faces.component.behavior.ClientBehavior; -import jakarta.faces.component.behavior.ClientBehaviorBase; -import jakarta.faces.component.behavior.ClientBehaviorContext; -import jakarta.faces.component.behavior.ClientBehaviorHolder; -import jakarta.faces.context.FacesContext; -import jakarta.faces.context.ResponseWriter; -import jakarta.faces.convert.Converter; -import jakarta.faces.convert.ConverterException; -import jakarta.faces.model.SelectItem; -import jakarta.faces.model.SelectItemGroup; -import jakarta.faces.render.ClientBehaviorRenderer; -import jakarta.faces.render.Renderer; import org.apache.myfaces.tobago.component.ClientBehaviors; import org.apache.myfaces.tobago.component.Facets; import org.apache.myfaces.tobago.component.RendererTypes; @@ -68,6 +50,24 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import jakarta.el.ValueExpression; +import jakarta.faces.component.EditableValueHolder; +import jakarta.faces.component.UIComponent; +import jakarta.faces.component.UIInput; +import jakarta.faces.component.ValueHolder; +import jakarta.faces.component.behavior.AjaxBehavior; +import jakarta.faces.component.behavior.ClientBehavior; +import jakarta.faces.component.behavior.ClientBehaviorBase; +import jakarta.faces.component.behavior.ClientBehaviorContext; +import jakarta.faces.component.behavior.ClientBehaviorHolder; +import jakarta.faces.context.FacesContext; +import jakarta.faces.context.ResponseWriter; +import jakarta.faces.convert.Converter; +import jakarta.faces.convert.ConverterException; +import jakarta.faces.model.SelectItem; +import jakarta.faces.model.SelectItemGroup; +import jakarta.faces.render.ClientBehaviorRenderer; +import jakarta.faces.render.Renderer; import java.io.IOException; import java.lang.invoke.MethodHandles; import java.util.Arrays; @@ -399,11 +399,11 @@ protected void decodeClientBehaviors(final FacesContext facesContext, final T co final Map> clientBehaviors = clientBehaviorHolder.getClientBehaviors(); if (clientBehaviors != null && !clientBehaviors.isEmpty()) { final Map paramMap = facesContext.getExternalContext().getRequestParameterMap(); - final String behaviorEventName = paramMap.get("jakarta.faces.behavior.event"); + final String behaviorEventName = paramMap.get(ClientBehaviorContext.BEHAVIOR_EVENT_PARAM_NAME); if (behaviorEventName != null) { final List clientBehaviorList = clientBehaviors.get(behaviorEventName); if (clientBehaviorList != null && !clientBehaviorList.isEmpty()) { - final String clientId = paramMap.get("jakarta.faces.source"); + final String clientId = paramMap.get(ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME); if (component.getClientId(facesContext).equals(clientId)) { for (final ClientBehavior clientBehavior : clientBehaviorList) { clientBehavior.decode(facesContext, component);