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
w3c validator warning: The type attribute is unnecessary for JavaScript resources. #4135
Comments
|
I like where you are going, PrimeFaces should definetely render valid markup in order for users to be able to include W3C QA validation icons on their websites for example. But shouldn't we first take care of the errors: Since |
+1 @cnsgithub |
+1. @tandraschko do you have an idea of where those errors are coming from? if not I can help investigate if you want. |
no idea, sry |
understood. I will investigate and see what I can find out. |
OK the errors are weird. The W3C validator is reporting type="button" is in the DOM twice but I when inspect the DOM in Chrome or any other tool its only there once. So I have no idea why its reporting this an an error and twice unless the JS is doing something to the DOM after it loads the W3C only looks at the original DOM sent from the server and not the JS manipulated DOM? |
@melloware Just right-click and view the page source, then you'll find them twice. |
Ahh interesting. Chrome and Firefox in the Inspector filter this out but View Source shows it. The issue is due to this.. <p:button type="button" value="GET STARTED" icon="fa fa-download" outcome="/getstarted"/> So its just bad markup in the showcase as that type="button" is not necessary. |
Ok, it's rather a showcase issue then... |
Yep I will submit a Showcase PR. |
As a solution for my problem, do not render the type attribute for the script element, I did write my own response writer. This solves the problem for primefaces and the standard jsf components. |
@OBreidenbach Do you care to share your response writer here please? |
@melloware sure, no big deal. Why are you coming back to this ticket after over 2 years? public class Html5ResponseWriter extends ResponseWriterWrapper {
private boolean inScriptStartTag;
public Html5ResponseWriter(ResponseWriter wrapped) {
super(wrapped);
}
@Override
public void startElement(String name, UIComponent component) throws IOException {
super.startElement(name, component);
inScriptStartTag = "script".equals(name);
}
@Override
public void endElement(String name) throws IOException {
super.endElement(name);
if ("script".equals(name)) {
inScriptStartTag = false;
}
}
@Override
public void writeAttribute(String name, Object value, String property) throws IOException {
if (inScriptStartTag && "text/javascript".equals(value)) {
return;
}
super.writeAttribute(name, value, property);
}
} public class MyFacesContext extends FacesContextWrapper {
public MyFacesContext(FacesContext context) {
super(context);
}
@Override
public void setResponseWriter(ResponseWriter responseWriter) {
super.setResponseWriter(new Html5ResponseWriter(responseWriter));
}
} public class MyFacesContextFactory extends FacesContextFactoryImpl {
private final FacesContextFactory wrapped;
public MyFacesContextFactory(FacesContextFactory facesContextFactory) {
wrapped = facesContextFactory;
}
@Override
public FacesContext getFacesContext(Object context, Object request, Object response, Lifecycle lifecycle) throws FacesException {
FacesContext wrappedContext = this.wrapped.getFacesContext(context, request, response, lifecycle);
return wrappedContext instanceof MyFacesContext ? wrappedContext : new MyFacesContext(wrappedContext);
}
} <faces-config>
<factory>
<faces-context-factory>my.package.MyFacesContextFactory</faces-context-factory>
</factory>
</faces-config> |
@OBreidenbach I think I might add this code in PFE for people to be able to enable with just... <faces-config>
<factory>
<faces-context-factory>org.primefaces.extensions.Html5ContextFactory</faces-context-factory>
</factory>
</faces-config> My client is running our HTML through WCAG and is seeing this and asking "WHY?" and they don't like my answer. :) |
Cool, good idea. |
just to clarify as i dont understand this 2 different factories? JSF/Java Server Faces API/Specs = javax:* Mojarra 2.3 = JSF impl MyFaces 2.3 = JSF Impl |
Therefor if we need to 2 different factories, they should be called Mojarra/MyFaces, not MyFaces/Jakarta, that doesnt make any sense. Its even better to only have 1 factory and add if-else statements for myfaces/mojarra |
And yes, the factory doenst need to extend a mojarra or myfaces class actually? Just check PrimeFaces, we have FactoryContextFactory there AFAIR |
Let me look I assumed i needed to extend the factory. |
Got it modeled after PrimeContextFactory now its just one class <faces-config>
<factory>
<faces-context-factory>org.primefaces.extensions.application.Html5ContextFactory</faces-context-factory>
</factory>
</faces-config> |
This is now a first class citizen in Faces 4.0: jakartaee/faces#1568 |
1) Environment
2) Expected behavior
No warning by the w3c validator.
3) Actual behavior
If Html 5 is used, the validator is complaining that the attribute 'type="text/javascript"' is unnecessary.
4) Steps to reproduce
Let the validator validate the primefaces showcase.
https://validator.w3.org/nu/?doc=https%3A%2F%2Fwww.primefaces.org%2Fshowcase%2F
I can provide a PR, but I do not know what would be the best solution.
The text was updated successfully, but these errors were encountered: