Skip to content

Commit 7fc49d6

Browse files
authored
Merge pull request #5732 from jasondlee/inline-js
Backport of inline js for non-CSP apps
2 parents 9ef2238 + 565b49a commit 7fc49d6

11 files changed

Lines changed: 272 additions & 23 deletions

File tree

impl/pom.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@
338338
<plugin>
339339
<groupId>org.apache.maven.plugins</groupId>
340340
<artifactId>maven-surefire-plugin</artifactId>
341-
<version>3.0.0-M5</version>
341+
<version>3.5.5</version>
342342
<configuration>
343343
<trimStackTrace>false</trimStackTrace>
344344
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
@@ -479,7 +479,7 @@
479479
<plugin>
480480
<groupId>org.apache.maven.plugins</groupId>
481481
<artifactId>maven-jar-plugin</artifactId>
482-
<version>3.2.2</version>
482+
<version>3.5.0</version>
483483
<configuration>
484484
<archive>
485485
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
@@ -490,12 +490,11 @@
490490
</excludes>
491491
</configuration>
492492
</plugin>
493-
494493
<!-- Creates the source jar -->
495494
<plugin>
496495
<groupId>org.apache.maven.plugins</groupId>
497496
<artifactId>maven-source-plugin</artifactId>
498-
<version>3.2.1</version>
497+
<version>3.4.0</version>
499498
<executions>
500499
<execution>
501500
<id>attach-sources</id>
@@ -512,7 +511,7 @@
512511
<plugin>
513512
<groupId>org.apache.maven.plugins</groupId>
514513
<artifactId>maven-javadoc-plugin</artifactId>
515-
<version>3.3.1</version>
514+
<version>3.12.0</version>
516515
<executions>
517516
<execution>
518517
<id>attach-javadocs</id>
@@ -545,7 +544,7 @@
545544
<plugin>
546545
<groupId>org.codehaus.mojo</groupId>
547546
<artifactId>flatten-maven-plugin</artifactId>
548-
<version>1.7.0</version>
547+
<version>1.7.3</version>
549548
<configuration>
550549
<flattenMode>ossrh</flattenMode>
551550
</configuration>

impl/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ private static void renderValueChangeEventListener(FacesContext context, UICompo
426426
? Collections.singletonList(new ClientBehaviorContext.Parameter("incExec", true))
427427
: Collections.emptyList();
428428

429-
addBehaviorEventListener(context, component, clientId, params, handlerName, userHandler, behaviorEventName, domEventName, null, false, incExec, true);
429+
addBehaviorEventListener(context, component, clientId, params, handlerName, userHandler, behaviorEventName, domEventName, null, false, incExec,
430+
ResourceHandlerImpl.resolveCurrentNonce(context) != null, true);
430431
}
431432

432433
// Renders the onclick event listener for command buttons. Handles
@@ -452,7 +453,8 @@ public static void renderOnclickEventListener(FacesContext context, UIComponent
452453
}
453454
}
454455

455-
addBehaviorEventListener(context, component, null, params, handlerName, userHandler, behaviorEventName, domEventName, submitTarget, needsSubmit, false, true);
456+
addBehaviorEventListener(context, component, null, params, handlerName, userHandler, behaviorEventName, domEventName, submitTarget, needsSubmit, false,
457+
ResourceHandlerImpl.resolveCurrentNonce(context) != null, true);
456458

457459
}
458460

