Skip to content
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

Add back id attribute to VDL of h:head and h:body #5186

Merged
merged 5 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public void decode(FacesContext context, UIComponent component) {
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("body", component);
writeIdAttributeIfNecessary(context, writer, component);
if (RenderKitUtils.isOutputHtml5Doctype(context)) {
writeIdAttributeIfNecessary(context, writer, component);
}
String styleClass = (String) component.getAttributes().get("styleClass");
if (styleClass != null && styleClass.length() != 0) {
writer.writeAttribute("class", styleClass, "styleClass");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import jakarta.faces.component.UIViewRoot;
import jakarta.faces.context.FacesContext;
import jakarta.faces.context.ResponseWriter;
import jakarta.faces.render.Renderer;

/**
* /**
Expand All @@ -35,7 +34,7 @@
* resources that should be output before the <code>head</code> tag is closed.
* </p>
*/
public class HeadRenderer extends Renderer {
public class HeadRenderer extends HtmlBasicRenderer {

private static final Attribute[] HEAD_ATTRIBUTES = AttributeManager.getAttributes(AttributeManager.Key.OUTPUTHEAD);

Expand All @@ -48,12 +47,10 @@ public void decode(FacesContext context, UIComponent component) {
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("head", component);
RenderKitUtils.renderPassThruAttributes(context, writer, component, HEAD_ATTRIBUTES);

if (RenderKitUtils.isOutputHtml5Doctype(context)) {
String clientId = component.getClientId(context);
writer.writeAttribute("id", clientId, "clientId");
writeIdAttributeIfNecessary(context, writer, component);
}
RenderKitUtils.renderPassThruAttributes(context, writer, component, HEAD_ATTRIBUTES);
}

@Override
Expand All @@ -68,6 +65,16 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
writer.endElement("head");
}

/**
* Do we render our children.
*
* @return false.
*/
@Override
public boolean getRendersChildren() {
return false;
}

// --------------------------------------------------------- Private Methods

private void encodeHeadResources(FacesContext context) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,20 @@
<component-type>jakarta.faces.Output</component-type>
<renderer-type>jakarta.faces.Head</renderer-type>
</component>
<attribute>
<description>
<![CDATA[
<span class="changed_added_4_1">
The component identifier for this component.
This value must be unique within the closest parent component that is a naming container.
The attribute is only rendered when the current doctype is a HTML5 doctype.
</span>
]]>
</description>
<name>id</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description>
<![CDATA[Direction indication for text that does not inherit directionality.
Expand Down Expand Up @@ -1278,6 +1292,20 @@
<component-type>jakarta.faces.Output</component-type>
<renderer-type>jakarta.faces.Body</renderer-type>
</component>
<attribute>
<description>
<![CDATA[
<span class="changed_added_4_1">
The component identifier for this component.
This value must be unique within the closest parent component that is a naming container.
The attribute is only rendered when the current doctype is a HTML5 doctype.
</span>
]]>
</description>
<name>id</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description>
<![CDATA[Direction indication for text that does not inherit directionality.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@

package com.sun.faces.renderkit.html_basic;

import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.StringWriter;
import java.util.Collections;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.easymock.EasyMock.expect;
import org.junit.Test;
import org.powermock.api.easymock.PowerMock;

import jakarta.faces.application.Application;
import jakarta.faces.application.ProjectStage;
import jakarta.faces.component.Doctype;
import jakarta.faces.component.UIViewRoot;
import jakarta.faces.component.html.HtmlBody;
import jakarta.faces.context.FacesContext;
Expand Down Expand Up @@ -56,11 +58,18 @@ public void testEncodeBegin() throws Exception {
StringWriter writer = new StringWriter();
ResponseWriter testResponseWriter = new TestResponseWriter(writer);
FacesContext facesContext = PowerMock.createPartialMock(FacesContext.class, "getResponseWriter");
UIViewRoot viewRoot = PowerMock.createMock(UIViewRoot.class);
Doctype doctype = PowerMock.createMock(Doctype.class);
BodyRenderer bodyRenderer = new BodyRenderer();
HtmlBody htmlBody = new HtmlBody();
htmlBody.getAttributes().put("styleClass", "myclass");

expect(facesContext.getResponseWriter()).andReturn(testResponseWriter).anyTimes();
expect(facesContext.getViewRoot()).andReturn(viewRoot).anyTimes();
expect(viewRoot.getDoctype()).andReturn(doctype).anyTimes();
expect(doctype.getRootElement()).andReturn("html").anyTimes();
expect(doctype.getPublic()).andReturn(null).anyTimes();
expect(doctype.getSystem()).andReturn(null).anyTimes();

PowerMock.replay(facesContext);
bodyRenderer.encodeBegin(facesContext, htmlBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@

package com.sun.faces.renderkit.html_basic;

import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertTrue;

import java.io.StringWriter;
import java.util.Collections;

import static org.junit.Assert.assertTrue;
import static org.easymock.EasyMock.expect;
import org.junit.Test;
import org.powermock.api.easymock.PowerMock;

import jakarta.faces.component.Doctype;
import jakarta.faces.component.UIViewRoot;
import jakarta.faces.component.html.HtmlHead;
import jakarta.faces.context.FacesContext;
Expand All @@ -50,13 +52,26 @@ public void testDecode() {
*/
@Test
public void testEncodeBegin() throws Exception {
//
// TODO: Note we are not testing this method as its complexity is too
// high, because it uses WebConfiguration.getInstance to get
// configuration information that should be readily available to the
// renderer through either the FacesContext or the component being
// rendered.
//
StringWriter writer = new StringWriter();
ResponseWriter testResponseWriter = new TestResponseWriter(writer);
FacesContext facesContext = PowerMock.createPartialMock(FacesContext.class, "getResponseWriter");
UIViewRoot viewRoot = PowerMock.createMock(UIViewRoot.class);
Doctype doctype = PowerMock.createMock(Doctype.class);
HeadRenderer headRenderer = new HeadRenderer();
HtmlHead htmlHead = new HtmlHead();

expect(facesContext.getResponseWriter()).andReturn(testResponseWriter).anyTimes();
expect(facesContext.getViewRoot()).andReturn(viewRoot).anyTimes();
expect(viewRoot.getDoctype()).andReturn(doctype).anyTimes();
expect(doctype.getRootElement()).andReturn("html").anyTimes();
expect(doctype.getPublic()).andReturn(null).anyTimes();
expect(doctype.getSystem()).andReturn(null).anyTimes();

PowerMock.replay(facesContext);
headRenderer.encodeBegin(facesContext, htmlHead);
PowerMock.verify(facesContext);
String html = writer.toString();
assertTrue(html.contains("<head"));
}

/**
Expand Down