You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by vo...@apache.org on 2022/09/26 01:36:29 UTC
[myfaces] branch main updated: MYFACES-4462: Generate script tag
This is an automated email from the ASF dual-hosted git repository.
volosied pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/main by this push:
new 4e27b0068 MYFACES-4462: Generate script tag
new d06c5ab60 Merge pull request #319 from volosied/MYFACES-4462
4e27b0068 is described below
commit 4e27b0068b763738f7994cac443b0c22fde610f1
Author: Volodymyr Siedlecki <vo...@gmail.com>
AuthorDate: Fri Sep 23 12:19:08 2022 -0400
MYFACES-4462: Generate script tag
---
.../html/base/HtmlButtonRendererBase.java | 5 +++
.../renderkit/html/util/HtmlJavaScriptUtils.java | 39 ++++++++++++++++++++++
.../renderkit/html/util/HtmlRendererUtils.java | 7 ++++
3 files changed, 51 insertions(+)
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlButtonRendererBase.java b/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlButtonRendererBase.java
index 22f7e4d18..ec08b2a60 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlButtonRendererBase.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/base/HtmlButtonRendererBase.java
@@ -139,6 +139,11 @@ public class HtmlButtonRendererBase extends HtmlRenderer
List<UIParameter> validParams = HtmlRendererUtils.getValidUIParameterChildren(
facesContext, getChildren(uiComponent), false, false);
+ if (form != null && (validParams != null && !validParams.isEmpty()))
+ {
+ HtmlRendererUtils.renderFormSubmitScript(facesContext);
+ }
+
String commandOnclick = (String)uiComponent.getAttributes().get(HTML.ONCLICK_ATTR);
if (commandOnclick != null && (validParams != null && !validParams.isEmpty()))
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlJavaScriptUtils.java b/impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlJavaScriptUtils.java
index a12060cc3..adf6c4c73 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlJavaScriptUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlJavaScriptUtils.java
@@ -18,14 +18,53 @@
*/
package org.apache.myfaces.renderkit.html.util;
+import java.io.IOException;
+import java.util.Map;
import java.util.logging.Logger;
import jakarta.faces.context.FacesContext;
+import jakarta.faces.context.ResponseWriter;
public final class HtmlJavaScriptUtils
{
private static final Logger log = Logger.getLogger(HtmlJavaScriptUtils.class.getName());
+ private static final String FIRST_SUBMIT_SCRIPT_ON_PAGE = "org.apache.MyFaces.FIRST_SUBMIT_SCRIPT_ON_PAGE";
+
+ @SuppressWarnings("unchecked")
+ public static void renderFormSubmitScript(FacesContext facesContext)
+ throws IOException
+ {
+ if (facesContext.getPartialViewContext() != null &&
+ (facesContext.getPartialViewContext().isPartialRequest() ||
+ facesContext.getPartialViewContext().isAjaxRequest() )
+ )
+ {
+ return;
+ }
+
+ Map map = facesContext.getExternalContext().getRequestMap();
+ Boolean firstScript = (Boolean) map.get(FIRST_SUBMIT_SCRIPT_ON_PAGE);
+
+ if (firstScript == null || firstScript.equals(Boolean.TRUE))
+ {
+ map.put(FIRST_SUBMIT_SCRIPT_ON_PAGE, Boolean.FALSE);
+ renderFormSubmitScriptIfNecessary(facesContext);
+ }
+ }
+
+ /**
+ * @param facesContext
+ * @throws IOException
+ */
+ private static void renderFormSubmitScriptIfNecessary(
+ FacesContext facesContext) throws IOException
+ {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ ResourceUtils
+ .renderDefaultJsfJsInlineIfNecessary(facesContext, writer);
+ }
+
public static void appendClearHiddenCommandFormParamsFunctionCall(
StringBuilder buf, String formName)
{
diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlRendererUtils.java b/impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlRendererUtils.java
index 8beca683d..049414355 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlRendererUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/util/HtmlRendererUtils.java
@@ -1078,6 +1078,13 @@ public final class HtmlRendererUtils
HtmlJavaScriptUtils.appendClearHiddenCommandFormParamsFunctionCall(buf, formName);
}
+ @SuppressWarnings("unchecked")
+ public static void renderFormSubmitScript(FacesContext facesContext)
+ throws IOException
+ {
+ HtmlJavaScriptUtils.renderFormSubmitScript(facesContext);
+ }
+
public static void renderHiddenCommandFormParams(ResponseWriter writer,
Set dummyFormParams) throws IOException
{