Author: alexsmirnov
Date: 2010-11-30 19:40:36 -0500 (Tue, 30 Nov 2010)
New Revision: 20246
Added:
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/FunctionDefWithDependencies.java
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/JavaScriptService.java
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptWithDependencies.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIResource.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIScripts.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/ValidatorTestBase.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/Script.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/ServiceGetOrCreateResourceTest.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererBuildScriptTest.java
Removed:
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryScriptString.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIValidatorScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptRenderer.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/UIValidatorScriptCollectionTest.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetOrCreateResourceTest.java
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UITransient.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/NullConverterScript.java
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/faces-config.xml
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Bean.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorTestBase.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
Log:
CODING IN PROGRESS - issue RF-9612: Create JSF 2.0 resource loading extension to
dynamically add scripts and its dependencies.
https://jira.jboss.org/browse/RF-9612
Added:
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/FunctionDefWithDependencies.java
===================================================================
---
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/FunctionDefWithDependencies.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/FunctionDefWithDependencies.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,35 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.javascript;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface FunctionDefWithDependencies extends ScriptWithDependencies {
+
+ String getName();
+
+}
Property changes on:
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/FunctionDefWithDependencies.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/JavaScriptService.java
===================================================================
---
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/JavaScriptService.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/JavaScriptService.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,56 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.javascript;
+
+import javax.faces.context.FacesContext;
+
+
+/**
+ * <p class="changed_added_4_0">
+ * This service stores JavaScript objects for deffered rendering, as described on
+ *
http://community.jboss.org/wiki/RichFacesJavaScripthandling
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface JavaScriptService {
+
+ /**
+ * <p class="changed_added_4_0">Adds new script to render at the end
of page. Is the same script already set to render ( lookup by equals() method ), no new
object added.</p>
+ * @param facesContext TODO
+ * @param script
+ * @return actual object that will be rendered at the end of page.
+ */
+ <S> S addScript(FacesContext facesContext, S script);
+
+ /**
+ * <p class="changed_added_4_0">This method adds script that has to
be executed in page.onready event listener, as required by jQuery components.</p>
+ * @param facesContext TODO
+ * @param script
+ * @param <S>
+ * @return
+ */
+ <S> S addPageReadyScript(FacesContext facesContext, S script);
+}
Property changes on:
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/JavaScriptService.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryScriptString.java
===================================================================
---
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryScriptString.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryScriptString.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -1,14 +0,0 @@
-package org.richfaces.javascript;
-
-import org.ajax4jsf.javascript.ScriptString;
-import org.richfaces.resource.ResourceLibrary;
-
-/**
- * This interface describes JavaScript object with optional dependent resources.
- * @author asmirnov
- *
- */
-public interface LibraryScriptString extends ResourceLibrary, ScriptString {
-
-
-}
\ No newline at end of file
Copied:
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptWithDependencies.java
(from rev 20241,
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryScriptString.java)
===================================================================
---
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptWithDependencies.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptWithDependencies.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,14 @@
+package org.richfaces.javascript;
+
+import org.ajax4jsf.javascript.ScriptString;
+import org.richfaces.resource.ResourceLibrary;
+
+/**
+ * This interface describes JavaScript object with optional dependent resources.
+ * @author asmirnov
+ *
+ */
+public interface ScriptWithDependencies extends ResourceLibrary, ScriptString {
+
+
+}
\ No newline at end of file
Property changes on:
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/ScriptWithDependencies.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -31,6 +31,8 @@
import org.richfaces.javascript.ClientScriptService;
import org.richfaces.javascript.ClientScriptServiceImpl;
import org.richfaces.javascript.ClientServiceConfigParser;
+import org.richfaces.javascript.JavaScriptService;
+import org.richfaces.javascript.JavaScriptServiceImpl;
import org.richfaces.javascript.LibraryFunction;
import org.richfaces.validator.BeanValidator;
import org.richfaces.validator.BeanValidatorFactory;
@@ -64,6 +66,7 @@
configureBeanValidators(factory);
factory.setInstance(FacesConverterService.class, new ConverterServiceImpl());
factory.setInstance(FacesValidatorService.class, new
FacesValidatorServiceImpl());
+ factory.setInstance(JavaScriptService.class, new JavaScriptServiceImpl());
ClientScriptServiceImpl clientScriptService = createClientScriptService();
factory.setInstance(ClientScriptService.class, clientScriptService);
}
Added:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIResource.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIResource.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIResource.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,125 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+import javax.faces.application.ResourceHandler;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class UIResource extends UITransient {
+
+ private final String name;
+ private final String library;
+
+ public UIResource(UIComponent parent,String name, String library) {
+ this.name = name;
+ this.library = library;
+ setParent(parent);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.UITransient#hasAttribute(java.lang.Object)
+ */
+ @Override
+ protected boolean hasAttribute(Object key) {
+ if("name".equals(key)){
+ return null != getName();
+ } else if ("library".equals(key)) {
+ return null != getLibrary();
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.UITransient#setAttribute(java.lang.String,
java.lang.Object)
+ */
+ @Override
+ protected Object setAttribute(String key, Object value) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.UITransient#getAttribute(java.lang.Object)
+ */
+ @Override
+ protected Object getAttribute(Object key) {
+ if("name".equals(key)){
+ return getName();
+ } else if ("library".equals(key)) {
+ return getLibrary();
+ }
+ return null;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the library
+ */
+ public String getLibrary() {
+ return library;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.component.UIComponent#getFamily()
+ */
+ @Override
+ public String getFamily() {
+ return UIOutput.COMPONENT_FAMILY;
+ }
+
+ @Override
+ public String getRendererType() {
+ return getRendererType(getFacesContext());
+ }
+
+ public String getRendererType(FacesContext context) {
+ ResourceHandler resourceHandler = context.getApplication().getResourceHandler();
+ return resourceHandler.getRendererTypeForResourceName(getName());
+ }
+
+ @Override
+ protected Renderer getRenderer(FacesContext context) {
+ String rendererType = getRendererType(context);
+ Renderer result = null;
+ if (rendererType != null) {
+ result = context.getRenderKit().getRenderer(getFamily(), rendererType);
+ }
+ return result;
+ }
+}
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIResource.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIScripts.java
(from rev 20241,
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIValidatorScript.java)
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIScripts.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIScripts.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,110 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+
+import org.richfaces.renderkit.html.ComponentValidatorScript;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+
+/**
+ * <p class="changed_added_4_0">
+ * This component user to render Client Validator scripts. Any ClientValidatorBehavior
that requires additional scripts
+ * should put them to this component, associated with "form" target in view
resources.
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class UIScripts extends UITransient {
+
+
+ public static final String COMPONENT_TYPE = "org.richfaces.Scripts";
+
+ private final List<Object> scripts = Lists.newArrayList();
+
+ private final List<Object> pageReadyScripts = Lists.newArrayList();
+
+ private String target = "form";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.Script";
+
+ public Collection<Object> getScripts() {
+ return scripts;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the pageReadyScripts
+ */
+ public Collection<Object> getPageReadyScripts() {
+ return this.pageReadyScripts;
+ }
+
+
+ @Override
+ public String getFamily() {
+ return UIScripts.COMPONENT_FAMILY;
+ }
+
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ public String getTarget() {
+ return target;
+ }
+
+ @Override
+ protected boolean hasAttribute(Object key) {
+ return "target".equals(key);
+ }
+
+ @Override
+ protected Object setAttribute(String key, Object value) {
+ if ("target".equals(key)) {
+ String oldTarget = getTarget();
+ setTarget((String) value);
+ return oldTarget;
+ }
+ return null;
+ }
+
+ @Override
+ protected Object getAttribute(Object key) {
+ if("target".equals(key)){
+ return getTarget();
+ }
+ return null;
+ }
+
+}
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIScripts.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UITransient.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UITransient.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UITransient.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -20,7 +20,7 @@
import javax.faces.event.FacesListener;
import javax.faces.render.Renderer;
-import org.richfaces.renderkit.html.ValidatorScriptRenderer;
+import org.richfaces.renderkit.html.ScriptsRenderer;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -28,13 +28,10 @@
public abstract class UITransient extends UIComponent {
- public static final String COMPONENT_FAMILY = "org.richfaces.Script";
private String id;
private UIComponent parent;
- private String target = "form";
-
private final Map<String, Object> attributesMap = new AttributesMap();
@@ -45,19 +42,6 @@
}
- public void setTarget(String target) {
- this.target = target;
- }
-
- public String getTarget() {
- return target;
- }
-
- @Override
- public String getFamily() {
- return COMPONENT_FAMILY;
- }
-
public Object saveState(FacesContext context) {
// This is transient component
return null;
@@ -81,11 +65,13 @@
return attributesMap;
}
+ @SuppressWarnings("deprecation")
@Override
public ValueBinding getValueBinding(String name) {
return null;
}
+ @SuppressWarnings("deprecation")
@Override
public void setValueBinding(String name, ValueBinding binding) {
// do nothing
@@ -110,7 +96,7 @@
// if the clientId is not yet set
if (this.clientId == null) {
- UIComponent namingContainerAncestor = this.getNamingContainerAncestor();
+ UIComponent namingContainerAncestor = this.getNamingContainer();
String parentId = null;
// give the parent the opportunity to first
@@ -146,17 +132,6 @@
return this.clientId;
}
- private UIComponent getNamingContainerAncestor() {
- UIComponent namingContainer = this.getParent();
- while (namingContainer != null) {
- if (namingContainer instanceof NamingContainer) {
- return namingContainer;
- }
- namingContainer = namingContainer.getParent();
- }
- return null;
- }
-
@Override
public String getId() {
return this.id;
@@ -165,7 +140,7 @@
@Override
public void setId(String id) {
this.id = id;
-
+ this.clientId = null;
}
@Override
@@ -190,12 +165,12 @@
@Override
public String getRendererType() {
- return ValidatorScriptRenderer.RENDERER_TYPE;
+ return ScriptsRenderer.RENDERER_TYPE;
}
@Override
public void setRendererType(String rendererType) {
- // TODO Auto-generated method stub
+ // do nothing
}
@@ -247,14 +222,18 @@
@Override
public void encodeBegin(FacesContext context) throws IOException {
- // TODO Auto-generated method stub
-
+ Renderer renderer = getRenderer(context);
+ if(null != renderer){
+ renderer.encodeBegin(context, this);
+ }
}
@Override
public void encodeChildren(FacesContext context) throws IOException {
- // TODO Auto-generated method stub
-
+ Renderer renderer = getRenderer(context);
+ if(null != renderer){
+ renderer.encodeChildren(context, this);
+ }
}
@Override
@@ -331,6 +310,7 @@
}
final class AttributesMap implements Map<String, Object> {
+
public void clear() {
// do nothing
@@ -338,7 +318,7 @@
public boolean containsKey(Object key) {
- return
"target".equals(key)||"id".equals(key)||"clientId".equals(key);
+ return
"target".equals(key)||"id".equals(key)||"clientId".equals(key)||hasAttribute(key);
}
public boolean containsValue(Object value) {
@@ -350,14 +330,13 @@
}
public Object get(Object key) {
- if("target".equals(key)){
- return getTarget();
- } else if ("id".equals(key)) {
+ if ("id".equals(key)) {
return getId();
} else if ("clientId".equals(key)) {
return getClientId();
+ } else {
+ return getAttribute(key);
}
- return null;
}
public boolean isEmpty() {
@@ -369,16 +348,13 @@
}
public Object put(String key, Object value) {
- if("target".equals(key)){
- String target = getTarget();
- setTarget((String) value);
- return target;
- } else if ("id".equals(key)) {
+ if ("id".equals(key)) {
String id = getId();
setId((String) value);
return id;
+ } else {
+ return setAttribute(key, value);
}
- return null;
}
public void putAll(Map<? extends String, ? extends Object> m) {
@@ -395,8 +371,16 @@
}
public Collection<Object> values() {
- return ImmutableList.<Object>of(getTarget(),getId(),getClientId());
+ return ImmutableList.<Object>of(getId(),getClientId());
}
}
+ protected abstract boolean hasAttribute(Object key);
+
+
+ protected abstract Object setAttribute(String key, Object value);
+
+
+ protected abstract Object getAttribute(Object key);
+
}
\ No newline at end of file
Deleted:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIValidatorScript.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIValidatorScript.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIValidatorScript.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -1,70 +0,0 @@
-/*
- * $Id$
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.richfaces.component;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-
-import org.richfaces.renderkit.html.ComponentValidatorScript;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-
-/**
- * <p class="changed_added_4_0">
- * This component user to render Client Validator scripts. Any ClientValidatorBehavior
that requires additional scripts
- * should put them to this component, associated with "form" target in view
resources.
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public class UIValidatorScript extends UITransient {
-
-
- public static final String COMPONENT_TYPE =
"org.richfaces.ValidatorScript";
-
- final List<ComponentValidatorScript> scripts = Lists.newArrayList();
-
- public Collection<ComponentValidatorScript> getScripts() {
- return scripts;
- }
-
- public ComponentValidatorScript addOrFindScript(ComponentValidatorScript
validatorScript) {
- // TODO optimize
- for (ComponentValidatorScript script : this.scripts) {
- if (script.equals(validatorScript)) {
- return script;
- }
- }
- scripts.add(validatorScript);
- return validatorScript;
- }
-
-}
Added:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,112 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.javascript;
+
+import java.util.Collection;
+import java.util.List;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.component.UIScripts;
+import org.richfaces.renderkit.html.NoSuchComponentException;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class JavaScriptServiceImpl implements JavaScriptService {
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.javascript.JavaScriptService#addScript(org.ajax4jsf.javascript.ScriptString)
+ */
+ public <S> S addScript(FacesContext facesContext, S script) {
+ UIScripts scriptResource = getOrCreateScriptResource(facesContext);
+
+ return addOrFind(scriptResource.getScripts(),script);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.javascript.JavaScriptService#addPageReadyScript(org.ajax4jsf.javascript.ScriptString)
+ */
+ public <S> S addPageReadyScript(FacesContext facesContext, S script) {
+ UIScripts scriptResource = getOrCreateScriptResource(facesContext);
+
+ return addOrFind(scriptResource.getPageReadyScripts(),script);
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private <S> S addOrFind(Collection<Object> collection,S script){
+ for (Object object : collection) {
+ if(script.equals(object)){
+ return (S) object;
+ }
+ }
+ collection.add(script);
+ return script;
+ }
+ /**
+ * <p class="changed_added_4_0">
+ * This method looks for {@link UIScripts} component in view resource. If such
resource not found, it
+ * creates a new instance and stores it in {@link UIViewRoot} view resource with
default target.
+ * </p>
+ *
+ * @param facesContext
+ * @return
+ */
+ UIScripts getOrCreateScriptResource(FacesContext facesContext) {
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+ if (null == viewRoot) {
+ throw new FacesException("View is not created");
+ }
+ List<UIComponent> componentResources =
viewRoot.getComponentResources(facesContext, "form");
+ try {
+ return findScriptResource(componentResources);
+ } catch (NoSuchComponentException e) {
+ componentResources = viewRoot.getComponentResources(facesContext,
"body");
+ try {
+ return findScriptResource(componentResources);
+ } catch (NoSuchComponentException e1) {
+ UIScripts component =
+ (UIScripts)
facesContext.getApplication().createComponent(UIScripts.COMPONENT_TYPE);
+ viewRoot.addComponentResource(facesContext, component);
+ return component;
+ }
+ }
+ }
+ private UIScripts findScriptResource(List<UIComponent> componentResources)
throws NoSuchComponentException {
+ for (UIComponent uiComponent : componentResources) {
+ if (uiComponent instanceof UIScripts) {
+ UIScripts script = (UIScripts) uiComponent;
+ return script;
+ }
+ }
+ throw new NoSuchComponentException();
+ }
+
+}
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -17,7 +17,7 @@
}
- public Iterable<ResourceKey> getResources(FacesContext context) {
+ public Iterable<ResourceKey> getResources() {
return Collections.emptySet();
}
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -2,7 +2,7 @@
import java.util.Collection;
-import org.richfaces.javascript.LibraryScriptString;
+import org.richfaces.javascript.ScriptWithDependencies;
public class ClientAndAjaxScript extends ClientOnlyScript{
@@ -11,8 +11,8 @@
final String ajaxScript;
- public ClientAndAjaxScript(LibraryScriptString clientSideConverterScript,
- Collection<? extends LibraryScriptString> validatorScripts, String
ajaxScript) {
+ public ClientAndAjaxScript(ScriptWithDependencies clientSideConverterScript,
+ Collection<? extends ScriptWithDependencies> validatorScripts, String
ajaxScript) {
super(clientSideConverterScript,validatorScripts);
this.ajaxScript = ajaxScript;
}
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -3,9 +3,7 @@
import java.util.Collection;
import java.util.LinkedHashSet;
-import javax.faces.context.FacesContext;
-
-import org.richfaces.javascript.LibraryScriptString;
+import org.richfaces.javascript.ScriptWithDependencies;
import org.richfaces.resource.ResourceKey;
import com.google.common.collect.Iterables;
@@ -13,11 +11,11 @@
public class ClientOnlyScript extends ValidatorScriptBase{
- protected final LibraryScriptString converter;
- protected final Collection<? extends LibraryScriptString> validators;
+ protected final ScriptWithDependencies converter;
+ protected final Collection<? extends ScriptWithDependencies> validators;
- public ClientOnlyScript(LibraryScriptString clientSideConverterScript,
- Collection<? extends LibraryScriptString> validatorScripts) {
+ public ClientOnlyScript(ScriptWithDependencies clientSideConverterScript,
+ Collection<? extends ScriptWithDependencies> validatorScripts) {
super();
if(null==clientSideConverterScript){
this.converter = NULL_CONVERTER_SCRIPT;
@@ -28,11 +26,11 @@
}
- public Iterable<ResourceKey> getResources(FacesContext context) {
+ public Iterable<ResourceKey> getResources() {
// TODO - make immutable.
LinkedHashSet<ResourceKey> resources = Sets.newLinkedHashSet();
Iterables.addAll(resources,converter.getResources());
- for (LibraryScriptString scriptString : validators) {
+ for (ScriptWithDependencies scriptString : validators) {
Iterables.addAll(resources,scriptString.getResources());
}
return resources;
@@ -52,7 +50,7 @@
converter.appendScriptToStringBuilder(body);
body.append(EOL);
// call validators
- for (LibraryScriptString validatorScript : validators) {
+ for (ScriptWithDependencies validatorScript : validators) {
validatorScript.appendScriptToStringBuilder(body);
body.append(EOL);
}
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -21,12 +21,13 @@
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.application.ServiceTracker;
-import org.richfaces.component.UIValidatorScript;
+import org.richfaces.component.UIScripts;
import org.richfaces.component.behavior.ClientValidatorBehavior;
import org.richfaces.component.behavior.ConverterNotFoundException;
import org.richfaces.javascript.ClientScriptService;
+import org.richfaces.javascript.JavaScriptService;
import org.richfaces.javascript.LibraryFunction;
-import org.richfaces.javascript.LibraryScriptString;
+import org.richfaces.javascript.ScriptWithDependencies;
import org.richfaces.javascript.ScriptNotFoundException;
import org.richfaces.validator.ConverterDescriptor;
import org.richfaces.validator.FacesObjectDescriptor;
@@ -135,53 +136,15 @@
ComponentValidatorScript validatorScript = createValidatorScript(behaviorContext,
behavior);
if (null != validatorScript) {
FacesContext facesContext = behaviorContext.getFacesContext();
- UIValidatorScript scriptResource =
getOrCreateValidatorScriptResource(facesContext);
- validatorScript = scriptResource.addOrFindScript(validatorScript);
+ JavaScriptService javaScriptService =
ServiceTracker.getService(JavaScriptService.class);
+ validatorScript = javaScriptService.addScript(facesContext,
validatorScript);
return
validatorScript.createCallScript(behaviorContext.getComponent().getClientId(facesContext),behaviorContext.getSourceId());
} else {
return null;
}
}
- /**
- * <p class="changed_added_4_0">
- * This method looks for {@link UIValidatorScript} component in view resource. If
such resource not found, it
- * creates a new instance and stores it in {@link UIViewRoot} view resource with
default target.
- * </p>
- *
- * @param facesContext
- * @return
- */
- UIValidatorScript getOrCreateValidatorScriptResource(FacesContext facesContext) {
- UIViewRoot viewRoot = facesContext.getViewRoot();
- if (null == viewRoot) {
- throw new FacesException("View is not created");
- }
- List<UIComponent> componentResources =
viewRoot.getComponentResources(facesContext, "form");
- try {
- return findScriptResource(componentResources);
- } catch (NoSuchComponentException e) {
- componentResources = viewRoot.getComponentResources(facesContext,
"body");
- try {
- return findScriptResource(componentResources);
- } catch (NoSuchComponentException e1) {
- UIValidatorScript component =
- (UIValidatorScript)
facesContext.getApplication().createComponent(UIValidatorScript.COMPONENT_TYPE);
- viewRoot.addComponentResource(facesContext, component);
- return component;
- }
- }
- }
- private UIValidatorScript findScriptResource(List<UIComponent>
componentResources) throws NoSuchComponentException {
- for (UIComponent uiComponent : componentResources) {
- if (uiComponent instanceof UIValidatorScript) {
- UIValidatorScript script = (UIValidatorScript) uiComponent;
- return script;
- }
- }
- throw new NoSuchComponentException();
- }
ComponentValidatorScript createValidatorScript(ClientBehaviorContext
behaviorContext,
ClientValidatorBehavior behavior) {
@@ -192,7 +155,7 @@
ConverterDescriptor converter = behavior.getConverter(behaviorContext);
if (null != converter) {
try {
- LibraryScriptString clientSideConverterScript =
+ ScriptWithDependencies clientSideConverterScript =
getClientSideConverterScript(behaviorContext.getFacesContext(), converter);
validatorScript = createValidatorScript(behaviorContext,
behavior, validators, clientSideConverterScript);
} catch (ScriptNotFoundException e) {
@@ -221,8 +184,8 @@
private ValidatorScriptBase createValidatorScript(ClientBehaviorContext
behaviorContext,
ClientValidatorBehavior behavior, Collection<ValidatorDescriptor>
validators,
- LibraryScriptString clientSideConverterScript) {
- Collection<? extends LibraryScriptString> validatorScripts =
getClientSideValidatorScript(behaviorContext.getFacesContext(), validators);
+ ScriptWithDependencies clientSideConverterScript) {
+ Collection<? extends ScriptWithDependencies> validatorScripts =
getClientSideValidatorScript(behaviorContext.getFacesContext(), validators);
if (validatorScripts.isEmpty()) {
return new AjaxOnlyScript(createAjaxScript(behaviorContext, behavior));
} else if (validatorScripts.size() < validators.size()) {
@@ -270,14 +233,14 @@
* @return
* @throws ScriptNotFoundException
*/
- LibraryScriptString getClientSideConverterScript(FacesContext facesContext,
+ ScriptWithDependencies getClientSideConverterScript(FacesContext facesContext,
ConverterDescriptor converter) throws ScriptNotFoundException {
ClientScriptService clientScriptService =
ServiceTracker.getService(facesContext, ClientScriptService.class);
return createClientFunction(facesContext, converter, VALUE_LITERAL,
clientScriptService);
}
- private LibraryScriptString createClientFunction(FacesContext facesContext,
FacesObjectDescriptor descriptor,
+ private ScriptWithDependencies createClientFunction(FacesContext facesContext,
FacesObjectDescriptor descriptor,
JSReference variable, ClientScriptService clientScriptService) throws
ScriptNotFoundException {
LibraryFunction script = clientScriptService.getScript(facesContext,
descriptor.getImplementationClass());
return new LibraryScriptFunction(script, variable, descriptor.getMessage(),
descriptor.getAdditionalParameters());
@@ -293,11 +256,11 @@
* @return
* @throws ScriptNotFoundException
*/
- Collection<? extends LibraryScriptString>
getClientSideValidatorScript(FacesContext facesContext,
+ Collection<? extends ScriptWithDependencies>
getClientSideValidatorScript(FacesContext facesContext,
Collection<ValidatorDescriptor> validators) {
ClientScriptService clientScriptService =
ServiceTracker.getService(facesContext, ClientScriptService.class);
- List<LibraryScriptString> scripts = Lists.newArrayList();
+ List<ScriptWithDependencies> scripts = Lists.newArrayList();
for (FacesObjectDescriptor validator : validators) {
try {
scripts.add(createClientFunction(facesContext, validator,
CONVERTED_VALUE_LITERAL, clientScriptService));
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -1,16 +1,10 @@
package org.richfaces.renderkit.html;
-import javax.faces.context.FacesContext;
+import org.richfaces.javascript.FunctionDefWithDependencies;
-import org.ajax4jsf.javascript.ScriptString;
-import org.richfaces.resource.ResourceKey;
-
-public interface ComponentValidatorScript extends ScriptString {
+public interface ComponentValidatorScript extends FunctionDefWithDependencies {
- String getName();
- Iterable<ResourceKey> getResources(FacesContext context);
-
/**
* <p class="changed_added_4_0">Creates JavasCript that calls
validator function.</p>
* @param clientId
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -25,7 +25,7 @@
import org.ajax4jsf.javascript.JSFunction;
import org.richfaces.javascript.LibraryFunction;
-import org.richfaces.javascript.LibraryScriptString;
+import org.richfaces.javascript.ScriptWithDependencies;
import org.richfaces.resource.ResourceKey;
/**
@@ -36,7 +36,7 @@
* @author asmirnov(a)exadel.com
*
*/
-public class LibraryScriptFunction extends JSFunction implements LibraryScriptString {
+public class LibraryScriptFunction extends JSFunction implements ScriptWithDependencies
{
private final Iterable<ResourceKey> resources;
private final String name;
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/NullConverterScript.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/NullConverterScript.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/NullConverterScript.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -6,7 +6,7 @@
import java.util.Collections;
import org.ajax4jsf.javascript.JSLiteral;
-import org.richfaces.javascript.LibraryScriptString;
+import org.richfaces.javascript.ScriptWithDependencies;
import org.richfaces.resource.ResourceKey;
/**
@@ -15,7 +15,7 @@
* @author asmirnov
*
*/
-public class NullConverterScript extends JSLiteral implements LibraryScriptString {
+public class NullConverterScript extends JSLiteral implements ScriptWithDependencies {
private String name;
Copied:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java
(from rev 20241,
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptRenderer.java)
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,78 @@
+/**
+ *
+ */
+package org.richfaces.renderkit.html;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.richfaces.component.UIResource;
+import org.richfaces.component.UIScripts;
+import org.richfaces.resource.ResourceKey;
+import org.richfaces.resource.ResourceLibrary;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ScriptsRenderer extends Renderer {
+
+ public static final String RENDERER_TYPE =
"org.richfaces.renderer.ScriptsRenderer";
+ private static final String TEXT_JAVASCRIPT = "text/javascript";
+ private static final String SRC = "src";
+ private static final String TYPE = "type";
+ private static final String SCRIPT = "script";
+ private static final ResourceKey JQUERY =
ResourceKey.create("jquery.js",null);
+
+ @Override
+ public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
+ UIScripts validatorScript = (UIScripts) component;
+ ResponseWriter responseWriter = context.getResponseWriter();
+ // TODO - change behavior for AJAX requests.
+ Collection<Object> scripts = validatorScript.getScripts();
+ encodeDependentResources(context, component, scripts);
+ Collection<Object> pageReadyScripts =
validatorScript.getPageReadyScripts();
+ if(!pageReadyScripts.isEmpty()){
+ encodeResource(component, context, JQUERY);
+ encodeDependentResources(context, component, pageReadyScripts);
+ }
+ responseWriter.startElement(SCRIPT, null);
+ responseWriter.writeAttribute(TYPE, TEXT_JAVASCRIPT, null);
+ for (Object script : scripts) {
+ ScriptUtils.writeToStream(responseWriter, script);
+ responseWriter.writeText("\n",null);
+ }
+ if(!pageReadyScripts.isEmpty()){
+ responseWriter.writeText("$(document).ready(function() {\n",null);
+ for (Object script : pageReadyScripts) {
+ ScriptUtils.writeToStream(responseWriter, script);
+ responseWriter.writeText("\n",null);
+ }
+ responseWriter.writeText("});\n",null);
+ }
+ responseWriter.endElement(SCRIPT);
+ }
+
+ private void encodeDependentResources(FacesContext context, UIComponent component,
Collection<Object> scripts) throws IOException {
+ for (Object script : scripts) {
+ if (script instanceof ResourceLibrary) {
+ ResourceLibrary library = (ResourceLibrary) script;
+ for( ResourceKey resource :library.getResources()){
+ encodeResource(component, context, resource);
+ }
+ }
+ }
+ }
+
+ private void encodeResource(UIComponent component,FacesContext context, ResourceKey
resource) throws IOException {
+ UIResource resourceComponent = new
UIResource(component,resource.getResourceName(),resource.getLibraryName());
+ resourceComponent.encodeAll(context);
+ }
+
+}
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Deleted:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptRenderer.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptRenderer.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptRenderer.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -1,74 +0,0 @@
-/**
- *
- */
-package org.richfaces.renderkit.html;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-
-import javax.faces.FacesException;
-import javax.faces.application.Resource;
-import javax.faces.application.ResourceHandler;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.Renderer;
-
-import org.richfaces.component.UIValidatorScript;
-import org.richfaces.resource.ResourceKey;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
-/**
- * @author asmirnov
- *
- */
-public class ValidatorScriptRenderer extends Renderer {
-
- public static final String RENDERER_TYPE =
"org.richfaces.renderer.ValidatorScriptRenderer";
- private static final String TEXT_JAVASCRIPT = "text/javascript";
- private static final String SRC = "src";
- private static final String TYPE = "type";
- private static final String SCRIPT = "script";
-
- @Override
- public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
- UIValidatorScript validatorScript = (UIValidatorScript) component;
-
- Collection<ComponentValidatorScript> scripts =
validatorScript.getScripts();
- // flatten all dependent resources.
- LinkedHashSet<ResourceKey> resources = Sets.newLinkedHashSet();
- for (ComponentValidatorScript script : scripts) {
- Iterables.addAll(resources, script.getResources(context));
- }
- // render dependencies
- for (ResourceKey resource : resources) {
- encodeResource(context, resource);
- }
- ResponseWriter responseWriter = context.getResponseWriter();
- responseWriter.startElement(SCRIPT, null);
- responseWriter.writeAttribute(TYPE, TEXT_JAVASCRIPT, null);
- for (ComponentValidatorScript componentValidatorScript : scripts) {
- responseWriter.writeText(componentValidatorScript.toScript(), null);
- responseWriter.write('\n');
- }
- responseWriter.endElement(SCRIPT);
- }
-
- private void encodeResource(FacesContext context, ResourceKey resource) throws
IOException {
- ResourceHandler resourceHandler = context.getApplication().getResourceHandler();
- Resource jsfResource = resourceHandler.createResource(resource.getResourceName(),
resource.getLibraryName());
- if (null != jsfResource) {
- ResponseWriter responseWriter = context.getResponseWriter();
- responseWriter.startElement(SCRIPT, null);
- responseWriter.writeAttribute(TYPE, TEXT_JAVASCRIPT, null);
- responseWriter.writeURIAttribute(SRC, jsfResource.getRequestPath(), null);
- responseWriter.endElement(SCRIPT);
- } else {
- throw new FacesException("Dependent resource "+resource.toString()+
" not found");
- }
- }
-
-}
Modified: branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/faces-config.xml
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/faces-config.xml 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/faces-config.xml 2010-12-01
00:40:36 UTC (rev 20246)
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" metadata-complete="false"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:cdk="http://jboss.org/schema/richfaces/cdk/extensions"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<component>
- <component-type>org.richfaces.ValidatorScript</component-type>
-
<component-class>org.richfaces.component.UIValidatorScript</component-class>
+ <component-type>org.richfaces.Scripts</component-type>
+ <component-class>org.richfaces.component.UIScripts</component-class>
</component>
<behavior>
<behavior-id>org.richfaces.behavior.ClientValidator</behavior-id>
@@ -11,8 +11,8 @@
<render-kit>
<renderer>
<component-family>org.richfaces.Script</component-family>
-
<renderer-type>org.richfaces.renderer.ValidatorScriptRenderer</renderer-type>
-
<renderer-class>org.richfaces.renderkit.html.ValidatorScriptRenderer</renderer-class>
+ <renderer-type>org.richfaces.renderer.ScriptsRenderer</renderer-type>
+
<renderer-class>org.richfaces.renderkit.html.ScriptsRenderer</renderer-class>
</renderer>
<client-behavior-renderer>
<client-behavior-renderer-type>org.richfaces.ClientValidatorRenderer</client-behavior-renderer-type>
Added:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/ValidatorTestBase.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/ValidatorTestBase.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/ValidatorTestBase.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,34 @@
+package org.richfaces;
+
+import javax.el.ValueExpression;
+
+import org.jboss.test.faces.mock.Environment;
+import org.jboss.test.faces.mock.Environment.Feature;
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockController;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.jboss.test.faces.mock.Stub;
+import org.junit.After;
+import org.richfaces.application.ServicesFactory;
+
+public class ValidatorTestBase {
+
+ @Mock()
+ @Environment({ Feature.APPLICATION, Feature.RENDER_KIT, Feature.EL_CONTEXT })
+ protected MockFacesEnvironment environment;
+ protected MockController controller;
+ @Mock
+ protected ValueExpression expression;
+ @Stub
+ protected ServicesFactory factory;
+
+ public ValidatorTestBase() {
+ super();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ controller.release();
+ }
+
+}
\ No newline at end of file
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/ValidatorTestBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/AjaxValidationTest.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -20,7 +20,7 @@
/**
- * Test for dynamic add/remove {@link UIValidatorScript} as view resource.
+ * Test for dynamic add/remove {@link UIScripts} as view resource.
* @author asmirnov
*
*/
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Bean.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Bean.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Bean.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -7,9 +7,10 @@
import java.util.Collection;
import java.util.Collections;
-import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.javascript.JavaScriptService;
import org.richfaces.renderkit.html.ComponentValidatorScript;
import org.richfaces.resource.ResourceKey;
@@ -49,7 +50,7 @@
}
}
- public Collection<ResourceKey> getResources(FacesContext context) {
+ public Collection<ResourceKey> getResources() {
return Collections.singleton(TEST_RESOURCE);
}
@@ -80,11 +81,9 @@
}
public String action() {
+ JavaScriptService javaScriptService =
ServiceTracker.getService(JavaScriptService.class);
FacesContext facesContext = FacesContext.getCurrentInstance();
- UIViewRoot viewRoot = facesContext.getViewRoot();
- UIValidatorScript resource = (UIValidatorScript)
facesContext.getApplication().createComponent(UIValidatorScript.COMPONENT_TYPE);
- resource.addOrFindScript(SCRIPT );
- viewRoot.addComponentResource(facesContext, resource);
+ javaScriptService.addPageReadyScript(facesContext, SCRIPT);
return null;
}
Deleted:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -1,77 +0,0 @@
-package org.richfaces.component;
-
-import java.io.IOException;
-import java.util.Collections;
-
-import javax.faces.context.FacesContext;
-
-import org.richfaces.javascript.LibraryScriptString;
-import org.richfaces.resource.ResourceKey;
-
-final class Script implements LibraryScriptString {
- private final String name;
-
- Script(String name) {
- this.name = name;
- }
-
- public String toScript() {
- return name;
- }
-
- public void appendScript(Appendable target) throws IOException {
- target.append(name);
- }
-
- public void appendScriptToStringBuilder(StringBuilder stringBuilder) {
- try {
- appendScript(stringBuilder);
- } catch (IOException e) {
- //ignore
- }
- }
-
- public Iterable<ResourceKey> getResources() {
- return Collections.singleton(UIValidatorScriptCollectionTest.FOO_RESOURCE);
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- return result;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- Script other = (Script) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- return true;
- }
-
- public String getName() {
- return name;
- }
-}
\ No newline at end of file
Deleted:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/UIValidatorScriptCollectionTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/UIValidatorScriptCollectionTest.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/UIValidatorScriptCollectionTest.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -1,72 +0,0 @@
-package org.richfaces.component;
-
-import static org.junit.Assert.*;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.junit.Test;
-import org.richfaces.javascript.LibraryScriptString;
-import org.richfaces.renderkit.html.ClientOnlyScript;
-import org.richfaces.renderkit.html.ComponentValidatorScript;
-import org.richfaces.resource.ResourceKey;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-/**
- * Test collection of validator scripts.
- * @author asmirnov
- *
- */
-public class UIValidatorScriptCollectionTest {
-
- static final ResourceKey FOO_RESOURCE =
ResourceKey.create("foo","org.rf");
-
-
- @Test
- public void testAddOrFindScript() {
- UIValidatorScript validatorScriptComponent = new UIValidatorScript();
- ComponentValidatorScript validatorScript = createValidatorScript("foo",
"bar");
- ComponentValidatorScript validatorScript2 =
validatorScriptComponent.addOrFindScript(validatorScript);
- Collection<ComponentValidatorScript> scripts =
validatorScriptComponent.getScripts();
- assertEquals(1, scripts.size());
- assertSame(validatorScript,Iterables.getOnlyElement(scripts));
- }
-
- @Test
- public void testAddOrFindScript2() {
- UIValidatorScript validatorScriptComponent = new UIValidatorScript();
- ComponentValidatorScript validatorScript = createValidatorScript("foo",
"bar");
- validatorScriptComponent.addOrFindScript(validatorScript);
- ComponentValidatorScript validatorScript2 =
createValidatorScript("fooz", "baz","bar");
- ComponentValidatorScript validatorScript3 =
validatorScriptComponent.addOrFindScript(validatorScript2);
- Collection<ComponentValidatorScript> scripts =
validatorScriptComponent.getScripts();
- assertEquals(2, scripts.size());
- assertSame(validatorScript2,validatorScript3);
- }
-
- @Test
- public void testAddOrFindScript3() {
- UIValidatorScript validatorScriptComponent = new UIValidatorScript();
- ComponentValidatorScript validatorScript = createValidatorScript("foo",
"bar");
- validatorScriptComponent.addOrFindScript(validatorScript);
- ComponentValidatorScript validatorScript2 =
createValidatorScript("foo", "bar");
- ComponentValidatorScript validatorScript3 =
validatorScriptComponent.addOrFindScript(validatorScript2);
- Collection<ComponentValidatorScript> scripts =
validatorScriptComponent.getScripts();
- assertEquals(1, scripts.size());
- assertSame(validatorScript,validatorScript3);
- }
-
- private LibraryScriptString createLibraryScript(final String name) {
- return new Script(name);
- }
-
- private ComponentValidatorScript createValidatorScript(String converter, String
...validators){
- ArrayList<LibraryScriptString> validatorScripts = Lists.newArrayList();
- for (String validatorName : validators) {
- validatorScripts.add(createLibraryScript(validatorName));
- }
- return new ClientOnlyScript(createLibraryScript(converter), validatorScripts);
- }
-}
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -14,7 +14,7 @@
/**
- * Test for dynamic add/remove {@link UIValidatorScript} as view resource.
+ * Test for dynamic add/remove {@link UIScripts} as view resource.
* @author asmirnov
*
*/
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorTestBase.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorTestBase.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/behavior/BehaviorTestBase.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -2,40 +2,24 @@
import static org.easymock.EasyMock.expect;
-import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.behavior.ClientBehaviorContext;
import javax.faces.render.ClientBehaviorRenderer;
-import org.jboss.test.faces.mock.Environment;
-import org.jboss.test.faces.mock.Environment.Feature;
import org.jboss.test.faces.mock.Mock;
-import org.jboss.test.faces.mock.MockController;
-import org.jboss.test.faces.mock.MockFacesEnvironment;
-import org.jboss.test.faces.mock.Stub;
-import org.junit.After;
import org.junit.Before;
-import org.richfaces.application.ServicesFactory;
+import org.richfaces.ValidatorTestBase;
-public class BehaviorTestBase {
+public class BehaviorTestBase extends ValidatorTestBase {
- @Mock()
- @Environment({ Feature.APPLICATION, Feature.RENDER_KIT,Feature.EL_CONTEXT })
- protected MockFacesEnvironment environment;
@Mock
protected UIInput input;
@Mock
protected ClientBehaviorContext behaviorContext;
@Mock
protected ClientBehaviorRenderer behaviorRenderer;
- protected MockController controller;
protected ClientValidatorBehavior behavior;
- @Mock
- protected ValueExpression expression;
- @Stub
- protected ServicesFactory factory;
-
public BehaviorTestBase() {
super();
}
@@ -46,11 +30,6 @@
}
- @After
- public void tearDown() throws Exception {
- controller.release();
- }
-
protected ClientBehaviorContext setupBehaviorContext(UIComponent component) {
expect(behaviorContext.getComponent()).andStubReturn(component);
expect(behaviorContext.getFacesContext()).andStubReturn(environment.getFacesContext());
Added:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,129 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.javascript;
+
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.jboss.test.faces.mock.Environment;
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockController;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.jboss.test.faces.mock.MockTestRunner;
+import org.jboss.test.faces.mock.Environment.Feature;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.ValidatorTestBase;
+import org.richfaces.component.UIScripts;
+import org.richfaces.renderkit.html.ClientOnlyScript;
+import org.richfaces.renderkit.html.ComponentValidatorScript;
+import org.richfaces.resource.ResourceKey;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+(a)RunWith(MockTestRunner.class)
+public class JavaScriptServiceTest extends ValidatorTestBase {
+
+ static final ResourceKey FOO_RESOURCE =
ResourceKey.create("foo","org.rf");
+
+
+ private UIScripts scriptResource;
+
+ private JavaScriptServiceImpl serviceImpl;
+
+ @Before
+ public void setUpResource(){
+ serviceImpl = new JavaScriptServiceImpl(){
+ @Override
+ UIScripts getOrCreateScriptResource(FacesContext facesContext) {
+ return scriptResource;
+ }
+ };
+ scriptResource = new UIScripts();
+ }
+
+ @After
+ public void cleanUpResource(){
+ scriptResource = null;
+ }
+
+
+ @Test
+ public void testAddOrFindScript() {
+ ComponentValidatorScript validatorScript = createValidatorScript("foo",
"bar");
+ ComponentValidatorScript validatorScript2 =
serviceImpl.addScript(environment.getFacesContext(),validatorScript);
+ Collection<Object> scripts = scriptResource.getScripts();
+ assertEquals(1, scripts.size());
+ assertSame(validatorScript,Iterables.getOnlyElement(scripts));
+ }
+
+ @Test
+ public void testAddOrFindScript2() {
+ ComponentValidatorScript validatorScript = createValidatorScript("foo",
"bar");
+ serviceImpl.addScript(environment.getFacesContext(),validatorScript);
+ ComponentValidatorScript validatorScript2 =
createValidatorScript("fooz", "baz","bar");
+ ComponentValidatorScript validatorScript3 =
serviceImpl.addScript(environment.getFacesContext(),validatorScript2);
+ Collection<Object> scripts = scriptResource.getScripts();
+ assertEquals(2, scripts.size());
+ assertSame(validatorScript2,validatorScript3);
+ }
+
+ @Test
+ public void testAddOrFindScript3() {
+ ComponentValidatorScript validatorScript = createValidatorScript("foo",
"bar");
+ serviceImpl.addScript(environment.getFacesContext(),validatorScript);
+ ComponentValidatorScript validatorScript2 =
createValidatorScript("foo", "bar");
+ ComponentValidatorScript validatorScript3 =
serviceImpl.addScript(environment.getFacesContext(),validatorScript2);
+ Collection<Object> scripts = scriptResource.getScripts();
+ assertEquals(1, scripts.size());
+ assertSame(validatorScript,validatorScript3);
+ }
+
+ private ScriptWithDependencies createLibraryScript(final String name) {
+ return new Script(name);
+ }
+
+ private ComponentValidatorScript createValidatorScript(String converter, String
...validators){
+ ArrayList<ScriptWithDependencies> validatorScripts = Lists.newArrayList();
+ for (String validatorName : validators) {
+ validatorScripts.add(createLibraryScript(validatorName));
+ }
+ return new ClientOnlyScript(createLibraryScript(converter), validatorScripts);
+ }
+
+}
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/Script.java
(from rev 20241,
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java)
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/Script.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/Script.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,74 @@
+package org.richfaces.javascript;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import org.richfaces.resource.ResourceKey;
+
+final class Script implements ScriptWithDependencies {
+ private final String name;
+
+ Script(String name) {
+ this.name = name;
+ }
+
+ public String toScript() {
+ return name;
+ }
+
+ public void appendScript(Appendable target) throws IOException {
+ target.append(name);
+ }
+
+ public void appendScriptToStringBuilder(StringBuilder stringBuilder) {
+ try {
+ appendScript(stringBuilder);
+ } catch (IOException e) {
+ //ignore
+ }
+ }
+
+ public Iterable<ResourceKey> getResources() {
+ return Collections.singleton(JavaScriptServiceTest.FOO_RESOURCE);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ Script other = (Script) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ return true;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
\ No newline at end of file
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/Script.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/ServiceGetOrCreateResourceTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/ServiceGetOrCreateResourceTest.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/ServiceGetOrCreateResourceTest.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,112 @@
+package org.richfaces.javascript;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockTestRunner;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.ValidatorTestBase;
+import org.richfaces.component.UIScripts;
+
+import com.google.common.collect.Lists;
+
+(a)RunWith(MockTestRunner.class)
+public class ServiceGetOrCreateResourceTest extends ValidatorTestBase {
+
+
+ @Mock
+ private UIViewRoot viewRoot;
+
+
+ private UIScripts scriptResource;
+
+ private JavaScriptServiceImpl serviceImpl;
+
+ @Before
+ public void setUpResource(){
+ serviceImpl = new JavaScriptServiceImpl();
+ scriptResource = new UIScripts();
+ }
+
+ @After
+ public void cleanUpResource(){
+ scriptResource = null;
+ }
+ /**
+ * <p class="changed_added_4_0">
+ * No resource exist in view, create a new one and store in "form" target.
+ * </p>
+ */
+ @Test
+ public void testCreateValidatorScriptResource() {
+ FacesContext facesContext = recordResources(null, null);
+ expect(environment.getApplication().createComponent(UIScripts.COMPONENT_TYPE))
+ .andReturn(scriptResource);
+ viewRoot.addComponentResource(facesContext, scriptResource);
+ expectLastCall();
+ verifyResult(facesContext);
+ }
+
+ private FacesContext recordResources(UIComponent formResource, UIComponent
bodyResource) {
+ FacesContext facesContext = recordViewRoot();
+ recordViewResources("form", formResource);
+ if(null == formResource || null != bodyResource){
+ recordViewResources("body", bodyResource);
+ }
+ return facesContext;
+ }
+
+ private void verifyResult(FacesContext facesContext) {
+ controller.replay();
+ assertSame(scriptResource, serviceImpl.getOrCreateScriptResource(facesContext));
+ controller.verify();
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * Resource already exists in "form" target
+ * </p>
+ */
+ @Test
+ public void testGetValidatorScriptResourceForm() {
+ FacesContext facesContext = recordResources(scriptResource, null);
+ verifyResult(facesContext);
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * Resource already exists in "body" target
+ * </p>
+ */
+ @Test
+ public void testGetValidatorScriptResourceBody() {
+ FacesContext facesContext = recordResources(null, scriptResource);
+ verifyResult(facesContext);
+ }
+
+
+ private void recordViewResources(String target, UIComponent resource) {
+ FacesContext facesContext = environment.getFacesContext();
+ List<UIComponent> resources = Lists.newArrayList();
+ if (null != resource) {
+ resources.add(resource);
+ }
+ expect(viewRoot.getComponentResources(facesContext,
target)).andReturn(resources);
+ }
+
+ private FacesContext recordViewRoot() {
+ FacesContext facesContext = environment.getFacesContext();
+ expect(facesContext.getViewRoot()).andStubReturn(viewRoot);
+ return facesContext;
+ }
+}
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/ServiceGetOrCreateResourceTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererBuildScriptTest.java
(from rev 20241,
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetOrCreateResourceTest.java)
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererBuildScriptTest.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererBuildScriptTest.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -0,0 +1,71 @@
+package org.richfaces.renderkit.html;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.context.FacesContext;
+
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockTestRunner;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.component.UIScripts;
+import org.richfaces.component.behavior.ClientValidatorBehavior;
+import org.richfaces.javascript.ClientScriptService;
+import org.richfaces.javascript.JavaScriptService;
+
+import com.google.common.collect.Lists;
+
+(a)RunWith(MockTestRunner.class)
+public class RendererBuildScriptTest extends RendererTestBase {
+
+ private static final String FUNCTION_NAME = "inputValidate";
+
+ private static final String SOURCE_ID ="clientValidator";
+
+ @Mock
+ private UIViewRoot viewRoot;
+
+ @Mock
+ private ComponentValidatorScript validatorScript;
+
+ @Mock
+ private JavaScriptService scriptService;
+
+ @Before
+ public void setUpResource(){
+ expect(factory.getInstance(JavaScriptService.class)).andReturn(scriptService);
+ ServiceTracker.setFactory(factory);
+ }
+
+ @After
+ public void cleanUpResource(){
+ ServiceTracker.release();
+ }
+
+ @Test
+ public void buildAndStoreScript() throws Exception {
+ ClientValidatorRenderer renderer = new ClientValidatorRenderer() {
+ ComponentValidatorScript createValidatorScript(ClientBehaviorContext
behaviorContext,
+ ClientValidatorBehavior behavior) {
+ return validatorScript;
+ };
+ };
+ setupBehaviorContext(input);
+ expect(behaviorContext.getSourceId()).andStubReturn(SOURCE_ID);
+
expect(validatorScript.createCallScript(FUNCTION_NAME,SOURCE_ID)).andReturn(FUNCTION_NAME);
+
expect(input.getClientId(environment.getFacesContext())).andReturn(FUNCTION_NAME);
+ expect(scriptService.addScript(environment.getFacesContext(),
validatorScript)).andReturn(validatorScript);
+ controller.replay();
+ assertEquals(FUNCTION_NAME,
renderer.buildAndStoreValidatorScript(behaviorContext, mockBehavior));
+ controller.verify();
+ }
+}
Property changes on:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererBuildScriptTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetClientSideScriptTest.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -20,7 +20,7 @@
import org.richfaces.application.ServiceTracker;
import org.richfaces.javascript.ClientScriptService;
import org.richfaces.javascript.LibraryFunction;
-import org.richfaces.javascript.LibraryScriptString;
+import org.richfaces.javascript.ScriptWithDependencies;
import org.richfaces.javascript.ScriptNotFoundException;
import org.richfaces.validator.ConverterDescriptor;
import org.richfaces.validator.ValidatorDescriptor;
@@ -63,7 +63,7 @@
expect(scriptService.getScript(environment.getFacesContext(),
RegexValidator.class)).andThrow(new ScriptNotFoundException());
controller.replay();
- Collection<? extends LibraryScriptString> clientSideValidatorScript =
renderer.getClientSideValidatorScript(
+ Collection<? extends ScriptWithDependencies> clientSideValidatorScript =
renderer.getClientSideValidatorScript(
environment.getFacesContext(), descriptors);
assertTrue(clientSideValidatorScript.isEmpty());
controller.verify();
@@ -88,7 +88,7 @@
expect(script.getName()).andReturn(REGEX_VALIDATOR).atLeastOnce();
expect(script.getResources()).andReturn(CLIENT_VALIDATOR_LIBRARY);
controller.replay();
- Collection<? extends LibraryScriptString> clientSideScripts =
renderer.getClientSideValidatorScript(environment.getFacesContext(), descriptors);
+ Collection<? extends ScriptWithDependencies> clientSideScripts =
renderer.getClientSideValidatorScript(environment.getFacesContext(), descriptors);
LibraryScriptFunction clientSideScript = (LibraryScriptFunction)
Iterables.getOnlyElement(clientSideScripts);
assertEquals(ClientValidatorRenderer.CONVERTED_VALUE_LITERAL,
clientSideScript.getParameters().get(0));
assertEquals(VALIDATOR_MESSAGE, clientSideScript.getParameters().get(1));
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -25,8 +25,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.javascript.LibraryFunction;
-import org.richfaces.javascript.LibraryScriptString;
import org.richfaces.javascript.ScriptNotFoundException;
+import org.richfaces.javascript.ScriptWithDependencies;
import org.richfaces.resource.ResourceKey;
import org.richfaces.validator.ConverterDescriptor;
import org.richfaces.validator.FacesObjectDescriptor;
@@ -139,7 +139,7 @@
// check what generated script contains ajax and client side scripts.
assertThat(script,
allOf(containsString(JSF_AJAX_REQUEST), containsString(REGEX_VALIDATOR),
containsString(NUMBER_CONVERTER)));
- assertThat(validatorScript.getResources(environment.getFacesContext()),
hasItem(CORE_LIBRARY_MATCHER));
+ assertThat(validatorScript.getResources(), hasItem(CORE_LIBRARY_MATCHER));
}
/**
@@ -175,7 +175,7 @@
script,
allOf(not(containsString(JSF_AJAX_REQUEST)),
containsString(REGEX_VALIDATOR),
not(containsString(NUMBER_CONVERTER))));
- assertThat(validatorScript.getResources(environment.getFacesContext()),
hasItem(CORE_LIBRARY_MATCHER));
+ assertThat(validatorScript.getResources(), hasItem(CORE_LIBRARY_MATCHER));
}
/**
@@ -196,7 +196,7 @@
script,
allOf(not(containsString(JSF_AJAX_REQUEST)),
containsString(REGEX_VALIDATOR),
containsString(NUMBER_CONVERTER)));
- assertThat(validatorScript.getResources(environment.getFacesContext()),
hasItem(CORE_LIBRARY_MATCHER));
+ assertThat(validatorScript.getResources(), hasItem(CORE_LIBRARY_MATCHER));
}
private LibraryScriptFunction createValidatorFunction() {
@@ -238,7 +238,7 @@
}
@Override
- Collection<? extends LibraryScriptString>
getClientSideValidatorScript(FacesContext facesContext,
+ Collection<? extends ScriptWithDependencies>
getClientSideValidatorScript(FacesContext facesContext,
Collection<ValidatorDescriptor> validators) {
return Lists.newArrayList(validatorFunctions);
}
Deleted:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetOrCreateResourceTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetOrCreateResourceTest.java 2010-11-30
19:36:09 UTC (rev 20245)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetOrCreateResourceTest.java 2010-12-01
00:40:36 UTC (rev 20246)
@@ -1,133 +0,0 @@
-package org.richfaces.renderkit.html;
-
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.*;
-
-import java.util.List;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
-import javax.faces.component.behavior.ClientBehaviorContext;
-import javax.faces.context.FacesContext;
-
-import org.jboss.test.faces.mock.Mock;
-import org.jboss.test.faces.mock.MockTestRunner;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.richfaces.component.UIValidatorScript;
-import org.richfaces.component.behavior.ClientValidatorBehavior;
-
-import com.google.common.collect.Lists;
-
-(a)RunWith(MockTestRunner.class)
-public class RendererGetOrCreateResourceTest extends RendererTestBase {
-
- private static final String FUNCTION_NAME = "inputValidate";
-
- private static final String SOURCE_ID ="clientValidator";
-
- @Mock
- private UIViewRoot viewRoot;
-
- @Mock
- private ComponentValidatorScript validatorScript;
-
- private UIValidatorScript scriptResource;
-
- @Before
- public void setUpResource(){
- scriptResource = new UIValidatorScript();
- }
-
- @After
- public void cleanUpResource(){
- scriptResource = null;
- }
- /**
- * <p class="changed_added_4_0">
- * No resource exist in view, create a new one and store in "form" target.
- * </p>
- */
- @Test
- public void testCreateValidatorScriptResource() {
- FacesContext facesContext = recordResources(null, null);
-
expect(environment.getApplication().createComponent(UIValidatorScript.COMPONENT_TYPE))
- .andReturn(scriptResource);
- viewRoot.addComponentResource(facesContext, scriptResource);
- expectLastCall();
- verifyResult(facesContext);
- }
-
- private FacesContext recordResources(UIComponent formResource, UIComponent
bodyResource) {
- FacesContext facesContext = recordViewRoot();
- recordViewResources("form", formResource);
- if(null == formResource || null != bodyResource){
- recordViewResources("body", bodyResource);
- }
- return facesContext;
- }
-
- private void verifyResult(FacesContext facesContext) {
- controller.replay();
- assertSame(scriptResource,
renderer.getOrCreateValidatorScriptResource(facesContext));
- controller.verify();
- }
-
- /**
- * <p class="changed_added_4_0">
- * Resource already exists in "form" target
- * </p>
- */
- @Test
- public void testGetValidatorScriptResourceForm() {
- FacesContext facesContext = recordResources(scriptResource, null);
- verifyResult(facesContext);
- }
-
- /**
- * <p class="changed_added_4_0">
- * Resource already exists in "body" target
- * </p>
- */
- @Test
- public void testGetValidatorScriptResourceBody() {
- FacesContext facesContext = recordResources(null, scriptResource);
- verifyResult(facesContext);
- }
-
- @Test
- public void buildAndStoreScript() throws Exception {
- FacesContext facesContext = recordResources(scriptResource, null);
- ClientValidatorRenderer renderer = new ClientValidatorRenderer() {
- ComponentValidatorScript createValidatorScript(ClientBehaviorContext
behaviorContext,
- ClientValidatorBehavior behavior) {
- return validatorScript;
- };
- };
- setupBehaviorContext(input);
- expect(behaviorContext.getSourceId()).andStubReturn(SOURCE_ID);
-
expect(validatorScript.createCallScript(FUNCTION_NAME,SOURCE_ID)).andReturn(FUNCTION_NAME);
- expect(input.getClientId(facesContext)).andReturn(FUNCTION_NAME);
- controller.replay();
- assertEquals(FUNCTION_NAME,
renderer.buildAndStoreValidatorScript(behaviorContext, mockBehavior));
- assertEquals(1, scriptResource.getScripts().size());
- controller.verify();
- }
-
- private void recordViewResources(String target, UIComponent resource) {
- FacesContext facesContext = environment.getFacesContext();
- List<UIComponent> resources = Lists.newArrayList();
- if (null != resource) {
- resources.add(resource);
- }
- expect(viewRoot.getComponentResources(facesContext,
target)).andReturn(resources);
- }
-
- private FacesContext recordViewRoot() {
- FacesContext facesContext = environment.getFacesContext();
- expect(facesContext.getViewRoot()).andStubReturn(viewRoot);
- return facesContext;
- }
-}