Does Primefaces render invalid HTML? - html

To build a very simple web app for my company I'm evaluating some web frameworks, including PrimeFaces.
One strict requirement is the accessibility, and the fact that the HTML must be valid (checked against W3C Validator).
I've played a bit with the examples and I've noticed that the HTML rendered is not valid. The invalid block is the following:
<input name="javax.faces.ViewState" id="javax.faces.ViewState" value="2042368857675116551:8104174386673838460" autocomplete="off" type="hidden">
and the reason is:
line 74 column 159 - Errore: Attribute autocomplete not allowed on element input at this point.
So, can I perform some action on Primefaces in order to render valid HTML code? I didn't go deep into Primefaces, but I guess I have little control over how controls are rendered. Has anyone experience on this problem (validity of HTML rendered by PF) and would like to share it?
Thanks

The viewstate is not something that PrimeFaces adds to your rendered html but the jsf implementation. If you use mojarra there are some parameters that you can set to tune things (not tested this myself, just did some simple googling for you (hint, hint)).
See in How to let JSF render conform XHTML 1.0 strict?

Related

JSF 2.2 conditionally render HTML5 elements with jsf:rendered attribute

I d like to implement a new page in JSF 2.2 using HTML5 syntax.
My question: How can I achieve that a specific HTML element won't be rendered if jsf:rendered evaluates to false?
Sample:
<span class="msnumber" jsf:id="msnumber" jsf:rendered="#{!empty controller.msnumber}">[#{controller.msnumber}]</span>
Do i need to use a h:outputText for this purpose? I would appreciate it, if I could use the HTML elements directly.
Greets
Marc
There's nothing wrong in using HTML syntax into facelets directly. If you want to control it being rendered or not, your best is to use the <ui:fragment /> tag, which doesn't render anything by itself:
<ui:fragment rendered="#{!empty controller.msnumber}">
<span class="msnumber" id="msnumber">[#{controller.msnumber}]</span>
</ui:fragment>
Will render just
<span class="msnumber" id="msnumber">xx</span>
in case of #{!empty controller.msnumber} evaluating to true.
Regarding to the way you want to achieve it, I'm not sure about adding JSF component specific attributes to HTML tags directly (although being possible the other way). Honestly I've never seen that.
Your approach with the span as pass-through element should definitely work. I tried it in one of my JSF 2.2 projects and it works as intended with MyFaces 2.2.3 and Mojarra 2.2.6.
Do you use MyFaces or Mojarra? Which version? Try to use the most current one. HTML5 support is quite new and there are bugs in older versions of MyFaces and Mojarra.
Another possibility is, that there is something wrong with your EL expression #{!empty controller.msnumber}.

php echo equivalent in JSF

I would like to know if there is a php echo equivalent in JSF. I would like to publish html from my bean to my facelet.
This is because I want to add three different primefaces components each time a user clicks on one of the component that has been added. I could not achieve this with taglibs.
Thank you
I believe you got confused by builtin XSS prevention of JSF which caused your "plain vanilla" HTML to get escaped and thus displayed as-is instead of being interpreted as part of HTML source. Given that you're familiar with PHP, the explanation is that JSF has basically PHP's htmlspecialchars() by default turned on in all EL expressions printing output.
Just use <h:outputText> with escape attribute set to false to turn off implicit HTML escaping.
<h:outputText value="#{bean.html}" escape="false" />
Please make sure that you're fully aware of the potential XSS attack hole created here when it concerns user-controlled input. Your question at its own already indicates that you had no idea of it.
See also:
CSRF, XSS and SQL Injection attack prevention in JSF
Is it suggested to use h:outputText for everything?
As to the concrete functional requirement,
This is because I want to add three different primefaces components each time a user clicks on one of the component that has been added. I could not achieve this with taglibs.
Please note that JSF code is not HTML code. You should instead be writing those JSF components directly in the view and use the rendered attribute to render them conditionally.

JSF inputText required attribute does not render

On JBoss AS 7.1.1 using Moharra JSF 2,
an XHTML file created with an inputText element will not render the attribute required="true".
No errors but the output HTML does not contain the required attribute. If writing pure HTML input element the required attribute renders as part of the JSF form.
Anyone know why this attribute would be stripped out?
The case is a container managed login form so there is no backing bean. Many thanks in advance.
That's expected behavior, that attribute is not for the HTML input tag, but for the required attribute of the UIInput component that stays on the server side.
See these related questions:
JSF 2.0 strips out needed HTML5 attributes
Adding custom attribute (HTML5) support to JSF 2.0 UIInput component

Knockout.js data-bind attribute causes html validation warning

I'm using the HTML Validator firefox add-on and when I go to the home page of http://knockoutjs.com/, I get warnings about the data-bind attribute (for the Live Example):
Examples:
<select> proprietary attribute "data-bind"
<button> proprietary attribute "data-bind"
I also get errors regarding the data-bind attribute when submitting the URL at http://validator.w3.org/.
I know this html attribute is used by knockout.js to do some data binding, but can we conclude that this approach does not follow the HTML specification? Does knockout.js follow the spirit of valid HTML markup?
They are HTML 5 custom attributes. Try to validate against HTML 5 specs and you should get an ok on the validation.
But since long you have been able to use custom attributes as you see fit although it may have violated strict HTML 4 specs.

Help with putting RDF in a web page (jsp)

When I read the documentation on Common-Tags, I thought it would be easy to put this in a jsp because the examples were cut and paste
<body xmlns:ctag="http://commontag.org/ns#" rel="ctag:tagged">
<span typeof="ctag:Tag"
rel="ctag:means"
resource="http://rdf.freebase.com/ns/en.u2"
property="ctag:label" content="U2"/>
</span>
</body>
It's a good thing that we're using Eclipse in our dev work. It's telling us that something is wrong with our markup. It's underlining the common-tags markup with yellow returning:
Undefined attribute name
What am I missing here? or is this completely okay?
The typeof, resource and property attributes are extensions to XHTML which are part of the RDFa specification which is why Eclipse doesn't know about them.
Since RDFa+XHTML is now a W3C recommendation this is absolutely fine to use as is.
http://www.w3.org/TR/rdfa-syntax/#rdfa-attributes
I assume you're not sending your pages with an XML MIME type, because that snippet isn't well-formed. Using RDFa isn't allowed when using a text/html MIME type. For an alternative, have a look at "microdata".