You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/08/16 11:52:12 UTC
svn commit: r985849 [1/3] - in /myfaces: core/trunk/impl/
core/trunk/impl/src/assembler/
core/trunk/impl/src/main/java/org/apache/myfaces/resource/
core/trunk/impl/src/main/javascript/
core/trunk/impl/src/main/javascript/META-INF/ core/trunk/impl/src/m...
Author: jakobk
Date: Mon Aug 16 09:52:11 2010
New Revision: 985849
URL: http://svn.apache.org/viewvc?rev=985849&view=rev
Log:
MYFACES-2858 pointless oamsubmit inline rendering
This is basically Werner's patch, however I moved the oamSubmit javascript from api to impl, because this is a MyFaces impl detail and should not be in api.
Added:
myfaces/core/trunk/impl/src/assembler/
myfaces/core/trunk/impl/src/assembler/myfacesscripts-compiler.xml (with props)
myfaces/core/trunk/impl/src/assembler/myfacesscripts-uncompressed-compiler.xml (with props)
myfaces/core/trunk/impl/src/main/javascript/
myfaces/core/trunk/impl/src/main/javascript/META-INF/
myfaces/core/trunk/impl/src/main/javascript/META-INF/resources/
myfaces/core/trunk/impl/src/main/javascript/META-INF/resources/myfaces/
myfaces/core/trunk/impl/src/main/javascript/META-INF/resources/myfaces/_impl/
myfaces/core/trunk/impl/src/main/javascript/META-INF/resources/myfaces/_impl/oamSubmit.js (with props)
Modified:
myfaces/core/trunk/impl/pom.xml
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ClassLoaderResourceLoader.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlButtonRendererTest.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlLinkRendererTest.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/behavior/AbstractClientBehaviorTestCase.java
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/util/ResourceUtils.java
Modified: myfaces/core/trunk/impl/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/pom.xml?rev=985849&r1=985848&r2=985849&view=diff
==============================================================================
--- myfaces/core/trunk/impl/pom.xml (original)
+++ myfaces/core/trunk/impl/pom.xml Mon Aug 16 09:52:11 2010
@@ -48,6 +48,56 @@
</resources>
<plugins>
<plugin>
+ <artifactId>myfaces-javascript-plugin</artifactId>
+ <groupId>org.apache.myfaces.buildtools</groupId>
+ <version>1.0.1</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>compile-myfacesscripts</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <phase>process-resources</phase>
+ <configuration>
+ <descriptor>${basedir}/src/assembler/myfacesscripts-compiler.xml</descriptor>
+ </configuration>
+ </execution>
+ <execution>
+ <id>compile-myfacesscripts-uncompressed</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <phase>process-resources</phase>
+ <configuration>
+ <descriptor>${basedir}/src/assembler/myfacesscripts-uncompressed-compiler.xml</descriptor>
+ <outputDirectory>${basedir}/target/classes/META-INF/internal-resources/org.apache.myfaces/</outputDirectory>
+ </configuration>
+ </execution>
+ <execution>
+ <id>compress-myfacesscripts</id>
+ <goals>
+ <goal>compress</goal>
+ </goals>
+ <phase>process-resources</phase>
+ <configuration>
+ <scripts>target/classes/META-INF/resources/org.apache.myfaces/</scripts>
+ <excludes>
+ <exclude>oamSubmit-uncompressed.js</exclude>
+ </excludes>
+ <compressor>yahooUI</compressor>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <optimizationLevel>0</optimizationLevel>
+ <sourceDirectory>src/main/javascript</sourceDirectory>
+ <webappDirectory>${basedir}</webappDirectory>
+ <outputDirectory>${basedir}/target/classes/META-INF/resources/org.apache.myfaces/</outputDirectory>
+ </configuration>
+ </plugin>
+
+ <plugin>
<groupId>org.apache.myfaces.buildtools</groupId>
<artifactId>myfaces-builder-plugin</artifactId>
<version>${myfaces-builder-plugin.version}</version>
Added: myfaces/core/trunk/impl/src/assembler/myfacesscripts-compiler.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/assembler/myfacesscripts-compiler.xml?rev=985849&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/assembler/myfacesscripts-compiler.xml (added)
+++ myfaces/core/trunk/impl/src/assembler/myfacesscripts-compiler.xml Mon Aug 16 09:52:11 2010
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+ * 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.
+-->
+<assembler>
+ <scripts>
+ <script>
+ <fileName>oamSubmit.js</fileName>
+ <includes>
+ <include>**/_impl/oamSubmit.js</include>
+ </includes>
+ </script>
+ </scripts>
+</assembler>
Propchange: myfaces/core/trunk/impl/src/assembler/myfacesscripts-compiler.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/core/trunk/impl/src/assembler/myfacesscripts-compiler.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/core/trunk/impl/src/assembler/myfacesscripts-compiler.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: myfaces/core/trunk/impl/src/assembler/myfacesscripts-uncompressed-compiler.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/assembler/myfacesscripts-uncompressed-compiler.xml?rev=985849&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/assembler/myfacesscripts-uncompressed-compiler.xml (added)
+++ myfaces/core/trunk/impl/src/assembler/myfacesscripts-uncompressed-compiler.xml Mon Aug 16 09:52:11 2010
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+ * 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.
+-->
+<assembler>
+ <scripts>
+ <script>
+ <fileName>oamSubmit-uncompressed.js</fileName>
+ <includes>
+ <include>**/_impl/oamSubmit.js</include>
+ </includes>
+ </script>
+ </scripts>
+</assembler>
Propchange: myfaces/core/trunk/impl/src/assembler/myfacesscripts-uncompressed-compiler.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/core/trunk/impl/src/assembler/myfacesscripts-uncompressed-compiler.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/core/trunk/impl/src/assembler/myfacesscripts-uncompressed-compiler.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ClassLoaderResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ClassLoaderResourceLoader.java?rev=985849&r1=985848&r2=985849&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ClassLoaderResourceLoader.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ClassLoaderResourceLoader.java Mon Aug 16 09:52:11 2010
@@ -415,8 +415,12 @@ public class ClassLoaderResourceLoader e
{
// InternalClassLoaderResourceLoader will serve it, so return null in this case.
return null;
- }
- else
+ } else if (_developmentStage && libraryName != null &&
+ org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils.MYFACES_LIBRARY_NAME.equals(libraryName) &&
+ org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils.MYFACES_JS_RESOURCE_NAME.equals(resourceName)) {
+ // InternalClassLoaderResourceLoader will serve it, so return null in this case.
+ return null;
+ } else
{
return new ResourceMetaImpl(prefix, libraryName, libraryVersion, resourceName, resourceVersion);
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java?rev=985849&r1=985848&r2=985849&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java Mon Aug 16 09:52:11 2010
@@ -1,190 +1,198 @@
-/*
- * 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.resource;
-
-import java.io.InputStream;
-import java.net.URL;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-
-import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
-import org.apache.myfaces.shared_impl.util.ClassUtils;
-
-/**
- * A resource loader implementation which loads resources from the thread ClassLoader.
- *
- */
-public class InternalClassLoaderResourceLoader extends ResourceLoader
-{
-
- /**
- * If this param is true and the project stage is development mode,
- * the source javascript files will be loaded separately instead have
- * all in just one file, to preserve line numbers and make javascript
- * debugging of jsf.js more simple.
- */
- @JSFWebConfigParam(since="2.0.1",defaultValue="false",expectedValues="true,false")
- public static final String USE_MULTIPLE_JS_FILES_FOR_JSF_UNCOMPRESSED_JS = "org.apache.myfaces.USE_MULTIPLE_JS_FILES_FOR_JSF_UNCOMPRESSED_JS";
-
- private final boolean _useMultipleJsFilesForJsfUncompressedJs;
-
- public InternalClassLoaderResourceLoader(String prefix)
- {
- super(prefix);
- _useMultipleJsFilesForJsfUncompressedJs = _getBooleanParameter(FacesContext.getCurrentInstance().getExternalContext(),
- USE_MULTIPLE_JS_FILES_FOR_JSF_UNCOMPRESSED_JS, null, false);
- }
-
- @Override
- public String getLibraryVersion(String path)
- {
- return null;
- }
-
- @Override
- public InputStream getResourceInputStream(ResourceMeta resourceMeta)
- {
- if (getPrefix() != null && !"".equals(getPrefix()))
- {
- return getClassLoader().getResourceAsStream(getPrefix() + '/' + resourceMeta.getResourceIdentifier());
- }
- else
- {
- return getClassLoader().getResourceAsStream(resourceMeta.getResourceIdentifier());
- }
- }
-
- @Override
- public URL getResourceURL(ResourceMeta resourceMeta)
- {
- if (getPrefix() != null && !"".equals(getPrefix()))
- {
- return getClassLoader().getResource(getPrefix() + '/' + resourceMeta.getResourceIdentifier());
- }
- else
- {
- return getClassLoader().getResource(resourceMeta.getResourceIdentifier());
- }
- }
-
- @Override
- public String getResourceVersion(String path)
- {
- return null;
- }
-
- @Override
- public ResourceMeta createResourceMeta(String prefix, String libraryName, String libraryVersion,
- String resourceName, String resourceVersion)
- {
- if (libraryName != null &&
- org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils.JAVAX_FACES_LIBRARY_NAME.equals(libraryName) &&
- org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils.JSF_JS_RESOURCE_NAME.equals(resourceName))
- {
- if (_useMultipleJsFilesForJsfUncompressedJs)
- {
- return new AliasResourceMetaImpl(prefix, libraryName, libraryVersion,
- resourceName, resourceVersion, org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils.JSF_UNCOMPRESSED_JS_RESOURCE_NAME, true);
- }
- else
- {
- return new AliasResourceMetaImpl(prefix, libraryName, libraryVersion, resourceName, resourceVersion, "jsf-uncompressed-full.js", false);
- }
- }
- else if (libraryName != null && libraryName.startsWith("org.apache.myfaces.core"))
- {
- return new ResourceMetaImpl(prefix, libraryName, libraryVersion, resourceName, resourceVersion);
- }
- else
- {
- return null;
- }
- }
-
- /**
- * Returns the ClassLoader to use when looking up resources under the top level package. By default, this is the
- * context class loader.
- *
- * @return the ClassLoader used to lookup resources
- */
- protected ClassLoader getClassLoader()
- {
- return ClassUtils.getContextClassLoader();
- }
-
- @Override
- public boolean libraryExists(String libraryName)
- {
- if (getPrefix() != null && !"".equals(getPrefix()))
- {
- URL url = getClassLoader().getResource(getPrefix() + '/' + libraryName);
- if (url != null)
- {
- return true;
- }
- }
- else
- {
- URL url = getClassLoader().getResource(libraryName);
- if (url != null)
- {
- return true;
- }
- }
- return false;
- }
-
- private String _getStringParameter(ExternalContext context, String name, String deprecatedName)
- {
- String param = context.getInitParameter(name);
-
- if ((param == null) && (deprecatedName != null))
- {
- param = context.getInitParameter (deprecatedName);
- }
-
- if (param == null)
- {
- return null;
- }
-
- param = param.trim();
- if (param.length() == 0)
- {
- return null;
- }
-
- return param;
- }
-
- private boolean _getBooleanParameter(ExternalContext context, String name, String deprecatedName, boolean defaultValue)
- {
- String param = _getStringParameter(context, name, deprecatedName);
- if (param == null)
- {
- return defaultValue;
- }
- else
- {
- return Boolean.parseBoolean(param.toLowerCase());
- }
- }
-
-}
+/*
+ * 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.resource;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
+import org.apache.myfaces.shared_impl.util.ClassUtils;
+
+/**
+ * A resource loader implementation which loads resources from the thread ClassLoader.
+ *
+ */
+public class InternalClassLoaderResourceLoader extends ResourceLoader
+{
+
+ /**
+ * If this param is true and the project stage is development mode,
+ * the source javascript files will be loaded separately instead have
+ * all in just one file, to preserve line numbers and make javascript
+ * debugging of jsf.js more simple.
+ */
+ @JSFWebConfigParam(since="2.0.1",defaultValue="false",expectedValues="true,false")
+ public static final String USE_MULTIPLE_JS_FILES_FOR_JSF_UNCOMPRESSED_JS = "org.apache.myfaces.USE_MULTIPLE_JS_FILES_FOR_JSF_UNCOMPRESSED_JS";
+
+ private final boolean _useMultipleJsFilesForJsfUncompressedJs;
+
+ public InternalClassLoaderResourceLoader(String prefix)
+ {
+ super(prefix);
+ _useMultipleJsFilesForJsfUncompressedJs = _getBooleanParameter(FacesContext.getCurrentInstance().getExternalContext(),
+ USE_MULTIPLE_JS_FILES_FOR_JSF_UNCOMPRESSED_JS, null, false);
+ }
+
+ @Override
+ public String getLibraryVersion(String path)
+ {
+ return null;
+ }
+
+ @Override
+ public InputStream getResourceInputStream(ResourceMeta resourceMeta)
+ {
+ if (getPrefix() != null && !"".equals(getPrefix()))
+ {
+ return getClassLoader().getResourceAsStream(getPrefix() + '/' + resourceMeta.getResourceIdentifier());
+ }
+ else
+ {
+ return getClassLoader().getResourceAsStream(resourceMeta.getResourceIdentifier());
+ }
+ }
+
+ @Override
+ public URL getResourceURL(ResourceMeta resourceMeta)
+ {
+ if (getPrefix() != null && !"".equals(getPrefix()))
+ {
+ return getClassLoader().getResource(getPrefix() + '/' + resourceMeta.getResourceIdentifier());
+ }
+ else
+ {
+ return getClassLoader().getResource(resourceMeta.getResourceIdentifier());
+ }
+ }
+
+ @Override
+ public String getResourceVersion(String path)
+ {
+ return null;
+ }
+
+ @Override
+ public ResourceMeta createResourceMeta(String prefix, String libraryName, String libraryVersion,
+ String resourceName, String resourceVersion)
+ {
+ //handle jsf.js
+ if (libraryName != null &&
+ org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils.JAVAX_FACES_LIBRARY_NAME.equals(libraryName) &&
+ org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils.JSF_JS_RESOURCE_NAME.equals(resourceName))
+ {
+ if (_useMultipleJsFilesForJsfUncompressedJs)
+ {
+ return new AliasResourceMetaImpl(prefix, libraryName, libraryVersion,
+ resourceName, resourceVersion, org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils.JSF_UNCOMPRESSED_JS_RESOURCE_NAME, true);
+ }
+ else
+ {
+ return new AliasResourceMetaImpl(prefix, libraryName, libraryVersion, resourceName, resourceVersion, "jsf-uncompressed-full.js", false);
+ }
+ }
+ //handle the oamSubmit.js
+ else if (libraryName != null &&
+ org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils.MYFACES_LIBRARY_NAME.equals(libraryName) &&
+ org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils.MYFACES_JS_RESOURCE_NAME.equals(resourceName))
+ {
+ return new AliasResourceMetaImpl(prefix, libraryName, libraryVersion,
+ resourceName, resourceVersion, org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils.MYFACES_JS_RESOURCE_NAME_UNCOMPRESSED, true);
+ } else if (libraryName != null && libraryName.startsWith("org.apache.myfaces.core"))
+ {
+ return new ResourceMetaImpl(prefix, libraryName, libraryVersion, resourceName, resourceVersion);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the ClassLoader to use when looking up resources under the top level package. By default, this is the
+ * context class loader.
+ *
+ * @return the ClassLoader used to lookup resources
+ */
+ protected ClassLoader getClassLoader()
+ {
+ return ClassUtils.getContextClassLoader();
+ }
+
+ @Override
+ public boolean libraryExists(String libraryName)
+ {
+ if (getPrefix() != null && !"".equals(getPrefix()))
+ {
+ URL url = getClassLoader().getResource(getPrefix() + '/' + libraryName);
+ if (url != null)
+ {
+ return true;
+ }
+ }
+ else
+ {
+ URL url = getClassLoader().getResource(libraryName);
+ if (url != null)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private String _getStringParameter(ExternalContext context, String name, String deprecatedName)
+ {
+ String param = context.getInitParameter(name);
+
+ if ((param == null) && (deprecatedName != null))
+ {
+ param = context.getInitParameter (deprecatedName);
+ }
+
+ if (param == null)
+ {
+ return null;
+ }
+
+ param = param.trim();
+ if (param.length() == 0)
+ {
+ return null;
+ }
+
+ return param;
+ }
+
+ private boolean _getBooleanParameter(ExternalContext context, String name, String deprecatedName, boolean defaultValue)
+ {
+ String param = _getStringParameter(context, name, deprecatedName);
+ if (param == null)
+ {
+ return defaultValue;
+ }
+ else
+ {
+ return Boolean.parseBoolean(param.toLowerCase());
+ }
+ }
+
+}
Added: myfaces/core/trunk/impl/src/main/javascript/META-INF/resources/myfaces/_impl/oamSubmit.js
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/javascript/META-INF/resources/myfaces/_impl/oamSubmit.js?rev=985849&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/javascript/META-INF/resources/myfaces/_impl/oamSubmit.js (added)
+++ myfaces/core/trunk/impl/src/main/javascript/META-INF/resources/myfaces/_impl/oamSubmit.js Mon Aug 16 09:52:11 2010
@@ -0,0 +1,160 @@
+/* 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.
+ */
+
+
+/**
+ * legacy code to enable various aspects
+ * of myfaces, used to be rendered inline
+ * for jsf 2.0 we can externalized it into its own custom resource
+ */
+
+
+
+/**
+ * sets a hidden input field
+ * @param formname the formName
+ * @param name the hidden field
+ * @param value the value to be rendered
+ */
+function oamSetHiddenInput(formname, name, value) {
+ var form = document.forms[formname];
+ if (typeof form == 'undefined') {
+ form = document.getElementById(formname);
+ }
+
+ if (typeof form.elements[name] != 'undefined' && (form.elements[name].nodeName == 'INPUT' || form.elements[name].nodeName == 'input')) {
+ form.elements[name].value = value;
+ }
+ else {
+ var newInput = document.createElement('input');
+ newInput.setAttribute('type', 'hidden');
+ newInput.setAttribute('id', name);
+ newInput.setAttribute('name', name);
+ newInput.setAttribute('value', value);
+ form.appendChild(newInput);
+ }
+}
+
+/**
+ * clears a hidden input field
+ *
+ * @param formname formName for the input
+ * @param name the name of the input field
+ * @param value the value to be cleared
+ */
+function oamClearHiddenInput(formname, name, value) {
+ var form = document.forms[formname];
+
+ if (typeof form == 'undefined') {
+ form = document.getElementById(formname);
+ }
+
+ var hInput = form.elements[name];
+ if (typeof hInput != 'undefined') {
+ form.removeChild(hInput);
+ }
+}
+
+/**
+ * does special form submit remapping
+ * remaps the issuing command link into something
+ * the decode of the command link on the server can understand
+ *
+ * @param formName
+ * @param linkId
+ * @param target
+ * @param params
+ */
+function oamSubmitForm(formName, linkId, target, params) {
+
+ var clearFn = 'clearFormHiddenParams_' + formName.replace(/-/g, '\$:').replace(/:/g, '_');
+ if (typeof window[clearFn] == 'function') {
+ window[clearFn](formName);
+ }
+
+ var form = document.forms[formName];
+ if (typeof form == 'undefined') {
+ form = document.getElementById(formName);
+ }
+
+ //autoscroll code
+ if (myfaces.core.config.autoScroll && typeof window.getScrolling != 'undefined') {
+ oamSetHiddenInput(formName, 'autoScroll', getScrolling());
+ }
+
+
+
+
+ if (myfaces.core.config.ieAutoSave) {
+ var agentString = navigator.userAgent.toLowerCase();
+ var version = navigator.appVersion;
+ if (agentString.indexOf('msie') != -1) {
+ if (!(agentString.indexOf('ppc') != -1 && agentString.indexOf('windows ce') != -1 && version >= 4.0)) {
+ window.external.AutoCompleteSaveForm(form);
+ }
+ }
+ }
+
+ var oldTarget = form.target;
+ if (target != null) {
+ form.target = target;
+ }
+ if ((typeof params != 'undefined') && params != null) {
+ for (var i = 0, param; (param = params[i]); i++) {
+ oamSetHiddenInput(formName, param[0], param[1]);
+ }
+
+ }
+
+ oamSetHiddenInput(formName, formName + ':' + '_idcl', linkId);
+
+ if (form.onsubmit) {
+ var result = form.onsubmit();
+ if ((typeof result == 'undefined') || result) {
+ try {
+ form.submit();
+ }
+ catch(e) {
+ }
+ }
+
+ }
+ else {
+ try {
+ form.submit();
+ }
+ catch(e) {
+ }
+ }
+
+ form.target = oldTarget;
+ if ((typeof params != 'undefined') && params != null) {
+
+ for (var i = 0, param; (param = params[i]); i++) {
+ oamClearHiddenInput(formName, param[0], param[1]);
+ }
+
+ }
+
+ oamClearHiddenInput(formName, formName + ':' + '_idcl', linkId);
+ return false;
+}
+
+//reserve a cofig namespace for impl related stuff
+(!window.myfaces) ? window.myfaces = {} : null;
+(!myfaces.core) ? myfaces.core = {} : null;
+(!myfaces.core.config) ? myfaces.core.config = {} : null;
+
Propchange: myfaces/core/trunk/impl/src/main/javascript/META-INF/resources/myfaces/_impl/oamSubmit.js
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/core/trunk/impl/src/main/javascript/META-INF/resources/myfaces/_impl/oamSubmit.js
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlButtonRendererTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlButtonRendererTest.java?rev=985849&r1=985848&r2=985849&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlButtonRendererTest.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlButtonRendererTest.java Mon Aug 16 09:52:11 2010
@@ -20,6 +20,7 @@ package org.apache.myfaces.renderkit.htm
import java.io.StringWriter;
+import javax.faces.FactoryFinder;
import javax.faces.component.UIParameter;
import javax.faces.component.behavior.AjaxBehavior;
import javax.faces.component.html.HtmlCommandButton;
@@ -52,6 +53,14 @@ public class HtmlButtonRendererTest exte
public static Test suite() {
return new TestSuite(HtmlButtonRendererTest.class);
}
+
+
+ @Override
+ protected void setFactories() throws Exception {
+ super.setFactories();
+ FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
+ "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
+ }
public void setUp() throws Exception {
super.setUp();
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlLinkRendererTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlLinkRendererTest.java?rev=985849&r1=985848&r2=985849&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlLinkRendererTest.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlLinkRendererTest.java Mon Aug 16 09:52:11 2010
@@ -20,6 +20,7 @@ package org.apache.myfaces.renderkit.htm
import java.io.StringWriter;
+import javax.faces.FactoryFinder;
import javax.faces.component.UIForm;
import javax.faces.component.UIParameter;
import javax.faces.component.behavior.AjaxBehavior;
@@ -79,6 +80,8 @@ public class HtmlLinkRendererTest extend
writer = new MockResponseWriter(new StringWriter(), null, "UTF-8");
facesContext.setResponseWriter(writer);
facesContext.getApplication().setNavigationHandler(new NavigationHandlerImpl());
+
+
facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.getRenderKit().addRenderer(
@@ -101,6 +104,13 @@ public class HtmlLinkRendererTest extend
facesContext.getAttributes().put("org.apache.myfaces.RENDERED_JSF_JS", Boolean.TRUE);
}
+ @Override
+ protected void setFactories() throws Exception {
+ super.setFactories();
+ FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
+ "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
+ }
+
public void tearDown() throws Exception
{
super.tearDown();
@@ -262,6 +272,7 @@ public class HtmlLinkRendererTest extend
{
commandLink.encodeAll(facesContext);
String output = ((StringWriter) writer.getWriter()).getBuffer().toString();
+ System.out.println("----OUTPUT----"+output);
assertTrue(output.matches("(?s).+id=\".+\".+"));
assertTrue(output.matches("(?s).+name=\".+\".+"));
}
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/behavior/AbstractClientBehaviorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/behavior/AbstractClientBehaviorTestCase.java?rev=985849&r1=985848&r2=985849&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/behavior/AbstractClientBehaviorTestCase.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/html/behavior/AbstractClientBehaviorTestCase.java Mon Aug 16 09:52:11 2010
@@ -1,206 +1,215 @@
-/*
- * 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.renderkit.html.behavior;
-
-import java.io.StringWriter;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.behavior.AjaxBehavior;
-import javax.faces.component.behavior.ClientBehaviorHolder;
-import javax.faces.context.ResponseWriter;
-
-import org.apache.myfaces.shared_impl.renderkit.html.HtmlResponseWriterImpl;
-import org.apache.myfaces.shared_impl.util.FastWriter;
-import org.apache.myfaces.test.base.junit4.AbstractJsfTestCase;
-import org.apache.myfaces.test.config.ConfigParser;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * @author Leonardo Uribe (latest modification by $Author: jankeesvanandel $)
- * @version $Revision: 799929 $ $Date: 2009-08-01 16:29:33 -0500 (sáb, 01 ago 2009) $
- */
-public abstract class AbstractClientBehaviorTestCase extends AbstractJsfTestCase
-{
- protected ResponseWriter writer;
- protected FastWriter outputWriter;
- protected ConfigParser parser;
-
- //protected abstract UIComponent getComponentToTest();
-
- protected abstract HtmlRenderedClientEventAttr[] getClientBehaviorHtmlRenderedAttributes();
-
- protected abstract UIComponent createComponentToTest();
-
- @Override
- protected void setUpJSFObjects() throws Exception
- {
- super.setUpJSFObjects();
- outputWriter = new FastWriter();
- writer = new HtmlResponseWriterImpl(outputWriter, null, null);
- facesContext.setResponseWriter(writer);
- facesContext.getAttributes().put("org.apache.myfaces.RENDERED_JSF_JS", true);
- }
-
- @Override
- protected void setUpApplication() throws Exception
- {
- super.setUpApplication();
- }
-
- @Override
- protected void setUpRenderKit() throws Exception
- {
- super.setUpRenderKit();
- parser = new ConfigParser();
- parser.parse(parser.getPlatformURLs());
- //parser.parse(this.getClass().getResource("/META-INF/faces-config.xml"));
- }
-
- /**
- * Components that render client behaviors should always render "id" and "name" attribute
- */
- @Test
- public void testClientBehaviorHolderRendersIdAndName()
- {
- HtmlRenderedClientEventAttr[] attrs = getClientBehaviorHtmlRenderedAttributes();
-
- for (int i = 0; i < attrs.length; i++)
- {
- UIComponent component = createComponentToTest();
- ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
- clientBehaviorHolder.addClientBehavior(attrs[i].getClientEvent(), new AjaxBehavior());
- try
- {
- component.encodeAll(facesContext);
- String output = outputWriter.toString();
- Assert.assertTrue(output.indexOf(" id=\""+component.getClientId(facesContext)+"\"") > -1);
- Assert.assertTrue(output.indexOf(" name=\""+component.getClientId(facesContext)+"\"") > -1);
- outputWriter.reset();
- }
- catch (Exception e)
- {
- Assert.fail(e.getMessage());
- }
- }
- }
-
- @Test
- public void testClientBehaviorRendered()
- {
- HtmlRenderedClientEventAttr[] attrs = getClientBehaviorHtmlRenderedAttributes();
-
- for (int i = 0; i < attrs.length; i++)
- {
- UIComponent component = createComponentToTest();
- ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
- clientBehaviorHolder.addClientBehavior(attrs[i].getClientEvent(), new AjaxBehavior());
- try
- {
- component.encodeAll(facesContext);
- String output = outputWriter.toString();
- //jsf.ajax.request('j_id0',event,{'javax.faces.behavior.event':'click'})
- //Only check if the property starts with jsf.ajax.request( is enough
- //Assert.assertTrue("output does not match expected output jsf.ajax.request(.... for property "+attrs[i].getName(),
- // output.matches(".+ "+attrs[i].getName()+"=\"jsf\\.ajax\\.request\\(.+"));
- int index = checkClientBehaviorRenderedOnClientEventProperty(output, 0, attrs[i]);
- outputWriter.reset();
- }
- catch (Exception e)
- {
- Assert.fail(e.getMessage());
- }
- }
- }
-
- public int checkClientBehaviorRenderedOnClientEventProperty(String output, int start, HtmlRenderedClientEventAttr attr)
- {
- String propStart = " "+attr.getName()+"=\"";
- int propIndex = output.indexOf(propStart, start);
- if (propIndex > -1)
- {
- int c = '"';
- int startPropIndex = propIndex + propStart.length();
- int endPropIndex = output.indexOf('"' , startPropIndex );
- String propertyValue = output.substring(startPropIndex, endPropIndex);
- Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains("jsf.ajax.request("));
- Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains("javax.faces.behavior.event"));
- Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains(attr.getClientEvent()));
- return endPropIndex + 1;
- }
- else
- {
- Assert.fail("Property " + attr.getName() + "not found");
- return -1;
- }
- }
-
- @Test
- public void testClientBehaviorRenderedWithHtmlAttribute()
- {
- HtmlRenderedClientEventAttr[] attrs = getClientBehaviorHtmlRenderedAttributes();
-
- for (int i = 0; i < attrs.length; i++)
- {
- UIComponent component = createComponentToTest();
- ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
- clientBehaviorHolder.addClientBehavior(attrs[i].getClientEvent(), new AjaxBehavior());
- component.getAttributes().put(attrs[i].getName(), "htmlValue");
- try
- {
- component.encodeAll(facesContext);
- String output = outputWriter.toString();
- //jsf.ajax.request('j_id0',event,{'javax.faces.behavior.event':'click'})
- //Only check if the property starts with jsf.ajax.request( is enough
- //Assert.assertTrue("output does not match expected output jsf.ajax.request(.... for property "+attrs[i].getName(),
- // output.matches(".+ "+attrs[i].getName()+"=\"jsf\\.ajax\\.request\\(.+"));
- int index = checkClientBehaviorRenderedOnClientEventPropertyAndHtmlValue(output, 0, attrs[i], "htmlValue");
- outputWriter.reset();
- }
- catch (Exception e)
- {
- Assert.fail(e.getMessage());
- }
- }
- }
-
- public int checkClientBehaviorRenderedOnClientEventPropertyAndHtmlValue(String output, int start, HtmlRenderedClientEventAttr attr, String value)
- {
- String propStart = " "+attr.getName()+"=\"";
- int propIndex = output.indexOf(propStart, start);
- if (propIndex > -1)
- {
- int c = '"';
- int startPropIndex = propIndex + propStart.length();
- int endPropIndex = output.indexOf('"' , startPropIndex );
- String propertyValue = output.substring(startPropIndex, endPropIndex);
- Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.startsWith("jsf.util.chain("));
- Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains("jsf.ajax.request("));
- Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains("javax.faces.behavior.event"));
- Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains(attr.getClientEvent()));
- Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains(value));
- return endPropIndex + 1;
- }
- else
- {
- Assert.fail("Property " + attr.getName() + "not found"+" Output: "+output);
- return -1;
- }
- }
-}
+/*
+ * 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.renderkit.html.behavior;
+
+import java.io.StringWriter;
+
+import javax.faces.FactoryFinder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.AjaxBehavior;
+import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.context.ResponseWriter;
+
+import org.apache.myfaces.shared_impl.renderkit.html.HtmlResponseWriterImpl;
+import org.apache.myfaces.shared_impl.util.FastWriter;
+import org.apache.myfaces.test.base.junit4.AbstractJsfTestCase;
+import org.apache.myfaces.test.config.ConfigParser;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Leonardo Uribe (latest modification by $Author: jankeesvanandel $)
+ * @version $Revision: 799929 $ $Date: 2009-08-01 16:29:33 -0500 (sáb, 01 ago 2009) $
+ */
+public abstract class AbstractClientBehaviorTestCase extends AbstractJsfTestCase
+{
+ protected ResponseWriter writer;
+ protected FastWriter outputWriter;
+ protected ConfigParser parser;
+
+ //protected abstract UIComponent getComponentToTest();
+
+ protected abstract HtmlRenderedClientEventAttr[] getClientBehaviorHtmlRenderedAttributes();
+
+ protected abstract UIComponent createComponentToTest();
+
+ @Override
+ protected void setUpJSFObjects() throws Exception
+ {
+ super.setUpJSFObjects();
+ outputWriter = new FastWriter();
+ writer = new HtmlResponseWriterImpl(outputWriter, null, null);
+ facesContext.setResponseWriter(writer);
+ facesContext.getAttributes().put("org.apache.myfaces.RENDERED_JSF_JS", true);
+ }
+
+ @Override
+ protected void setUpApplication() throws Exception
+ {
+ super.setUpApplication();
+ }
+
+ @Override
+ protected void setUpRenderKit() throws Exception
+ {
+ super.setUpRenderKit();
+ parser = new ConfigParser();
+ parser.parse(parser.getPlatformURLs());
+ //parser.parse(this.getClass().getResource("/META-INF/faces-config.xml"));
+ }
+
+
+ @Override
+ protected void setFactories() throws Exception {
+ super.setFactories();
+ FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
+ "org.apache.myfaces.test.mock.MockPartialViewContextFactory");
+ }
+
+ /**
+ * Components that render client behaviors should always render "id" and "name" attribute
+ */
+ @Test
+ public void testClientBehaviorHolderRendersIdAndName()
+ {
+ HtmlRenderedClientEventAttr[] attrs = getClientBehaviorHtmlRenderedAttributes();
+
+ for (int i = 0; i < attrs.length; i++)
+ {
+ UIComponent component = createComponentToTest();
+ ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
+ clientBehaviorHolder.addClientBehavior(attrs[i].getClientEvent(), new AjaxBehavior());
+ try
+ {
+ component.encodeAll(facesContext);
+ String output = outputWriter.toString();
+ Assert.assertTrue(output.indexOf(" id=\""+component.getClientId(facesContext)+"\"") > -1);
+ Assert.assertTrue(output.indexOf(" name=\""+component.getClientId(facesContext)+"\"") > -1);
+ outputWriter.reset();
+ }
+ catch (Exception e)
+ {
+ Assert.fail(e.getMessage());
+ }
+ }
+ }
+
+ @Test
+ public void testClientBehaviorRendered()
+ {
+ HtmlRenderedClientEventAttr[] attrs = getClientBehaviorHtmlRenderedAttributes();
+
+ for (int i = 0; i < attrs.length; i++)
+ {
+ UIComponent component = createComponentToTest();
+ ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
+ clientBehaviorHolder.addClientBehavior(attrs[i].getClientEvent(), new AjaxBehavior());
+ try
+ {
+ component.encodeAll(facesContext);
+ String output = outputWriter.toString();
+ //jsf.ajax.request('j_id0',event,{'javax.faces.behavior.event':'click'})
+ //Only check if the property starts with jsf.ajax.request( is enough
+ //Assert.assertTrue("output does not match expected output jsf.ajax.request(.... for property "+attrs[i].getName(),
+ // output.matches(".+ "+attrs[i].getName()+"=\"jsf\\.ajax\\.request\\(.+"));
+ int index = checkClientBehaviorRenderedOnClientEventProperty(output, 0, attrs[i]);
+ outputWriter.reset();
+ }
+ catch (Exception e)
+ {
+ Assert.fail(e.getMessage());
+ }
+ }
+ }
+
+ public int checkClientBehaviorRenderedOnClientEventProperty(String output, int start, HtmlRenderedClientEventAttr attr)
+ {
+ String propStart = " "+attr.getName()+"=\"";
+ int propIndex = output.indexOf(propStart, start);
+ if (propIndex > -1)
+ {
+ int c = '"';
+ int startPropIndex = propIndex + propStart.length();
+ int endPropIndex = output.indexOf('"' , startPropIndex );
+ String propertyValue = output.substring(startPropIndex, endPropIndex);
+ Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains("jsf.ajax.request("));
+ Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains("javax.faces.behavior.event"));
+ Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains(attr.getClientEvent()));
+ return endPropIndex + 1;
+ }
+ else
+ {
+ Assert.fail("Property " + attr.getName() + "not found");
+ return -1;
+ }
+ }
+
+ @Test
+ public void testClientBehaviorRenderedWithHtmlAttribute()
+ {
+ HtmlRenderedClientEventAttr[] attrs = getClientBehaviorHtmlRenderedAttributes();
+
+ for (int i = 0; i < attrs.length; i++)
+ {
+ UIComponent component = createComponentToTest();
+ ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
+ clientBehaviorHolder.addClientBehavior(attrs[i].getClientEvent(), new AjaxBehavior());
+ component.getAttributes().put(attrs[i].getName(), "htmlValue");
+ try
+ {
+ component.encodeAll(facesContext);
+ String output = outputWriter.toString();
+ //jsf.ajax.request('j_id0',event,{'javax.faces.behavior.event':'click'})
+ //Only check if the property starts with jsf.ajax.request( is enough
+ //Assert.assertTrue("output does not match expected output jsf.ajax.request(.... for property "+attrs[i].getName(),
+ // output.matches(".+ "+attrs[i].getName()+"=\"jsf\\.ajax\\.request\\(.+"));
+ int index = checkClientBehaviorRenderedOnClientEventPropertyAndHtmlValue(output, 0, attrs[i], "htmlValue");
+ outputWriter.reset();
+ }
+ catch (Exception e)
+ {
+ Assert.fail(e.getMessage());
+ }
+ }
+ }
+
+ public int checkClientBehaviorRenderedOnClientEventPropertyAndHtmlValue(String output, int start, HtmlRenderedClientEventAttr attr, String value)
+ {
+ String propStart = " "+attr.getName()+"=\"";
+ int propIndex = output.indexOf(propStart, start);
+ if (propIndex > -1)
+ {
+ int c = '"';
+ int startPropIndex = propIndex + propStart.length();
+ int endPropIndex = output.indexOf('"' , startPropIndex );
+ String propertyValue = output.substring(startPropIndex, endPropIndex);
+ Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.startsWith("jsf.util.chain("));
+ Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains("jsf.ajax.request("));
+ Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains("javax.faces.behavior.event"));
+ Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains(attr.getClientEvent()));
+ Assert.assertTrue("Property: " + attr.getName()+" Output: "+output, propertyValue.contains(value));
+ return endPropIndex + 1;
+ }
+ else
+ {
+ Assert.fail("Property " + attr.getName() + "not found"+" Output: "+output);
+ return -1;
+ }
+ }
+}