Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize code: use constants #5827

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,7 +51,7 @@ public abstract class PaginatorRenderer<T extends AbstractUIPaginator> extends R
@Override
public void decodeInternal(final FacesContext facesContext, final T paginator) {
final Map<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -41,7 +42,8 @@ public class ReloadRenderer<T extends AbstractUIReload> extends RendererBase<T>
@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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -165,7 +166,8 @@ private void decodeColumnAction(final FacesContext facesContext, final List<Abst
for (final AbstractUIColumnBase column : columns) {
final boolean sortable = ComponentUtils.getBooleanAttribute(column, Attributes.sortable);
if (sortable) {
final String sourceId = facesContext.getExternalContext().getRequestParameterMap().get("jakarta.faces.source");
final String sourceId = facesContext.getExternalContext().getRequestParameterMap()
.get(ClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAME);
final String columnId = column.getClientId(facesContext);
final String sorterId = columnId + "_" + AbstractUISheet.SORTER_ID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.faces.component.behavior.ClientBehaviorContext;
import jakarta.faces.context.FacesContext;

import java.io.IOException;
Expand All @@ -54,7 +55,8 @@ public class SplitLayoutRenderer<T extends AbstractUISplitLayout> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,11 @@ public static void decodeClientBehaviors(final FacesContext facesContext, final
final Map<String, List<ClientBehavior>> clientBehaviors = clientBehaviorHolder.getClientBehaviors();
if (clientBehaviors != null && !clientBehaviors.isEmpty()) {
final Map<String, String> 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<ClientBehavior> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -399,11 +399,11 @@ protected void decodeClientBehaviors(final FacesContext facesContext, final T co
final Map<String, List<ClientBehavior>> clientBehaviors = clientBehaviorHolder.getClientBehaviors();
if (clientBehaviors != null && !clientBehaviors.isEmpty()) {
final Map<String, String> 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<ClientBehavior> 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);
Expand Down
Loading