Skip to content

Commit d55a7ba

Browse files
authored
Merge pull request #5627 from eclipse-ee4j/issue_5625
#5625: improved fix for #5059
2 parents 5815d9a + 6fd2256 commit d55a7ba

10 files changed

Lines changed: 209 additions & 15 deletions

File tree

impl/src/main/java/com/sun/faces/facelets/impl/DefaultFacelet.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@
2727
import java.util.Date;
2828
import java.util.Iterator;
2929
import java.util.List;
30-
import java.util.Map;
3130
import java.util.logging.Level;
3231
import java.util.logging.Logger;
3332

34-
import com.sun.faces.facelets.tag.faces.ComponentSupport;
35-
import com.sun.faces.util.FacesLogger;
36-
import com.sun.faces.util.Util;
37-
3833
import jakarta.el.ELException;
3934
import jakarta.el.ExpressionFactory;
4035
import jakarta.faces.FacesException;
4136
import jakarta.faces.application.ProjectStage;
4237
import jakarta.faces.component.Doctype;
38+
import jakarta.faces.component.TransientStateHelper;
4339
import jakarta.faces.component.UIComponent;
4440
import jakarta.faces.context.FacesContext;
4541
import jakarta.faces.view.facelets.Facelet;
4642
import jakarta.faces.view.facelets.FaceletContext;
4743
import jakarta.faces.view.facelets.FaceletException;
4844
import jakarta.faces.view.facelets.FaceletHandler;
4945

