users@javaserverfaces-spec-public.java.net

[jsr344-experts mirror] [jsr344-experts] Re: [1089-HTML5-data-*attributes] PROPOSAL

From: Andy Schwartz <andy.schwartz_at_oracle.com>
Date: Wed, 16 May 2012 12:42:07 -0400

Ed -

I find the use of JSON here very confusing and unnecessarily complex.

Two simpler options that I would prefer:

1. Enhance f:attribute to allow pass-thru of data- attributes, eg:

<h:outputText>
<f:attribute name="data-andy-rocks" value="false"/>
</h:outputText>

Thinking the <f:attribute> handler would populate a map that hangs off
of the component's attribute map. Renderers would be required to
iterate over this map and blast out all of attributes.

2. Add a new f:dataAttribute tag, eg:

If we prefer not to complicate <f:attribute>, we could do:

<h:outputText>
<f:dataAttribute name="andy-rocks" value="false"/>
</h:outputText>

With a similar implementation.

Ideally either/both of these would support EL-binding, eg:

<h:outputText>
<f:dataAttribute name="andy-rocks" value="#{bean.doesAndyRockYet}"/>
</h:outputText>

Regarding:

> If the view being rendered is not HTML5, the value of this attribute
> must be ignored.

I would lean towards passing these through regardless of the target
markup language. Although data- attributes are not strictly valid
pre-HTML5, simply dropping these might make life more difficult for an
app developer who needs to target a range of browsers (including both
HTML5 and pre-HTML5 browsers).

Andy

On 5/16/12 12:08 PM, Edward Burns wrote:
> - Add support for HTML5 data-* attributes to the HTML_BASIC renderkit.
> This attribute is valid on any h: component. Here is the
> specification.
>
> This is for an attribute called "data" which will be on all h: components.
>
> If the view being rendered is not HTML5, the value of this attribute
> must be ignored. Otherwise, determine the correct markup element to host
> the data- attribute(s). This markup element will always be the
> outer-most markup element corresponding precisely to this component
> instance. If necessary, a<div> or a<span> must be rendered to host the
> data- attribute(s), depending on whether or not the component is,
> itself, block or inline in nature.
>
> Interpret the value of the attribute as a JSON string.
>
> If none of the right hand side values in the JSON string is itself a
> JSON object, for each name : value pair in the JSON object output
> data-[name]="[value]", where name is the name from the name : value
> pair, and value is the value from the name : value pair.
>
> If any of the right hand side values in the JSON string is a JSON object
> render the attributes according to the following algorithm. Let
> nameStack be a stack data structure. Let jsonObj be a JSON object
> comprised of jsonName and jsonValue. Parse the value of the attribute as
> JSON into jsonObj. Push jsonName onto nameStack. If jsonValue is a JSON
> object, recursively apply the algorithm. Otherwise, render a data-
> attribute with the name data-stackExplode, where stackExplode is a
> printout of the entire stack, starting with the literal string "data-"
> and followed by each element in the stack, separated by "-". The value
> of such a data- attribute is jsonValue, enclosed in quotes. When all the
> values for the current jsonName have been handled, pop jsonName from the
> nameStack.
>
> Consider this example.
>
> <h:outputText data="{ a : { b : { c : { d : e, f : g }, h, { i : { j : { k : l } } } } } }" value="foo"/>
>
> This would be rendered as
>
> <span data-a-b-c-d="e" data-a-b-c-f="g" data-a-b-c="h"
> data-a-b-c-i-j-k="l">foo</span>
>
> SECTION: Modified Files
> ----------------------------
> M jsf-tools/src/main/java/com/sun/faces/generate/HtmlTaglib21Generator.java
>
> - Fix the component generation so that ivar names don't conflict with
> this new attribute.
>
> M jsf-ri/src/main/java/com/sun/faces/renderkit/html_basic/TextRenderer.java
> M jsf-ri/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java
> M jsf-api/doc/standard-html-renderkit.xml
> M jsf-api/doc/core-props.xml
>
> - Implement this in the textrenderer.
>
> - Further work must be done to verify this works for all h: components.
> This is tracked in<http://java.net/jira/browse/JAVASERVERFACES-2418>.
>
> M jsf-ri/mojarra-jsf-impl.bnd
> M nbproject/project.xml
> M common/ant/dependencies.xml
> M common/ant/common.xml
>
> - Introduce dependency on jettison JSON software. This is acceptable
> because GlassFish is already using it.
>
> A + test/agnostic/renderKit/basic/src/test/java/com/sun/faces/test/agnostic/renderKit/basic/Issue1089IT.java
> A + test/agnostic/renderKit/basic/src/main/webapp/data-attributes.xhtml
>
> - Test in one case, h:outputText.
> Sending common/ant/common.xml
> Sending common/ant/dependencies.xml
> Sending jsf-api/doc/core-props.xml
> Sending jsf-api/doc/standard-html-renderkit.xml
> Sending jsf-ri/mojarra-jsf-impl.bnd
> Sending jsf-ri/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java
> Sending jsf-ri/src/main/java/com/sun/faces/renderkit/html_basic/TextRenderer.java
> Sending jsf-tools/src/main/java/com/sun/faces/generate/HtmlTaglib21Generator.java
> Sending nbproject/project.xml
> Adding test/agnostic/renderKit/basic/src/main/webapp/data-attributes.xhtml
> Adding test/agnostic/renderKit/basic/src/test/java/com/sun/faces/test/agnostic/renderKit/basic/Issue1089IT.java
> Transmitting file data ...........
> Committed revision 9947.
>
>