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

Fix MYFACES-4117 in JSF 2.2 #30415

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -131,9 +131,19 @@ protected FacesConfigImpl createFacesConfig(Map<Class<? extends Annotation>, Set

if (comp.createTag())
{
String tagName = comp.tagName(); // MYFACES-4117
if (tagName != null && tagName.length() > 0)
{
//Ok
}
else //
{
tagName = clazz.getSimpleName();
tagName = Character.toLowerCase(tagName.charAt(0)) + tagName.substring(1);
}
facesConfig.addComponentTagDeclaration(value,
new ComponentTagDeclarationImpl(value,
comp.namespace(), comp.tagName()));
comp.namespace(), tagName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2023 IBM Corporation and others.
* Copyright (c) 2015, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -62,7 +62,8 @@ public static void setup() throws Exception {
"com.ibm.ws.jsf22.fat.componentrenderer.jsf599",
"com.ibm.ws.jsf22.fat.componentrenderer.jsf703",
isEE10 ? "com.ibm.ws.jsf22.fat.componentrenderer.jsf943.bean.faces40" : "com.ibm.ws.jsf22.fat.componentrenderer.jsf943.bean.jsf22",
"com.ibm.ws.jsf22.fat.componentrenderer.jsf997");
"com.ibm.ws.jsf22.fat.componentrenderer.jsf997",
"com.ibm.ws.jsf22.fat.componentrenderer.myfaces4117");

jsfTestServer2.startServer(c.getSimpleName() + ".log");
}
Expand Down Expand Up @@ -288,4 +289,28 @@ public void testJsf599() throws Exception {
assertTrue(page.asText().contains("I'm a place!"));
}
}

/*
* Two items are tested.
* 1) Default tag name is assigned when one is not specified on the @FacesComonent annotation.
* 2) Verifies a custom renderer is used when specified. This was added because we don't have any
* exisiting tests for the @FacesRenderer annotation. The component class doesn't render the element, but
* the renderer class does.
*
*/
@Test
public void testMyFaces4117AndRenderer() throws Exception {
try (WebClient webClient = new WebClient()) {

URL url = JSFUtils.createHttpUrl(jsfTestServer2, contextRoot, "myfaces4117.xhtml");
HtmlPage page = (HtmlPage) webClient.getPage(url);

if (page == null) {
Assert.fail("myfaces4117.xhtml did not render properly.");
}

assertTrue(page.getWebResponse().getContentAsString().contains("Renderer Works!"));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* Copyright (c) 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:g="http://xmlns.jcp.org/jsf/component">
<h:body>
<g:testFacesComponent/>
</h:body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package com.ibm.ws.jsf22.fat.componentrenderer.myfaces4117;

import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

/*
* For MYFACES-4117 - No specific tag name is specified, so "testFacesComponent"
* will be used instead.
*/
@FacesComponent(value=TestFacesComponent.COMPONENT_TYPE, createTag=true)
public class TestFacesComponent extends UIComponentBase {


public static final String COMPONENT_FAMILY = "test.component";
public static final String COMPONENT_TYPE = "custom.type";

public TestFacesComponent() {
setRendererType("test.renderer");
}
@Override
public String getFamily() {
return COMPONENT_FAMILY;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package com.ibm.ws.jsf22.fat.componentrenderer.myfaces4117;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.FacesRenderer;
import javax.faces.render.Renderer;

/*
* No existing FATS use @FacesRenderer, so this is added to verify the annotation works.
*/
@FacesRenderer(componentFamily="test.component", rendererType="test.renderer")
public class TestFacesRenderer extends Renderer {

public static final String RENDERER_TYPE = "test.renderer";

@Override
public boolean getRendersChildren() {
return super.getRendersChildren();
}

@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
System.out.println("Within TestFacesRenderer#encodeBegin");
ResponseWriter writer = context.getResponseWriter();
writer.startElement("div",component);
writer.writeText("Renderer Works!", null);
super.encodeBegin(context, component);
}

@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
System.out.println("Within TestFacesRenderer#encodeEnd");
ResponseWriter writer = context.getResponseWriter();
writer.endElement("div");
super.encodeEnd(context, component);
}

}