Skip to content

Commit

Permalink
MYFACES-4644 (4.1): Enable extensionless requests for programmatic v…
Browse files Browse the repository at this point in the history
…iews
  • Loading branch information
volosied committed Dec 1, 2023
1 parent 814102f commit 9ed828b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
2 changes: 0 additions & 2 deletions api/src/main/java/jakarta/faces/annotation/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.lang.annotation.Target;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.enterprise.util.Nonbinding;
import jakarta.inject.Qualifier;

/**
Expand Down Expand Up @@ -60,7 +59,6 @@
*
* @return the Faces View Id pattern
*/
@Nonbinding
String value() default "";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
import org.apache.myfaces.util.lang.StringUtils;
import org.apache.myfaces.util.WebConfigParamUtils;

import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.spi.Bean;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.faces.annotation.View;
import jakarta.faces.application.Resource;
import jakarta.faces.application.ResourceHandler;
import jakarta.faces.application.ResourceWrapper;
Expand All @@ -40,6 +44,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -61,6 +67,7 @@
import jakarta.faces.application.ViewHandler;
import jakarta.faces.view.ViewDeclarationLanguage;

import org.apache.myfaces.cdi.util.CDIUtils;
import org.apache.myfaces.config.webparameters.MyfacesConfig;
import org.apache.myfaces.core.api.shared.lang.Assert;
import org.apache.myfaces.core.api.shared.lang.LocaleUtils;
Expand Down Expand Up @@ -1697,8 +1704,31 @@ public Stream<String> getViewResources(FacesContext facesContext,
Iterator it = new FilterInvalidSuffixViewResourceIterator(new ViewResourceIterator(facesContext,
getResourceHandlerSupport(), localePrefix, contracts,
contractPreferred, path, maxDepth, options), facesContext, _viewSuffixes);

return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it,Spliterator.DISTINCT), false);

return Stream.concat(StreamSupport.stream(Spliterators.spliteratorUnknownSize(it,Spliterator.DISTINCT),
false), getProgrammaticViewIds(facesContext));
}

private Stream<String> getProgrammaticViewIds(FacesContext facesContext)
{
ArrayList<String> views = new ArrayList<String>();
BeanManager beanManager = CDIUtils.getBeanManager(facesContext);
if(beanManager != null)
{
for(Bean<?> bean : beanManager.getBeans(Object.class, Any.Literal.INSTANCE))
{
for(Annotation anno :bean.getBeanClass().getAnnotations())
{
// ensure it is of type view (avoid cast errors such as jdk.proxy4.$Proxy17)
if(anno instanceof View)
{
View view = (View) anno;
views.add(view.value());
}
}
}
}
return views.stream();
}

private Set<String> loadSuffixes(ExternalContext context)
Expand Down

0 comments on commit 9ed828b

Please sign in to comment.