46+
import com.sun.faces.facelets.tag.faces.ComponentSupport;
47+
import com.sun.faces.util.FacesLogger;
48+
import com.sun.faces.util.Util;
49+
5050
/**
5151
* Default Facelet implementation.
5252
*
@@ -150,7 +150,7 @@ private void refresh(UIComponent c) {
150150
while (--sz >= 0) {
151151
UIComponent cc = (UIComponent) cl.get(sz);
152152
if (!cc.isTransient()) {
153-
token = (ApplyToken) cc.getAttributes().get(APPLIED_KEY);
153+
token = (ApplyToken) cc.getTransientStateHelper().getTransient(APPLIED_KEY);
154154
if (token != null && token.time < createTime && token.alias.equals(alias)) {
155155
if (log.isLoggable(Level.INFO)) {
156156
DateFormat df = SimpleDateFormat.getTimeInstance();
@@ -171,7 +171,7 @@ private void refresh(UIComponent c) {
171171
for (Iterator itr = col.iterator(); itr.hasNext();) {
172172
fc = (UIComponent) itr.next();
173173
if (!fc.isTransient()) {
174-
token = (ApplyToken) fc.getAttributes().get(APPLIED_KEY);
174+
token = (ApplyToken) fc.getTransientStateHelper().getTransient(APPLIED_KEY);
175175
if (token != null && token.time < createTime && token.alias.equals(alias)) {
176176
if (log.isLoggable(Level.INFO)) {
177177
DateFormat df = SimpleDateFormat.getTimeInstance();
@@ -193,9 +193,9 @@ private void markApplied(UIComponent parent) {
193193
while (itr.hasNext()) {
194194
UIComponent c = (UIComponent) itr.next();
195195
if (!c.isTransient()) {
196-
Map<String, Object> attr = c.getAttributes();
197-
if (!attr.containsKey(APPLIED_KEY)) {
198-
attr.put(APPLIED_KEY, token);
196+
TransientStateHelper state = c.getTransientStateHelper();
197+
if (state.getTransient(APPLIED_KEY) == null) {
198+
state.putTransient(APPLIED_KEY, token);
199199
}
200200
}
201201
}

impl/src/main/java/jakarta/faces/component/ComponentStateHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ public void add(Serializable key, Object value) {
232232
}
233233

234234
private void initList(Serializable key) {
235+
if (component.initialStateMarked()) {
236+
deltaMap.computeIfAbsent(key, e -> new ArrayList<>(4));
237+
}
238+
235239
if (get(key) == null) {
236240
List<Object> items = new ArrayList<>(4);
237241
defaultMap.put(key, items);
238242
}
239-
240-
if (component.initialStateMarked()) {
241-
deltaMap.computeIfAbsent(key, e -> new ArrayList<>((List<Object>) get(key)));
242-
}
243243
}
244244

245245
/**

impl/src/test/java/jakarta/faces/component/UIComponentBaseTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public void testAttributesThatAreSetStateHolder() throws Exception {
375375
c.pushComponentToEL(facesContext, c);
376376
c.restoreState(facesContext, state);
377377
c.popComponentFromEL(facesContext);
378-
assertEquals(Arrays.asList("attr1", "attr2"), c.getAttributes().get("jakarta.faces.component.UIComponentBase.attributesThatAreSet"));
378+
assertEquals(Arrays.asList("attr2"), c.getAttributes().get("jakarta.faces.component.UIComponentBase.attributesThatAreSet"));
379379
}
380380

381381
@Test

test/issue5059/pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) Contributors to Eclipse Foundation.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<parent>
23+
<groupId>org.eclipse.mojarra.test</groupId>
24+
<artifactId>pom</artifactId>
25+
<version>4.0.14-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>issue5059</artifactId>
29+
<packaging>war</packaging>
30+
31+
<name>Mojarra ${project.version} - INTEGRATION TESTS - ${project.artifactId}</name>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.eclipse.mojarra.test</groupId>
36+
<artifactId>base</artifactId>
37+
<version>${project.version}</version>
38+
<scope>test</scope>
39+
</dependency>
40+
</dependencies>
41+
</project>

test/issue5059/src/main/webapp/WEB-INF/beans.xml

Whitespace-only changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) Contributors to Eclipse Foundation.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
<web-app
20+
xmlns="https://jakarta.ee/xml/ns/jakartaee"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
23+
version="5.0"
24+
>
25+
<context-param>
26+
<param-name>jakarta.faces.FACELETS_REFRESH_PERIOD</param-name>
27+
<param-value>1</param-value>
28+
</context-param>
29+
30+
<servlet>
31+
<servlet-name>facesServlet</servlet-name>
32+
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
33+
<load-on-startup>1</load-on-startup>
34+
</servlet>
35+
<servlet-mapping>
36+
<servlet-name>facesServlet</servlet-name>
37+
<url-pattern>*.xhtml</url-pattern>
38+
</servlet-mapping>
39+
</web-app>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<!--
3+
4+
Copyright (c) Contributors to Eclipse Foundation.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
<html
20+
xmlns:h="jakarta.faces.html"
21+
xmlns:ui="jakarta.faces.facelets"
22+
>
23+
<h:head>
24+
<title>issue 5059</title>
25+
</h:head>
26+
<h:body>
27+
<ui:include src="issue5059include.xhtml" />
28+
29+
<h:form id="form" style="font-size: 8px;">
30+
<h:commandButton id="submit" value="Click Here" />
31+
</h:form>
32+
</h:body>
33+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<!--
3+
4+
Copyright (c) Contributors to Eclipse Foundation.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
<ui:composition
20+
xmlns="http://www.w3.org/1999/xhtml"
21+
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
22+
>
23+
<p>include</p>
24+
</ui:composition>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) Contributors to the Eclipse Foundation.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* This Source Code may also be made available under the following Secondary
10+
* Licenses when the conditions for such availability set forth in the Eclipse
11+
* Public License v. 2.0 are satisfied: GPL-2.0 with Classpath-exception-2.0 which
12+
* is available at https://openjdk.java.net/legal/gplv2+ce.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 or Apache-2.0
15+
*/
16+
package org.eclipse.mojarra.test.issue5059;
17+
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
19+
20+
import org.eclipse.mojarra.test.base.BaseIT;
21+
import org.junit.jupiter.api.Test;
22+
import org.openqa.selenium.By;
23+
24+
class Issue5059IT extends BaseIT {
25+
26+
/**
27+
* https://github.com/eclipse-ee4j/mojarra/issues/5059
28+
*/
29+
@Test
30+
void test() {
31+
open("issue5059.xhtml");
32+
assertStyleAttributePresent();
33+
34+
// submit form, the style attribute should be there
35+
submitForm();
36+
assertStyleAttributePresent();
37+
38+
// submit form once more, the style should still be there, this did not happen before 5059 fix
39+
submitForm();
40+
assertStyleAttributePresent();
41+
42+
// yet once more, just to be on the safe side
43+
submitForm();
44+
assertStyleAttributePresent();
45+
}
46+
47+
private void submitForm() {
48+
guardHttp(browser.findElement(By.id("form:submit"))::click);
49+
}
50+
51+
private void assertStyleAttributePresent() {
52+
String style = browser.findElement(By.id("form")).getAttribute("style");
53+
assertTrue(style != null && !style.trim().isEmpty());
54+
}
55+
56+
}

test/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<module>base</module>
3636
<module>example_jar_with_metadata_complete_false</module>
3737
<module>example_jar_with_metadata_complete_true</module>
38+
<module>issue5059</module>
3839
<module>issue5460</module>
3940
<module>issue5464</module>
4041
<module>issue5488</module>

0 commit comments

Comments
 (0)