@@ -657,7 +659,8 @@ private static void renderPassThruAttributesOptimized(FacesContext context, Resp
657659
Attribute attr = knownAttributes[index];
658660

659661
if (isBehaviorEventAttribute(attr, behaviorEventName)) {
660-
addBehaviorEventListener(context, component, null, null, name, value, behaviorEventName, behaviorEventName, null, false, false, false);
662+
addBehaviorEventListener(context, component, null, null, name, value, behaviorEventName, behaviorEventName, null, false, false,
663+
ResourceHandlerImpl.resolveCurrentNonce(context) != null, false);
661664

662665
renderedBehavior = true;
663666
} else {
@@ -669,7 +672,8 @@ else if (isBehaviorEventAttribute(name)) {
669672
Object value = attrMap.get(name);
670673
if (value != null && shouldRenderAttribute(value)) {
671674
if (name.substring(2).equals(behaviorEventName)) {
672-
addBehaviorEventListener(context, component, null, null, name, value, behaviorEventName, behaviorEventName, null, false, false, false);
675+
addBehaviorEventListener(context, component, null, null, name, value, behaviorEventName, behaviorEventName, null, false, false,
676+
ResourceHandlerImpl.resolveCurrentNonce(context) != null, false);
673677

674678
renderedBehavior = true;
675679
} else {
@@ -700,7 +704,8 @@ else if (isBehaviorEventAttribute(name)) {
700704
String attrName = attribute.getName();
701705
String[] events = attribute.getEvents();
702706
if (events != null && events.length > 0 && behaviorEventName.equals(events[0])) {
703-
addBehaviorEventListener(context, component, null, null, attrName, null, behaviorEventName, behaviorEventName, null, false, false, false);
707+
addBehaviorEventListener(context, component, null, null, attrName, null, behaviorEventName, behaviorEventName, null, false, false,
708+
ResourceHandlerImpl.resolveCurrentNonce(context) != null, false);
704709
return;
705710
}
706711
}
@@ -762,7 +767,8 @@ private static void renderPassthruAttribute(FacesContext context, ResponseWriter
762767
// If we've got a behavior for this attribute,
763768
// we may need to chain scripts together, so use
764769
// renderEventListener().
765-
addBehaviorEventListener(context, component, null, null, attrName, value, eventName, eventName, null, false, false, false);
770+
addBehaviorEventListener(context, component, null, null, attrName, value, eventName, eventName, null, false, false,
771+
ResourceHandlerImpl.resolveCurrentNonce(context) != null, false);
766772
}
767773
}
768774

@@ -1672,7 +1678,8 @@ private static boolean isSubmitting(ClientBehavior behavior) {
16721678
* render the submit script to make the link submit.
16731679
*/
16741680
private static void addBehaviorEventListener(FacesContext context, UIComponent component, String clientId, Collection<ClientBehaviorContext.Parameter> params, String handlerName,
1675-
Object handlerValue, String behaviorEventName, String domEventName, String submitTarget, boolean needsSubmit, boolean includeExec, boolean flushPendingBehaviorEventListeners) throws IOException {
1681+
Object handlerValue, String behaviorEventName, String domEventName, String submitTarget, boolean needsSubmit, boolean includeExec,
1682+
boolean renderAsEventListener, boolean flushPendingBehaviorEventListeners) throws IOException {
16761683

16771684
String userHandler = getNonEmptyUserHandler(handlerValue);
16781685
List<ClientBehavior> behaviors = getClientBehaviors(component, behaviorEventName);
@@ -1706,6 +1713,13 @@ private static void addBehaviorEventListener(FacesContext context, UIComponent c
17061713
assert false;
17071714
}
17081715

1716+
if (!renderAsEventListener) {
1717+
if (handler != null) {
1718+
context.getResponseWriter().writeAttribute(handlerName, handler, null);
1719+
}
1720+
return;
1721+
}
1722+
17091723
if (flushPendingBehaviorEventListeners) {
17101724
flushPendingBehaviorEventListeners(context, component, clientId);
17111725
}

impl/src/main/java/com/sun/faces/renderkit/html_basic/ButtonRenderer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import jakarta.faces.event.ActionEvent;
3232

3333
import com.sun.faces.RIConstants;
34+
import com.sun.faces.application.resource.ResourceHandlerImpl;
3435
import com.sun.faces.renderkit.Attribute;
3536
import com.sun.faces.renderkit.AttributeManager;
3637
import com.sun.faces.renderkit.RenderKitUtils;
@@ -125,6 +126,10 @@ else if (writer.getContentType().equals(RIConstants.XHTML_CONTENT_TYPE)) {
125126
writer.writeAttribute("class", styleClass, "styleClass");
126127
}
127128

129+
if (ResourceHandlerImpl.resolveCurrentNonce(context) == null) {
130+
RenderKitUtils.renderOnclickEventListener(context, component, getBehaviorParameters(component), null, false);
131+
}
132+
128133
// PENDING(edburns): Prior to i_spec_1111, this element
129134
// was rendered unconditionally
130135

@@ -152,7 +157,9 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
152157
RenderKitUtils.renderFacesJsIfNecessary(context);
153158
}
154159

155-
RenderKitUtils.renderOnclickEventListener(context, component, params, null, false);
160+
if (ResourceHandlerImpl.resolveCurrentNonce(context) != null) {
161+
RenderKitUtils.renderOnclickEventListener(context, component, params, null, false);
162+
}
156163
}
157164

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

impl/src/main/java/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import jakarta.faces.context.ResponseWriter;
3131
import jakarta.faces.event.ActionEvent;
3232

33+
import com.sun.faces.application.resource.ResourceHandlerImpl;
3334
import com.sun.faces.renderkit.Attribute;
3435
import com.sun.faces.renderkit.AttributeManager;
3536
import com.sun.faces.renderkit.RenderKitUtils;
@@ -120,14 +121,16 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
120121
} else {
121122
writer.endElement("a");
122123

123-
String target = (String) component.getAttributes().get("target");
124-
if (target != null) {
125-
target = target.trim();
126-
} else {
127-
target = "";
124+
if (ResourceHandlerImpl.resolveCurrentNonce(context) != null) {
125+
String target = (String) component.getAttributes().get("target");
126+
if (target != null) {
127+
target = target.trim();
128+
} else {
129+
target = "";
130+
}
131+
Collection<ClientBehaviorContext.Parameter> params = getBehaviorParameters(component);
132+
RenderKitUtils.renderOnclickEventListener(context, component, params, target, true);
128133
}
129-
Collection<ClientBehaviorContext.Parameter> params = getBehaviorParameters(component);
130-
RenderKitUtils.renderOnclickEventListener(context, component, params, target, true);
131134
}
132135
}
133136

@@ -165,6 +168,18 @@ protected void renderAsActive(FacesContext context, UIComponent command) throws
165168

166169
RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, command);
167170

171+
if (ResourceHandlerImpl.resolveCurrentNonce(context) == null) {
172+
String target = (String) command.getAttributes().get("target");
173+
if (target != null) {
174+
target = target.trim();
175+
} else {
176+
target = "";
177+
}
178+
179+
Collection<ClientBehaviorContext.Parameter> params = getBehaviorParameters(command);
180+
RenderKitUtils.renderOnclickEventListener(context, command, params, target, true);
181+
}
182+
168183
writeCommonLinkAttributes(writer, command);
169184

170185
// render the current value as link text.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<groupId>org.eclipse.ee4j</groupId>
2626
<artifactId>project</artifactId>
27-
<version>2.0.1</version>
27+
<version>2.0.2</version>
2828
</parent>
2929

3030
<groupId>org.glassfish</groupId>
@@ -67,7 +67,7 @@
6767
<plugin>
6868
<groupId>org.apache.maven.plugins</groupId>
6969
<artifactId>maven-enforcer-plugin</artifactId>
70-
<version>3.0.0</version>
70+
<version>3.6.2</version>
7171
<executions>
7272
<execution>
7373
<id>enforce-maven</id>

test/issue5606/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.18-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>issue5606</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>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
5+
version="4.0"
6+
bean-discovery-mode="annotated">
7+
</beans>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
<servlet>
26+
<servlet-name>facesServlet</servlet-name>
27+
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
28+
<load-on-startup>1</load-on-startup>
29+
</servlet>
30+
<servlet-mapping>
31+
<servlet-name>facesServlet</servlet-name>
32+
<url-pattern>*.xhtml</url-pattern>
33+
</servlet-mapping>
34+
</web-app>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 lang="en"
20+
xmlns:f="jakarta.faces.core"
21+
xmlns:h="jakarta.faces.html"
22+
>
23+
<h:head>
24+
<title>issue5606</title>
25+
</h:head>
26+
<h:body>
27+
<h:form id="form">
28+
<h:commandLink id="link" value="commandLink" />
29+
<h:outputText id="executed" value="#{not empty param['form:link']}" />
30+
<h:commandButton id="ajaxButton" value="ajaxButton">
31+
<f:ajax render="ajaxExecuted" />
32+
</h:commandButton>
33+
<h:panelGroup id="ajaxExecuted">
34+
<h:outputText value="#{facesContext.partialViewContext.ajaxRequest ? 'true' : 'false'}" />
35+
</h:panelGroup>
36+
</h:form>
37+
</h:body>
38+
</html>

0 commit comments

Comments
 (0)