From 5d7b82686efc556617a202e7b8951f6e79e16c8a Mon Sep 17 00:00:00 2001 From: Thomas Andraschko Date: Mon, 24 Jul 2023 14:08:33 +0200 Subject: [PATCH] revert MYFACES-4617 --- .../jakarta/faces/annotation/FacesConfig.java | 16 +++ .../faces/application/ResourceHandler.java | 12 ++ .../faces/application/ViewHandler.java | 12 +- .../component/html/_DisabledProperty.java | 31 ----- .../faces/component/html/_HtmlInputFile.java | 29 ++++- .../component/html/_HtmlInputSecret.java | 2 +- .../application/ResourceHandlerImpl.java | 20 +++- .../myfaces/application/ViewIdSupport.java | 112 ++++++++++-------- .../config/webparameters/MyfacesConfig.java | 10 ++ .../html/base/HtmlInputFileRendererBase.java | 5 + .../facelets/compiler/TagLibraryConfig.java | 2 +- .../composite/CompositeResourceLibrary.java | 2 +- 12 files changed, 164 insertions(+), 89 deletions(-) delete mode 100644 api/src/main/java/jakarta/faces/component/html/_DisabledProperty.java diff --git a/api/src/main/java/jakarta/faces/annotation/FacesConfig.java b/api/src/main/java/jakarta/faces/annotation/FacesConfig.java index ec179e9a69..0a89adcd3d 100644 --- a/api/src/main/java/jakarta/faces/annotation/FacesConfig.java +++ b/api/src/main/java/jakarta/faces/annotation/FacesConfig.java @@ -23,6 +23,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import jakarta.enterprise.util.Nonbinding; import jakarta.inject.Qualifier; /** @@ -33,10 +34,25 @@ @Retention(value=RetentionPolicy.RUNTIME) public @interface FacesConfig { + @Deprecated(forRemoval = true, since = "4.0") + @Nonbinding Version version() default Version.JSF_2_3; + + @Deprecated(forRemoval = true, since = "4.0") + public static enum Version + { + JSF_2_3 + } + public static final class Literal extends AnnotationLiteral implements FacesConfig { private static final long serialVersionUID = 1L; public static final Literal INSTANCE = new Literal(); + + @Override + public Version version() + { + return Version.JSF_2_3; + } } } diff --git a/api/src/main/java/jakarta/faces/application/ResourceHandler.java b/api/src/main/java/jakarta/faces/application/ResourceHandler.java index b4692d345d..0befd241d3 100644 --- a/api/src/main/java/jakarta/faces/application/ResourceHandler.java +++ b/api/src/main/java/jakarta/faces/application/ResourceHandler.java @@ -58,6 +58,18 @@ public abstract class ResourceHandler */ public static final String WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME = "jakarta.faces.WEBAPP_RESOURCES_DIRECTORY"; + /** + * @since 2.3 + */ + @Deprecated + public static final String JSF_SCRIPT_RESOURCE_NAME = "faces.js"; + + /** + * @since 2.3 + */ + @Deprecated + public static final String JSF_SCRIPT_LIBRARY_NAME = "jakarta.faces"; + /** * @since 4.0 */ diff --git a/api/src/main/java/jakarta/faces/application/ViewHandler.java b/api/src/main/java/jakarta/faces/application/ViewHandler.java index 3cdf62bc21..9888552de9 100755 --- a/api/src/main/java/jakarta/faces/application/ViewHandler.java +++ b/api/src/main/java/jakarta/faces/application/ViewHandler.java @@ -69,7 +69,17 @@ public abstract class ViewHandler { public static final String CHARACTER_ENCODING_KEY = "jakarta.faces.request.charset"; public static final String DEFAULT_FACELETS_SUFFIX = ".xhtml"; - + @Deprecated(since = "4.0") + public static final String DEFAULT_SUFFIX = ".xhtml"; + + /** + * Indicate the default suffixes, separated by spaces to derive the default file URI + * used by Faces to create views and render pages. + */ + @JSFWebConfigParam(defaultValue=".xhtml", since="1.1", group="viewhandler", deprecated = true) + @Deprecated(since = "4.0") + public static final String DEFAULT_SUFFIX_PARAM_NAME = "jakarta.faces.DEFAULT_SUFFIX"; + /** * The default extension used to handle facelets pages. */ diff --git a/api/src/main/java/jakarta/faces/component/html/_DisabledProperty.java b/api/src/main/java/jakarta/faces/component/html/_DisabledProperty.java deleted file mode 100644 index 522a246e49..0000000000 --- a/api/src/main/java/jakarta/faces/component/html/_DisabledProperty.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 jakarta.faces.component.html; - -import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty; - -interface _DisabledProperty -{ - /** - * HTML: When true, this element cannot receive focus. - * - */ - @JSFProperty(defaultValue="false") - public abstract boolean isDisabled(); -} diff --git a/api/src/main/java/jakarta/faces/component/html/_HtmlInputFile.java b/api/src/main/java/jakarta/faces/component/html/_HtmlInputFile.java index 5777d28542..0d1b275323 100644 --- a/api/src/main/java/jakarta/faces/component/html/_HtmlInputFile.java +++ b/api/src/main/java/jakarta/faces/component/html/_HtmlInputFile.java @@ -38,7 +38,7 @@ defaultEventName = "valueChange" ) abstract class _HtmlInputFile extends UIInput implements _AccesskeyProperty, - _UniversalProperties, _DisabledProperty, + _AltProperty, _UniversalProperties, _DisabledReadonlyProperties, _FocusBlurProperties, _ChangeProperty, _SelectProperty, _EventProperties, _StyleProperties, _TabindexProperty, _LabelProperty, _RoleProperty @@ -47,6 +47,33 @@ abstract class _HtmlInputFile extends UIInput implements _AccesskeyProperty, static public final String COMPONENT_FAMILY = "jakarta.faces.Input"; static public final String COMPONENT_TYPE = "jakarta.faces.HtmlInputFile"; + /** + * HTML: The maximum number of characters allowed to be entered. + * + * @JSFProperty + * defaultValue = "Integer.MIN_VALUE" + */ + public abstract int getMaxlength(); + + /** + * HTML: The initial width of this control, in characters. + * + * @JSFProperty + * defaultValue = "Integer.MIN_VALUE" + */ + public abstract int getSize(); + + /** + * If the value of this attribute is "off", render "off" as the value of the attribute. + * This indicates that the browser should disable its autocomplete feature for this component. + * This is useful for components that perform autocompletion and do not want the browser interfering. + * If this attribute is not set or the value is "on", render nothing. + * + * @return the new autocomplete value + */ + @JSFProperty + public abstract String getAutocomplete(); + /** * Comma separated string of mime types of files to filter in client side file browse dialog. * NOTE: this is not validated in server side. diff --git a/api/src/main/java/jakarta/faces/component/html/_HtmlInputSecret.java b/api/src/main/java/jakarta/faces/component/html/_HtmlInputSecret.java index 1b120bd33e..aa2ba9d7de 100644 --- a/api/src/main/java/jakarta/faces/component/html/_HtmlInputSecret.java +++ b/api/src/main/java/jakarta/faces/component/html/_HtmlInputSecret.java @@ -33,7 +33,7 @@ implementz = "jakarta.faces.component.behavior.ClientBehaviorHolder", defaultEventName = "valueChange") abstract class _HtmlInputSecret extends UIInput implements _AccesskeyProperty, - _UniversalProperties, _FocusBlurProperties, _EventProperties, + _AltProperty, _UniversalProperties, _FocusBlurProperties, _EventProperties, _StyleProperties, _TabindexProperty, _ChangeProperty, _SelectProperty, _DisabledReadonlyProperties, _LabelProperty, _RoleProperty { diff --git a/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java b/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java index 7112bcdaad..19d82e94c6 100644 --- a/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java +++ b/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java @@ -1704,9 +1704,24 @@ public Stream getViewResources(FacesContext facesContext, private Set loadSuffixes(ExternalContext context) { Set result = new HashSet<>(); - + String definedSuffixes = WebConfigParamUtils.getStringInitParameter(context, + ViewHandler.DEFAULT_SUFFIX_PARAM_NAME, ViewHandler.DEFAULT_SUFFIX); StringTokenizer tokenizer; - + + if (definedSuffixes == null) + { + definedSuffixes = ViewHandler.DEFAULT_SUFFIX; + } + + // This is a space-separated list of suffixes, so parse them out. + + tokenizer = new StringTokenizer (definedSuffixes, " "); + + while (tokenizer.hasMoreTokens()) + { + result.add (tokenizer.nextToken()); + } + String faceletSuffix = WebConfigParamUtils.getStringInitParameter(context, ViewHandler.FACELETS_SUFFIX_PARAM_NAME, ViewHandler.DEFAULT_FACELETS_SUFFIX); @@ -1716,6 +1731,7 @@ private Set loadSuffixes(ExternalContext context) } String faceletViewMappings = WebConfigParamUtils.getStringInitParameter(context, FACELETS_VIEW_MAPPINGS_PARAM); + if (faceletViewMappings != null) { tokenizer = new StringTokenizer(faceletViewMappings, ";"); diff --git a/impl/src/main/java/org/apache/myfaces/application/ViewIdSupport.java b/impl/src/main/java/org/apache/myfaces/application/ViewIdSupport.java index 5ebb8fda26..5c595a226e 100644 --- a/impl/src/main/java/org/apache/myfaces/application/ViewIdSupport.java +++ b/impl/src/main/java/org/apache/myfaces/application/ViewIdSupport.java @@ -249,14 +249,16 @@ else if (mapping.isExtensionMapping()) { //See Faces 2.0 section 7.5.2 boolean founded = false; - String contextSuffix = config.getFaceletsViewSuffix(); - if (viewId.endsWith(contextSuffix)) + for (String contextSuffix : config.getViewSuffix()) { - builder.append(viewId, 0, viewId.indexOf(contextSuffix)); - builder.append(mapping.getExtension()); - founded = true; + if (viewId.endsWith(contextSuffix)) + { + builder.append(viewId, 0, viewId.indexOf(contextSuffix)); + builder.append(mapping.getExtension()); + founded = true; + break; + } } - if (!founded) { //See Faces 2.0 section 7.5.2 @@ -277,12 +279,12 @@ else if (mapping.isExtensionMapping()) else if(viewId.lastIndexOf('.') != -1 ) { builder.append(viewId, 0, viewId.lastIndexOf('.')); - builder.append(config.getFaceletsViewSuffix()); + builder.append(config.getViewSuffix()[0]); } else { builder.append(viewId); - builder.append(config.getFaceletsViewSuffix()); + builder.append(config.getViewSuffix()[0]); } } } @@ -327,12 +329,14 @@ else if (mapping.isPrefixMapping()) private String calculateExactMapping(FacesContext context, String viewId) { String prefixedExactMapping = null; - - if (viewId.endsWith(config.getFaceletsViewSuffix())) + for (String contextSuffix : config.getViewSuffix()) { - prefixedExactMapping = viewId.substring(0, viewId.length() - config.getFaceletsViewSuffix().length()); + if (viewId.endsWith(contextSuffix)) + { + prefixedExactMapping = viewId.substring(0, viewId.length() - contextSuffix.length()); + break; + } } - return prefixedExactMapping == null ? viewId : prefixedExactMapping; } @@ -400,62 +404,68 @@ protected String handleSuffixMapping(FacesContext context, String requestViewId) StringBuilder builder = SharedStringBuilder.get(context, VIEW_HANDLER_SUPPORT_SB); //Try to locate any resource that match with the expected id - String defaultSuffix = config.getFaceletsViewSuffix(); - builder.append(requestViewId); - - if (extensionPos > -1 && extensionPos > slashPos) - { - builder.replace(extensionPos, requestViewId.length(), defaultSuffix); - } - else + for (String defaultSuffix : config.getViewSuffix()) { - builder.append(defaultSuffix); - } - - String candidateViewId = builder.toString(); + builder.setLength(0); + builder.append(requestViewId); + + if (extensionPos > -1 && extensionPos > slashPos) + { + builder.replace(extensionPos, requestViewId.length(), defaultSuffix); + } + else + { + builder.append(defaultSuffix); + } - if (config.getFaceletsViewMappings() != null && config.getFaceletsViewMappings().length > 0 ) - { - for (String mapping : config.getFaceletsViewMappings()) + String candidateViewId = builder.toString(); + + if (config.getFaceletsViewMappings() != null && config.getFaceletsViewMappings().length > 0 ) { - if (mapping.startsWith("/")) - { - continue; //skip this entry, its a prefix mapping - } - if (mapping.equals(candidateViewId)) - { - return candidateViewId; - } - if (mapping.startsWith(".")) //this is a wildcard entry + for (String mapping : config.getFaceletsViewMappings()) { - builder.setLength(0); //reset/reuse the builder object - builder.append(candidateViewId); - builder.replace(candidateViewId.lastIndexOf('.'), candidateViewId.length(), mapping); - String tempViewId = builder.toString(); - if (isViewExistent(context, tempViewId)) + if (mapping.startsWith("/")) { - return tempViewId; + continue; //skip this entry, its a prefix mapping + } + if (mapping.equals(candidateViewId)) + { + return candidateViewId; + } + if (mapping.startsWith(".")) //this is a wildcard entry + { + builder.setLength(0); //reset/reuse the builder object + builder.append(candidateViewId); + builder.replace(candidateViewId.lastIndexOf('.'), candidateViewId.length(), mapping); + String tempViewId = builder.toString(); + if (isViewExistent(context, tempViewId)) + { + return tempViewId; + } } } } - } - // forced facelets mappings did not match or there were no entries in faceletsViewMappings array - if (isViewExistent(context,candidateViewId)) - { - return candidateViewId; + // forced facelets mappings did not match or there were no entries in faceletsViewMappings array + if (isViewExistent(context,candidateViewId)) + { + return candidateViewId; + } } //jsp suffixes didn't match, try facelets suffix String faceletsDefaultSuffix = config.getFaceletsViewSuffix(); if (faceletsDefaultSuffix != null) { - if (faceletsDefaultSuffix.equals(defaultSuffix)) + for (String defaultSuffix : config.getViewSuffix()) { - faceletsDefaultSuffix = null; + if (faceletsDefaultSuffix.equals(defaultSuffix)) + { + faceletsDefaultSuffix = null; + break; + } } } - if (faceletsDefaultSuffix != null) { builder.setLength(0); @@ -470,7 +480,7 @@ protected String handleSuffixMapping(FacesContext context, String requestViewId) builder.append(faceletsDefaultSuffix); } - candidateViewId = builder.toString(); + String candidateViewId = builder.toString(); if (isViewExistent(context,candidateViewId)) { return candidateViewId; diff --git a/impl/src/main/java/org/apache/myfaces/config/webparameters/MyfacesConfig.java b/impl/src/main/java/org/apache/myfaces/config/webparameters/MyfacesConfig.java index 5d7506bc9e..134f2f1f9c 100755 --- a/impl/src/main/java/org/apache/myfaces/config/webparameters/MyfacesConfig.java +++ b/impl/src/main/java/org/apache/myfaces/config/webparameters/MyfacesConfig.java @@ -856,6 +856,7 @@ public class MyfacesConfig private String[] fullStateSavingViewIds; private int faceletsBufferSize = 1024; private boolean markInitialStateWhenApplyBuildView = MARK_INITIAL_STATE_WHEN_APPLY_BUILD_VIEW_DEFAULT; + private String[] viewSuffix = new String[] { ViewHandler.DEFAULT_SUFFIX }; private String[] faceletsViewMappings = new String[] {}; private String faceletsViewSuffix = ViewHandler.DEFAULT_FACELETS_SUFFIX; private ELExpressionCacheMode elExpressionCacheMode; @@ -1235,6 +1236,10 @@ else if (refreshTransientBuildOnPSS.equalsIgnoreCase("true") || cfg.markInitialStateWhenApplyBuildView = getBoolean(extCtx, MARK_INITIAL_STATE_WHEN_APPLY_BUILD_VIEW, MARK_INITIAL_STATE_WHEN_APPLY_BUILD_VIEW_DEFAULT); + cfg.viewSuffix = StringUtils.splitShortString( + getString(extCtx, ViewHandler.DEFAULT_SUFFIX_PARAM_NAME, ViewHandler.DEFAULT_SUFFIX), + ' '); + cfg.faceletsViewMappings = StringUtils.splitShortString( getString(extCtx, ViewHandler.FACELETS_VIEW_MAPPINGS_PARAM_NAME, null), ';'); @@ -1694,6 +1699,11 @@ public boolean isMarkInitialStateWhenApplyBuildView() return markInitialStateWhenApplyBuildView; } + public String[] getViewSuffix() + { + return viewSuffix; + } + public String[] getFaceletsViewMappings() { return faceletsViewMappings; diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlInputFileRendererBase.java b/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlInputFileRendererBase.java index 935150caa7..e37679ed34 100644 --- a/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlInputFileRendererBase.java +++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlInputFileRendererBase.java @@ -240,6 +240,11 @@ protected void renderInputBegin(FacesContext facesContext, UIComponent component writer.writeAttribute(HTML.MULTIPLE_ATTR, HTML.MULTIPLE_ATTR, null); } + if (AUTOCOMPLETE_VALUE_OFF.equals(inputFile.getAutocomplete())) + { + writer.writeAttribute(HTML.AUTOCOMPLETE_ATTR, AUTOCOMPLETE_VALUE_OFF, HTML.AUTOCOMPLETE_ATTR); + } + if (inputFile.getAccept() != null) { writer.writeAttribute(HTML.ACCEPT_ATTR, inputFile.getAccept(), HTML.ACCEPT_ATTR); diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TagLibraryConfig.java b/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TagLibraryConfig.java index b5e071d3ee..2aa909ae6c 100644 --- a/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TagLibraryConfig.java +++ b/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TagLibraryConfig.java @@ -85,7 +85,7 @@ public TagLibraryImpl(FacesContext facesContext, String namespace) _extension = loadFaceletExtension(externalContext); String defaultSuffixes = WebConfigParamUtils.getStringInitParameter(externalContext, - ViewHandler.FACELETS_SUFFIX_PARAM_NAME, ViewHandler.DEFAULT_FACELETS_SUFFIX ); + ViewHandler.DEFAULT_SUFFIX_PARAM_NAME, ViewHandler.DEFAULT_SUFFIX ); _defaultSuffixesArray = StringUtils.splitShortString(defaultSuffixes, ' '); diff --git a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeResourceLibrary.java b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeResourceLibrary.java index 6d76a10e83..7731ff3766 100644 --- a/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeResourceLibrary.java +++ b/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeResourceLibrary.java @@ -72,7 +72,7 @@ public CompositeResourceLibrary(FacesContext facesContext, String namespacePrefi _extension = loadFaceletExtension(externalContext); String defaultSuffixes = WebConfigParamUtils.getStringInitParameter(externalContext, - ViewHandler.FACELETS_SUFFIX_PARAM_NAME, ViewHandler.DEFAULT_FACELETS_SUFFIX ); + ViewHandler.DEFAULT_SUFFIX_PARAM_NAME, ViewHandler.DEFAULT_SUFFIX ); _defaultSuffixesArray = StringUtils.splitShortString(defaultSuffixes, ' ');