Skip to content

Commit

Permalink
Merge pull request #709 from volosied/main-updates
Browse files Browse the repository at this point in the history
Apply MYFACES-4662 & MYFACES-4664 to 5.0
  • Loading branch information
volosied committed Apr 26, 2024
2 parents 877442a + 54058bb commit 2fa694a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 9 deletions.
4 changes: 4 additions & 0 deletions impl/src/main/conf/META-INF/standard-faces-config-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,9 @@
<converter-for-class>java.lang.Short</converter-for-class>
<converter-class>jakarta.faces.convert.ShortConverter</converter-class>
</converter>
<converter>
<converter-for-class>java.util.UUID</converter-for-class>
<converter-class>jakarta.faces.convert.UUIDConverter</converter-class>
</converter>

</faces-config>
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public void encodeBegin(FacesContext facesContext, UIComponent component) throws

ResponseWriter writer = facesContext.getResponseWriter();
writer.startElement(HTML.HEAD_ELEM, component);
HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
if (HtmlRendererUtils.isOutputHtml5Doctype(facesContext))
{
HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
}
HtmlRendererUtils.renderHTMLAttributes(writer, component, HEAD_PASSTHROUGH_ATTRIBUTES);
HtmlRendererUtils.renderHTMLAttribute(writer, component, HTML.XMLNS_ATTR , HTML.XMLNS_ATTR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public void encodeBegin(FacesContext facesContext, UIComponent component) throws
}
else
{
HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
if (HtmlRendererUtils.isOutputHtml5Doctype(facesContext))
{
HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
}
}
if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
*/
package org.apache.myfaces.view.facelets;

import java.util.Collection;
import java.util.Collections;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.myfaces.view.ViewDeclarationLanguageStrategy;
import org.apache.myfaces.webapp.MyFacesContainerInitializer;

import jakarta.faces.application.ViewHandler;
import jakarta.faces.context.ExternalContext;
import jakarta.faces.context.FacesContext;
import jakarta.faces.view.ViewDeclarationLanguage;

import org.apache.myfaces.view.ViewDeclarationLanguageStrategy;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletRegistration;

/**
* @author Simon Lessard (latest modification by $Author$)
Expand All @@ -36,6 +42,7 @@
public class FaceletViewDeclarationLanguageStrategy implements ViewDeclarationLanguageStrategy
{
private Pattern _acceptPatterns;
private Pattern _servletMappingPatterns;
private String _extension;

private ViewDeclarationLanguage _language;
Expand All @@ -47,6 +54,8 @@ public FaceletViewDeclarationLanguageStrategy()

_acceptPatterns = loadAcceptPattern(eContext);

_servletMappingPatterns = loadServletMappingPatterns(eContext);

_extension = loadFaceletExtension(eContext);

_language = new FaceletViewDeclarationLanguage(context, this);
Expand All @@ -73,7 +82,12 @@ public boolean handles(String viewId)
}

// Otherwise, try to match the view identifier with the facelet mappings
return _acceptPatterns != null && _acceptPatterns.matcher(viewId).matches();
boolean matchFound = _acceptPatterns != null && _acceptPatterns.matcher(viewId).matches();

boolean servletMappingFound = _servletMappingPatterns != null
&& _servletMappingPatterns.matcher(viewId).matches();

return matchFound || servletMappingFound;
}

/**
Expand Down Expand Up @@ -108,6 +122,30 @@ private Pattern loadAcceptPattern(ExternalContext context)
return Pattern.compile(toRegex(mappings));
}

private Pattern loadServletMappingPatterns(ExternalContext context)
{
assert context != null;

ServletRegistration facesServletRegistration = (ServletRegistration)
((ServletContext)context.getContext()).getAttribute(
MyFacesContainerInitializer.FACES_SERVLET_SERVLETREGISTRATION);

Collection<String> servletMappings = Collections.emptyList();

if(facesServletRegistration != null)
{
servletMappings = facesServletRegistration.getMappings();
}
String joinedMappings = servletMappings.stream().collect(Collectors.joining(";"));

if(joinedMappings.length() == 0)
{
return null;
}

return Pattern.compile(toRegex(joinedMappings));
}

private String loadFaceletExtension(ExternalContext context)
{
assert context != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ else if (context.getViewRoot().getAttributes().get(ViewPoolProcessor.RESET_SAVE_
if (context.getCurrentPhaseId() != null &&
!PhaseId.RENDER_RESPONSE.equals(context.getCurrentPhaseId()))
{
if (parentSaved == null /*&&_rowDeltaStates.isEmpty()*/ && _rowStates.isEmpty())
if (parentSaved == null &&_rowDeltaStates.isEmpty() && _rowStates.isEmpty())
{
return null;
}
Expand Down Expand Up @@ -2156,17 +2156,18 @@ else if (context.getViewRoot().getAttributes().get(ViewPoolProcessor.RESET_SAVE_
if (context.getCurrentPhaseId() != null &&
!PhaseId.RENDER_RESPONSE.equals(context.getCurrentPhaseId()))
{
Object[] values = new Object[3];
Object[] values = new Object[4];
values[0] = super.saveState(context);
values[1] = null;
values[1] = UIComponentBase.saveAttachedState(context, _rowDeltaStates);
values[2] = UIComponentBase.saveAttachedState(context, _rowStates);
values[3] = UIComponentBase.saveAttachedState(context, _rowTransientStates);
return values;
}
else
{
Object[] values = new Object[2];
values[0] = super.saveState(context);
values[1] = null;
values[1] = UIComponentBase.saveAttachedState(context, _rowDeltaStates);
return values;
}
}
Expand Down

0 comments on commit 2fa694a

Please sign in to comment.