You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2023/11/03 10:34:49 UTC

(myfaces) branch 4.1.x updated: MYFACES-4636

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch 4.1.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/4.1.x by this push:
     new 21db82ada MYFACES-4636
21db82ada is described below

commit 21db82ada5f6c92933b9604ca8d146f66be0fcdb
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Fri Nov 3 11:34:40 2023 +0100

    MYFACES-4636
---
 .../renderkit/html/util/AjaxScriptBuilder.java     |  3 +-
 .../renderkit/html/util/AjaxScriptBuilderTest.java | 92 ++++++++++++++++++++++
 .../apache/myfaces/test/mock/MockApplication.java  |  2 +-
 .../myfaces/test/mock/MockApplication23.java       | 51 ++++++++++++
 4 files changed, 145 insertions(+), 3 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/AjaxScriptBuilder.java b/impl/src/main/java/org/apache/myfaces/renderkit/html/util/AjaxScriptBuilder.java
index 5980da08d..8300333d7 100644
--- a/impl/src/main/java/org/apache/myfaces/renderkit/html/util/AjaxScriptBuilder.java
+++ b/impl/src/main/java/org/apache/myfaces/renderkit/html/util/AjaxScriptBuilder.java
@@ -258,8 +258,7 @@ public class AjaxScriptBuilder
                     }
                 }
                 paramsBuilder.append(R_C_BRACE);
-                sb.append(AJAX_KEY_PARAMS+COLON);
-                sb.append(paramsBuilder);
+                appendProperty(sb, AJAX_KEY_PARAMS, paramsBuilder, false);
             }
 
             sb.append(R_C_BRACE);
diff --git a/impl/src/test/java/org/apache/myfaces/renderkit/html/util/AjaxScriptBuilderTest.java b/impl/src/test/java/org/apache/myfaces/renderkit/html/util/AjaxScriptBuilderTest.java
new file mode 100644
index 000000000..f4f10ea5d
--- /dev/null
+++ b/impl/src/test/java/org/apache/myfaces/renderkit/html/util/AjaxScriptBuilderTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.renderkit.html.util;
+
+import jakarta.faces.FactoryFinder;
+import jakarta.faces.component.UIComponentMock;
+import jakarta.faces.component.behavior.ClientBehaviorContext;
+import jakarta.faces.context.FacesContext;
+import org.apache.myfaces.component.search.*;
+import org.apache.myfaces.test.base.junit.AbstractJsfTestCase;
+import org.apache.myfaces.test.mock.MockApplication;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class AjaxScriptBuilderTest extends AbstractJsfTestCase
+{
+    @BeforeEach
+    @Override
+    public void setUp() throws Exception
+    {
+        super.setUp();
+
+        FactoryFinder.setFactory(FactoryFinder.SEARCH_EXPRESSION_CONTEXT_FACTORY,
+                SearchExpressionContextFactoryImpl.class.getName());
+
+        MockApplication mockApplication = (MockApplication) FacesContext.getCurrentInstance().getApplication();
+        mockApplication.setSearchExpressionHandler(new SearchExpressionHandlerImpl());
+
+        CompositeSearchKeywordResolver baseResolver = new CompositeSearchKeywordResolver();
+        baseResolver.add(new ThisSearchKeywordResolver());
+        baseResolver.add(new ParentSearchKeywordResolver());
+        baseResolver.add(new ChildSearchKeywordResolver());
+        baseResolver.add(new CompositeComponentParentSearchKeywordResolver());
+        baseResolver.add(new FormSearchKeywordResolver());
+        baseResolver.add(new NamingContainerSearchKeywordResolver());
+        baseResolver.add(new NextSearchKeywordResolver());
+        baseResolver.add(new NoneSearchKeywordResolver());
+        baseResolver.add(new PreviousSearchKeywordResolver());
+        baseResolver.add(new RootSearchKeywordResolver());
+        baseResolver.add(new IdSearchKeywordResolver());
+        baseResolver.add(new AllSearchKeywordResolver());
+        mockApplication.setSearchKeywordResolver(baseResolver);
+    }
+
+    @Test
+    public void test()
+    {
+        UIComponentMock component = new UIComponentMock();
+        component.setId("test");
+
+        List<ClientBehaviorContext.Parameter> params = new ArrayList<>();
+        params.add(new ClientBehaviorContext.Parameter("var1", "NEW VALUE"));
+
+        StringBuilder sb = new StringBuilder();
+        AjaxScriptBuilder.build(FacesContext.getCurrentInstance(),
+                sb,
+                component,
+                "j_id_i",
+                "click",
+                Arrays.asList("@this"),
+                null,
+                null,
+                false,
+                null,
+                "testJs",
+                params);
+
+        String script = sb.toString();
+
+        Assertions.assertFalse(script.contains("':testJsparams:{"));
+        Assertions.assertTrue(script.contains("':testJs,'params':{"));
+        Assertions.assertEquals("myfaces.ab('j_id_i',event,'click','test','',{'onevent':testJs,'params':{'var1':'NEW VALUE'}})", script);
+    }
+}
diff --git a/test/src/main/java/org/apache/myfaces/test/mock/MockApplication.java b/test/src/main/java/org/apache/myfaces/test/mock/MockApplication.java
index ce915a2ff..ca4a201f3 100644
--- a/test/src/main/java/org/apache/myfaces/test/mock/MockApplication.java
+++ b/test/src/main/java/org/apache/myfaces/test/mock/MockApplication.java
@@ -27,7 +27,7 @@ package org.apache.myfaces.test.mock;
  * @since 1.0.0
  *
  */
-public class MockApplication extends MockApplication22
+public class MockApplication extends MockApplication23
 {
  
 
diff --git a/test/src/main/java/org/apache/myfaces/test/mock/MockApplication23.java b/test/src/main/java/org/apache/myfaces/test/mock/MockApplication23.java
new file mode 100644
index 000000000..ada12e1ae
--- /dev/null
+++ b/test/src/main/java/org/apache/myfaces/test/mock/MockApplication23.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.test.mock;
+
+import jakarta.faces.component.search.SearchExpressionHandler;
+import jakarta.faces.component.search.SearchKeywordResolver;
+
+public class MockApplication23 extends MockApplication22
+{
+    private SearchExpressionHandler searchExpressionHandler;
+    private SearchKeywordResolver searchKeywordResolver;
+
+    @Override
+    public SearchExpressionHandler getSearchExpressionHandler()
+    {
+        return searchExpressionHandler;
+    }
+
+    @Override
+    public void setSearchExpressionHandler(SearchExpressionHandler searchExpressionHandler)
+    {
+        this.searchExpressionHandler = searchExpressionHandler;
+    }
+
+    @Override
+    public SearchKeywordResolver getSearchKeywordResolver()
+    {
+        return searchKeywordResolver;
+    }
+
+    public void setSearchKeywordResolver(SearchKeywordResolver searchKeywordResolver)
+    {
+        this.searchKeywordResolver = searchKeywordResolver;
+    }
+}