Author: alexsmirnov
Date: 2010-12-01 19:50:34 -0500 (Wed, 01 Dec 2010)
New Revision: 20283
Added:
branches/RF-8742-1/core/api/src/main/java/org/richfaces/javascript/
branches/RF-8742-1/core/api/src/main/java/org/richfaces/javascript/JavaScriptService.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UIResource.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UIScripts.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UITransient.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/javascript/
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceRenderer.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/component/Bean.java
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/component/UIViewResourceTest.java
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java
branches/RF-8742-1/core/impl/src/test/resources/org/richfaces/component/
branches/RF-8742-1/core/impl/src/test/resources/org/richfaces/component/faces-config.xml
Removed:
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/JavaScriptService.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/component/UITransient.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/component/UIViewResourceTest.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/resources/org/richfaces/component/faces-config.xml
Modified:
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/application/DefaultModule.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceLibraryRenderer.java
branches/RF-8742-1/core/impl/src/main/resources/META-INF/components.faces-config.xml
branches/RF-8742-1/core/impl/src/main/resources/META-INF/resource-library.faces-config.xml
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/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/resources/META-INF/faces-config.xml
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/renderkit/html/RendererBuildScriptTest.java
Log:
RESOLVED - issue RF-9612: Create JSF 2.0 resource loading extension to dynamically add
scripts and its dependencies.
https://jira.jboss.org/browse/RF-9612
Copied:
branches/RF-8742-1/core/api/src/main/java/org/richfaces/javascript/JavaScriptService.java
(from rev 20280,
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/JavaScriptService.java)
===================================================================
---
branches/RF-8742-1/core/api/src/main/java/org/richfaces/javascript/JavaScriptService.java
(rev 0)
+++
branches/RF-8742-1/core/api/src/main/java/org/richfaces/javascript/JavaScriptService.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -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/core/api/src/main/java/org/richfaces/javascript/JavaScriptService.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/application/DefaultModule.java
===================================================================
---
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/application/DefaultModule.java 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/application/DefaultModule.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -5,6 +5,8 @@
import org.richfaces.application.push.PushContextFactory;
import org.richfaces.application.push.impl.jms.PushContextFactoryImpl;
import org.richfaces.cache.Cache;
+import org.richfaces.javascript.JavaScriptService;
+import org.richfaces.javascript.JavaScriptServiceImpl;
import org.richfaces.l10n.BundleLoader;
import org.richfaces.renderkit.AjaxDataSerializer;
import org.richfaces.renderkit.AjaxDataSerializerImpl;
@@ -28,6 +30,8 @@
factory.setInstance(MessageFactory.class, new MessageFactoryImpl(new
BundleLoader()));
factory.setInstance(ResourceLibraryFactory.class, new
ResourceLibraryFactoryImpl());
factory.setInstance(PushContextFactory.class,
ServiceLoader.loadService(PushContextFactory.class, PushContextFactoryImpl.class));
+ factory.setInstance(JavaScriptService.class, new JavaScriptServiceImpl());
+
}
}
Copied: branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UIResource.java
(from rev 20280,
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIResource.java)
===================================================================
--- branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UIResource.java
(rev 0)
+++
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UIResource.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -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/core/impl/src/main/java/org/richfaces/component/UIResource.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UIScripts.java
(from rev 20280,
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIScripts.java)
===================================================================
--- branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UIScripts.java
(rev 0)
+++
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UIScripts.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -0,0 +1,102 @@
+/*
+ * $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.List;
+
+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";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.Script";
+
+ private final List<Object> scripts = Lists.newArrayList();
+
+ private final List<Object> pageReadyScripts = Lists.newArrayList();
+
+ private String target = "form";
+
+ 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/core/impl/src/main/java/org/richfaces/component/UIScripts.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UITransient.java (from
rev 20280,
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UITransient.java)
===================================================================
--- branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UITransient.java
(rev 0)
+++
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UITransient.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -0,0 +1,385 @@
+package org.richfaces.component;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UINamingContainer;
+import javax.faces.component.UniqueIdVendor;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+import javax.faces.render.Renderer;
+
+import org.richfaces.renderkit.html.ScriptsRenderer;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterators;
+
+public abstract class UITransient extends UIComponent {
+
+ private String id;
+
+ private UIComponent parent;
+
+ private final Map<String, Object> attributesMap = new AttributesMap();
+
+
+ private String clientId;
+
+ public UITransient() {
+ super();
+ }
+
+
+ public Object saveState(FacesContext context) {
+ // This is transient component
+ return null;
+ }
+
+ public void restoreState(FacesContext context, Object state) {
+ // Do nothing, this component never saved
+
+ }
+
+ public boolean isTransient() {
+ return true;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+
+ }
+
+ @Override
+ public Map<String, Object> getAttributes() {
+ return attributesMap;
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public ValueBinding getValueBinding(String name) {
+ return null;
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public void setValueBinding(String name, ValueBinding binding) {
+ // do nothing
+
+ }
+
+ @Override
+ public ValueExpression getValueExpression(String name) {
+ return null;
+ }
+
+ @Override
+ public void setValueExpression(String name, ValueExpression binding) {
+ // do nothing
+ }
+
+ @Override
+ public String getClientId(FacesContext context) {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ // if the clientId is not yet set
+ if (this.clientId == null) {
+ UIComponent namingContainerAncestor = this.getNamingContainer();
+ String parentId = null;
+
+ // give the parent the opportunity to first
+ // grab a unique clientId
+ if (namingContainerAncestor != null) {
+ parentId = namingContainerAncestor.getContainerClientId(context);
+ }
+
+ // now resolve our own client id
+ String clientId = getId();
+ if (clientId == null) {
+ if (null != namingContainerAncestor && namingContainerAncestor
instanceof UniqueIdVendor) {
+ clientId = ((UniqueIdVendor)
namingContainerAncestor).createUniqueId(context, null);
+ } else {
+ clientId = context.getViewRoot().createUniqueId();
+ }
+ setId(clientId);
+ }
+ if (parentId != null) {
+ StringBuilder idBuilder = new StringBuilder(parentId.length() + 1 +
clientId.length());
+ clientId =
idBuilder.append(parentId).append(UINamingContainer.getSeparatorChar(context))
+ .append(clientId).toString();
+ }
+
+ // allow the renderer to convert the clientId
+ Renderer renderer = this.getRenderer(context);
+ if (renderer != null) {
+ this.clientId = renderer.convertClientId(context, clientId);
+ } else {
+ this.clientId = clientId;
+ }
+ }
+ return this.clientId;
+ }
+
+ @Override
+ public String getId() {
+ return this.id;
+ }
+
+ @Override
+ public void setId(String id) {
+ this.id = id;
+ this.clientId = null;
+ }
+
+ @Override
+ public UIComponent getParent() {
+ return this.parent;
+ }
+
+ @Override
+ public void setParent(UIComponent parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public boolean isRendered() {
+ return true;
+ }
+
+ @Override
+ public void setRendered(boolean rendered) {
+ // always rendered
+ }
+
+ @Override
+ public String getRendererType() {
+ return ScriptsRenderer.RENDERER_TYPE;
+ }
+
+ @Override
+ public void setRendererType(String rendererType) {
+ // do nothing
+
+ }
+
+ @Override
+ public boolean getRendersChildren() {
+ return false;
+ }
+
+ @Override
+ public List<UIComponent> getChildren() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public int getChildCount() {
+ return 0;
+ }
+
+ @Override
+ public UIComponent findComponent(String expr) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Map<String, UIComponent> getFacets() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public UIComponent getFacet(String name) {
+ return null;
+ }
+
+ @Override
+ public Iterator<UIComponent> getFacetsAndChildren() {
+ return Iterators.emptyIterator();
+ }
+
+ @Override
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ // Do nothing
+ }
+
+ @Override
+ public void decode(FacesContext context) {
+ // Do nothing
+ }
+
+ @Override
+ public void encodeBegin(FacesContext context) throws IOException {
+ Renderer renderer = getRenderer(context);
+ if(null != renderer){
+ renderer.encodeBegin(context, this);
+ }
+ }
+
+ @Override
+ public void encodeChildren(FacesContext context) throws IOException {
+ Renderer renderer = getRenderer(context);
+ if(null != renderer){
+ renderer.encodeChildren(context, this);
+ }
+ }
+
+ @Override
+ public void encodeEnd(FacesContext context) throws IOException {
+ Renderer renderer = getRenderer(context);
+ if(null != renderer){
+ renderer.encodeEnd(context, this);
+ }
+ }
+
+ @Override
+ protected void addFacesListener(FacesListener listener) {
+ }
+
+ @Override
+ protected FacesListener[] getFacesListeners(Class clazz) {
+ return new FacesListener[0];
+ }
+
+ @Override
+ protected void removeFacesListener(FacesListener listener) {
+ }
+
+ @Override
+ public void queueEvent(FacesEvent event) {
+ if (null != getParent()) {
+ getParent().queueEvent(event);
+ }
+
+ }
+
+ @Override
+ public void processRestoreState(FacesContext context, Object state) {
+ // Do nothing, this component does not have state.
+
+ }
+
+ @Override
+ public void processDecodes(FacesContext context) {
+ // Do nothing
+
+ }
+
+ @Override
+ public void processValidators(FacesContext context) {
+ // Do nothing
+
+ }
+
+ @Override
+ public void processUpdates(FacesContext context) {
+ // Do nothing
+ }
+
+ @Override
+ public Object processSaveState(FacesContext context) {
+ // Should never be used
+ return null;
+ }
+
+ @Override
+ protected FacesContext getFacesContext() {
+ return FacesContext.getCurrentInstance();
+ }
+
+ @Override
+ protected Renderer getRenderer(FacesContext context) {
+ String rendererType = getRendererType();
+ Renderer result = null;
+ if (rendererType != null) {
+ result = context.getRenderKit().getRenderer(getFamily(), rendererType);
+ }
+ return result;
+ }
+
+ final class AttributesMap implements Map<String, Object> {
+
+ public void clear() {
+ // do nothing
+
+ }
+
+ public boolean containsKey(Object key) {
+
+ return
"target".equals(key)||"id".equals(key)||"clientId".equals(key)||hasAttribute(key);
+ }
+
+ public boolean containsValue(Object value) {
+ return false;
+ }
+
+ public Set<java.util.Map.Entry<String, Object>> entrySet() {
+ return Collections.emptySet();
+ }
+
+ public Object get(Object key) {
+ if ("id".equals(key)) {
+ return getId();
+ } else if ("clientId".equals(key)) {
+ return getClientId();
+ } else {
+ return getAttribute(key);
+ }
+ }
+
+ public boolean isEmpty() {
+ return false;
+ }
+
+ public Set<String> keySet() {
+ return
ImmutableSet.of("target","id","clientId");
+ }
+
+ public Object put(String key, Object value) {
+ if ("id".equals(key)) {
+ String id = getId();
+ setId((String) value);
+ return id;
+ } else {
+ return setAttribute(key, value);
+ }
+ }
+
+ public void putAll(Map<? extends String, ? extends Object> m) {
+
+
+ }
+
+ public Object remove(Object key) {
+ return null;
+ }
+
+ public int size() {
+ return 3;
+ }
+
+ public Collection<Object> values() {
+ 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
Property changes on:
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/UITransient.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java
(from rev 20280,
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java)
===================================================================
---
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java
(rev 0)
+++
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -0,0 +1,115 @@
+/*
+ * $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;
+
+/**
+ * <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");
+ UIScripts scriptResource = findScriptResource(componentResources);
+ if (null == scriptResource) {
+ componentResources = viewRoot.getComponentResources(facesContext,
"body");
+ scriptResource = findScriptResource(componentResources);
+ if (null == scriptResource) {
+ scriptResource = (UIScripts)
facesContext.getApplication().createComponent(UIScripts.COMPONENT_TYPE);
+ viewRoot.addComponentResource(facesContext, scriptResource);
+ }
+ }
+ return scriptResource;
+ }
+
+ private UIScripts findScriptResource(List<UIComponent> componentResources) {
+ for (UIComponent uiComponent : componentResources) {
+ if (uiComponent instanceof UIScripts) {
+ UIScripts script = (UIScripts) uiComponent;
+ return script;
+ }
+ }
+ return null;
+ }
+
+}
Property changes on:
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceLibraryRenderer.java
===================================================================
---
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceLibraryRenderer.java 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceLibraryRenderer.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -24,11 +24,8 @@
import java.io.IOException;
import java.util.Map;
-import javax.faces.application.Application;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
-import javax.faces.render.Renderer;
import org.richfaces.application.ServiceTracker;
import org.richfaces.log.Logger;
@@ -43,7 +40,7 @@
* @author Nick Belaevski
*
*/
-public class ResourceLibraryRenderer extends Renderer {
+public class ResourceLibraryRenderer extends ResourceRenderer {
public static final String RENDERER_TYPE =
"org.richfaces.renderkit.ResourceLibraryRenderer";
@@ -92,22 +89,9 @@
return;
}
- Application application = context.getApplication();
- UIComponent resourceComponent = null;
for (ResourceKey resourceKey: resourceLibrary.getResources()) {
- String rendererType =
application.getResourceHandler().getRendererTypeForResourceName(resourceKey.getResourceName());
-
- if (resourceComponent == null) {
- resourceComponent =
application.createComponent(UIOutput.COMPONENT_TYPE);
- resourceComponent.setTransient(true);
- component.getChildren().add(resourceComponent);
- }
-
- resourceComponent.setRendererType(rendererType);
- setupResourceAttributes(resourceComponent, resourceKey);
-
- resourceComponent.encodeAll(context);
+ encodeResource(component, context, resourceKey);
}
}
Added:
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceRenderer.java
===================================================================
---
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceRenderer.java
(rev 0)
+++
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceRenderer.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -0,0 +1,36 @@
+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.render.Renderer;
+
+import org.richfaces.component.UIResource;
+import org.richfaces.resource.ResourceKey;
+import org.richfaces.resource.ResourceLibrary;
+
+public abstract class ResourceRenderer extends Renderer {
+
+ public ResourceRenderer() {
+ super();
+ }
+
+ protected 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);
+ }
+ }
+ }
+ }
+
+ protected void encodeResource(UIComponent component, FacesContext context,
ResourceKey resource) throws IOException {
+ UIResource resourceComponent = new
UIResource(component,resource.getResourceName(),resource.getLibraryName());
+ resourceComponent.encodeAll(context);
+ }
+
+}
\ No newline at end of file
Property changes on:
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ResourceRenderer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java
(from rev 20280,
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java)
===================================================================
---
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java
(rev 0)
+++
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -0,0 +1,59 @@
+/**
+ *
+ */
+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 org.ajax4jsf.javascript.ScriptUtils;
+import org.richfaces.component.UIScripts;
+import org.richfaces.resource.ResourceKey;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ScriptsRenderer extends ResourceRenderer {
+
+ 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);
+ }
+
+}
Property changes on:
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified:
branches/RF-8742-1/core/impl/src/main/resources/META-INF/components.faces-config.xml
===================================================================
---
branches/RF-8742-1/core/impl/src/main/resources/META-INF/components.faces-config.xml 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/core/impl/src/main/resources/META-INF/components.faces-config.xml 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,21 +1,28 @@
<?xml version="1.0"?>
-<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- version="2.0">
-
+<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
<factory>
- <partial-view-context-factory>org.richfaces.context.PartialViewContextFactoryImpl</partial-view-context-factory>
+ <partial-view-context-factory>org.richfaces.context.PartialViewContextFactoryImpl
+ </partial-view-context-factory>
</factory>
-
+
<application>
<system-event-listener>
- <system-event-listener-class>org.richfaces.context.PartialViewContextAjaxOutputTracker</system-event-listener-class>
- <system-event-class>javax.faces.event.PreRemoveFromViewEvent</system-event-class>
+ <system-event-listener-class>org.richfaces.context.PartialViewContextAjaxOutputTracker
+ </system-event-listener-class>
+ <system-event-class>javax.faces.event.PreRemoveFromViewEvent
+ </system-event-class>
</system-event-listener>
<system-event-listener>
- <system-event-listener-class>org.richfaces.context.PartialViewContextAjaxOutputTracker</system-event-listener-class>
- <system-event-class>javax.faces.event.PostAddToViewEvent</system-event-class>
+ <system-event-listener-class>org.richfaces.context.PartialViewContextAjaxOutputTracker
+ </system-event-listener-class>
+ <system-event-class>javax.faces.event.PostAddToViewEvent
+ </system-event-class>
</system-event-listener>
</application>
+ <component>
+ <component-type>org.richfaces.Scripts</component-type>
+ <component-class>org.richfaces.component.UIScripts</component-class>
+ </component>
</faces-config>
Modified:
branches/RF-8742-1/core/impl/src/main/resources/META-INF/resource-library.faces-config.xml
===================================================================
---
branches/RF-8742-1/core/impl/src/main/resources/META-INF/resource-library.faces-config.xml 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/core/impl/src/main/resources/META-INF/resource-library.faces-config.xml 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,14 +1,22 @@
<?xml version="1.0"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
- version="2.0">
- <name>richfaces</name>
+ version="2.0">
+ <name>richfaces</name>
- <render-kit>
- <renderer>
- <component-family>javax.faces.Output</component-family>
-
<renderer-type>org.richfaces.renderkit.ResourceLibraryRenderer</renderer-type>
-
<renderer-class>org.richfaces.renderkit.html.ResourceLibraryRenderer</renderer-class>
- </renderer>
- </render-kit>
+ <render-kit>
+ <renderer>
+ <component-family>org.richfaces.Script</component-family>
+ <renderer-type>org.richfaces.renderer.ScriptsRenderer</renderer-type>
+ <renderer-class>org.richfaces.renderkit.html.ScriptsRenderer
+ </renderer-class>
+ </renderer>
+ <renderer>
+ <component-family>javax.faces.Output</component-family>
+ <renderer-type>org.richfaces.renderkit.ResourceLibraryRenderer
+ </renderer-type>
+ <renderer-class>org.richfaces.renderkit.html.ResourceLibraryRenderer
+ </renderer-class>
+ </renderer>
+ </render-kit>
</faces-config>
Copied: branches/RF-8742-1/core/impl/src/test/java/org/richfaces/component/Bean.java (from
rev 20280,
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Bean.java)
===================================================================
--- branches/RF-8742-1/core/impl/src/test/java/org/richfaces/component/Bean.java
(rev 0)
+++
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/component/Bean.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -0,0 +1,72 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+import java.util.Collections;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.javascript.JSLiteral;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.javascript.JavaScriptService;
+import org.richfaces.resource.ResourceKey;
+import org.richfaces.resource.ResourceLibrary;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class Bean {
+
+ private static final class TestScript extends JSLiteral implements ResourceLibrary {
+
+ public TestScript() {
+ super(TEST_SCRIPT);
+ }
+
+ public Iterable<ResourceKey> getResources() {
+ return Collections.singleton(TEST_RESOURCE);
+ }
+
+ }
+
+ public static final String TEST_SCRIPT_NAME = "test_script";
+
+ public static final String FOO_BAR = "foo.bar";
+
+ public static final String FOO = "foo";
+
+ public static final String FOO_VALUE = "fooValue";
+
+ public static final String TEST_SCRIPT = "function " + FOO +
"(id){alert(id);}";
+
+ private static final ResourceKey TEST_RESOURCE = ResourceKey.create(TEST_SCRIPT_NAME
+ ".js",FOO_BAR);
+
+ private static final ResourceLibrary SCRIPT = new TestScript();
+
+ private String value=FOO_VALUE;
+
+ /**
+ * @return the value
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * @param value the value to set
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String action() {
+ JavaScriptService javaScriptService =
ServiceTracker.getService(JavaScriptService.class);
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ javaScriptService.addPageReadyScript(facesContext, SCRIPT);
+ return null;
+ }
+
+
+}
Property changes on:
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/component/Bean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied:
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/component/UIViewResourceTest.java
(from rev 20280,
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java)
===================================================================
---
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/component/UIViewResourceTest.java
(rev 0)
+++
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/component/UIViewResourceTest.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -0,0 +1,68 @@
+package org.richfaces.component;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.MalformedURLException;
+
+import org.jboss.test.faces.FacesEnvironment;
+import org.jboss.test.faces.FacesEnvironment.FacesRequest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Test for dynamic add/remove {@link UIScripts} as view resource.
+ * @author asmirnov
+ *
+ */
+public class UIViewResourceTest {
+
+ private FacesEnvironment environment;
+
+
+ @Before
+ public void setUp() {
+ environment =
FacesEnvironment.createEnvironment().withContent("/test.xhtml",
+ "<html
xmlns=\"http://www.w3.org/1999/xhtml\"\n" +
+ "
xmlns:ui=\"http://java.sun.com/jsf/facelets\"\n" +
+ "
xmlns:h=\"http://java.sun.com/jsf/html\">"+
+ "<h:form id=\"helloForm\" >"+
+ " <h:inputText id=\"input\"
value=\"#{test.value}\" />\n" +
+ " <h:commandButton id=\"command\"
value=\"Ok\" action=\"#{test.action}\"/>\n" +
+ "</h:form>\n" +
+ "</html>").
+ withResource(FacesEnvironment.FACES_CONFIG_XML,
"org/richfaces/component/faces-config.xml").
+ start();
+ }
+
+ @After
+ public void thearDown() throws Exception{
+ environment.release();
+ environment = null;
+ }
+
+ @Test
+ public void testRequest() throws Exception {
+ FacesRequest request =
environment.createFacesRequest("http://localhost/test.jsf?foo=bar");
+ assertNotNull(request.execute());
+ String contentAsString = request.getConnection().getContentAsString();
+ assertFalse(contentAsString.contains(Bean.TEST_SCRIPT));
+ FacesRequest request2 = submit(request).submit();
+ request2.execute();
+ String content2 = request2.getConnection().getContentAsString();
+ assertFalse(content2.contains(Bean.TEST_SCRIPT));
+ }
+
+ private FacesRequest submit(FacesRequest request) throws MalformedURLException {
+ FacesRequest request2 =
request.submit().withParameter("helloForm:input",
"BAZ").withParameter("helloForm:command", "Ok");
+ request2.execute();
+ String content2 = request2.getConnection().getContentAsString();
+ assertTrue(content2.contains(Bean.TEST_SCRIPT));
+ return request2;
+ }
+
+
+}
Property changes on:
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/component/UIViewResourceTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied:
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java
(from rev 20280,
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java)
===================================================================
---
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java
(rev 0)
+++
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -0,0 +1,133 @@
+/*
+ * $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.Collection;
+
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+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.MockTestRunner;
+import org.jboss.test.faces.mock.Stub;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.application.ServicesFactory;
+import org.richfaces.component.UIScripts;
+import org.richfaces.resource.ResourceKey;
+
+import com.google.common.collect.Iterables;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+(a)RunWith(MockTestRunner.class)
+public class JavaScriptServiceTest {
+
+ static final ResourceKey FOO_RESOURCE =
ResourceKey.create("foo","org.rf");
+
+
+ protected UIScripts scriptResource;
+
+ protected JavaScriptServiceImpl serviceImpl;
+
+ @Mock()
+ @Environment({ Feature.APPLICATION, Feature.RENDER_KIT, Feature.EL_CONTEXT })
+ protected MockFacesEnvironment environment;
+ protected MockController controller;
+ @Mock
+ protected ValueExpression expression;
+ @Stub
+ protected ServicesFactory factory;
+
+
+ @After
+ public void tearDown() throws Exception {
+ controller.release();
+ }
+ @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() {
+ Object script = createScript("foo bar");
+ Object script2 = serviceImpl.addScript(environment.getFacesContext(),script);
+ Collection<Object> scripts = scriptResource.getScripts();
+ assertEquals(1, scripts.size());
+ assertSame(script,Iterables.getOnlyElement(scripts));
+ }
+
+ @Test
+ public void testAddOrFindScript2() {
+ Object script = createScript("foo bar");
+ serviceImpl.addScript(environment.getFacesContext(),script);
+ Object script2 = createScript("fooz baz bar");
+ Object script3 = serviceImpl.addScript(environment.getFacesContext(),script2);
+ Collection<Object> scripts = scriptResource.getScripts();
+ assertEquals(2, scripts.size());
+ assertSame(script2,script3);
+ }
+
+ @Test
+ public void testAddOrFindScript3() {
+ Object script = createScript("foo bar");
+ serviceImpl.addScript(environment.getFacesContext(),script);
+ Object script2 = createScript("foo bar");
+ Object script3 = serviceImpl.addScript(environment.getFacesContext(),script2);
+ Collection<Object> scripts = scriptResource.getScripts();
+ assertEquals(1, scripts.size());
+ assertSame(script,script3);
+ }
+
+
+ private Object createScript(String content){
+ return content;
+ }
+
+}
Property changes on:
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
branches/RF-8742-1/core/impl/src/test/resources/org/richfaces/component/faces-config.xml
(from rev 20280,
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/faces-config.xml)
===================================================================
---
branches/RF-8742-1/core/impl/src/test/resources/org/richfaces/component/faces-config.xml
(rev 0)
+++
branches/RF-8742-1/core/impl/src/test/resources/org/richfaces/component/faces-config.xml 2010-12-02
00:50:34 UTC (rev 20283)
@@ -0,0 +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">
+<managed-bean>
+ <managed-bean-name>test</managed-bean-name>
+ <managed-bean-class>org.richfaces.component.Bean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+</managed-bean>
+</faces-config>
\ No newline at end of file
Property changes on:
branches/RF-8742-1/core/impl/src/test/resources/org/richfaces/component/faces-config.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Deleted:
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 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/JavaScriptService.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,56 +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.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);
-}
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-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/application/ValidatorModule.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -66,7 +66,6 @@
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);
}
Deleted:
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 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIResource.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,125 +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 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;
- }
-}
Deleted:
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/component/UIScripts.java 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UIScripts.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,110 +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 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;
- }
-
-}
Deleted:
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-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/component/UITransient.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,386 +0,0 @@
-package org.richfaces.component;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.el.ValueExpression;
-import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UINamingContainer;
-import javax.faces.component.UniqueIdVendor;
-import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.FacesListener;
-import javax.faces.render.Renderer;
-
-import org.richfaces.renderkit.html.ScriptsRenderer;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterators;
-
-public abstract class UITransient extends UIComponent {
-
- private String id;
-
- private UIComponent parent;
-
- private final Map<String, Object> attributesMap = new AttributesMap();
-
-
- private String clientId;
-
- public UITransient() {
- super();
- }
-
-
- public Object saveState(FacesContext context) {
- // This is transient component
- return null;
- }
-
- public void restoreState(FacesContext context, Object state) {
- // Do nothing, this component never saved
-
- }
-
- public boolean isTransient() {
- return true;
- }
-
- public void setTransient(boolean newTransientValue) {
-
- }
-
- @Override
- public Map<String, Object> getAttributes() {
- return attributesMap;
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public ValueBinding getValueBinding(String name) {
- return null;
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public void setValueBinding(String name, ValueBinding binding) {
- // do nothing
-
- }
-
- @Override
- public ValueExpression getValueExpression(String name) {
- return null;
- }
-
- @Override
- public void setValueExpression(String name, ValueExpression binding) {
- // do nothing
- }
-
- @Override
- public String getClientId(FacesContext context) {
- if (context == null) {
- throw new NullPointerException();
- }
-
- // if the clientId is not yet set
- if (this.clientId == null) {
- UIComponent namingContainerAncestor = this.getNamingContainer();
- String parentId = null;
-
- // give the parent the opportunity to first
- // grab a unique clientId
- if (namingContainerAncestor != null) {
- parentId = namingContainerAncestor.getContainerClientId(context);
- }
-
- // now resolve our own client id
- String clientId = getId();
- if (clientId == null) {
- if (null != namingContainerAncestor && namingContainerAncestor
instanceof UniqueIdVendor) {
- clientId = ((UniqueIdVendor)
namingContainerAncestor).createUniqueId(context, null);
- } else {
- clientId = context.getViewRoot().createUniqueId();
- }
- setId(clientId);
- }
- if (parentId != null) {
- StringBuilder idBuilder = new StringBuilder(parentId.length() + 1 +
clientId.length());
- clientId =
idBuilder.append(parentId).append(UINamingContainer.getSeparatorChar(context))
- .append(clientId).toString();
- }
-
- // allow the renderer to convert the clientId
- Renderer renderer = this.getRenderer(context);
- if (renderer != null) {
- this.clientId = renderer.convertClientId(context, clientId);
- } else {
- this.clientId = clientId;
- }
- }
- return this.clientId;
- }
-
- @Override
- public String getId() {
- return this.id;
- }
-
- @Override
- public void setId(String id) {
- this.id = id;
- this.clientId = null;
- }
-
- @Override
- public UIComponent getParent() {
- return this.parent;
- }
-
- @Override
- public void setParent(UIComponent parent) {
- this.parent = parent;
- }
-
- @Override
- public boolean isRendered() {
- return true;
- }
-
- @Override
- public void setRendered(boolean rendered) {
- // always rendered
- }
-
- @Override
- public String getRendererType() {
- return ScriptsRenderer.RENDERER_TYPE;
- }
-
- @Override
- public void setRendererType(String rendererType) {
- // do nothing
-
- }
-
- @Override
- public boolean getRendersChildren() {
- return false;
- }
-
- @Override
- public List<UIComponent> getChildren() {
- return Collections.emptyList();
- }
-
- @Override
- public int getChildCount() {
- return 0;
- }
-
- @Override
- public UIComponent findComponent(String expr) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Map<String, UIComponent> getFacets() {
- return Collections.emptyMap();
- }
-
- @Override
- public UIComponent getFacet(String name) {
- return null;
- }
-
- @Override
- public Iterator<UIComponent> getFacetsAndChildren() {
- return Iterators.emptyIterator();
- }
-
- @Override
- public void broadcast(FacesEvent event) throws AbortProcessingException {
- // Do nothing
- }
-
- @Override
- public void decode(FacesContext context) {
- // Do nothing
- }
-
- @Override
- public void encodeBegin(FacesContext context) throws IOException {
- Renderer renderer = getRenderer(context);
- if(null != renderer){
- renderer.encodeBegin(context, this);
- }
- }
-
- @Override
- public void encodeChildren(FacesContext context) throws IOException {
- Renderer renderer = getRenderer(context);
- if(null != renderer){
- renderer.encodeChildren(context, this);
- }
- }
-
- @Override
- public void encodeEnd(FacesContext context) throws IOException {
- Renderer renderer = getRenderer(context);
- if(null != renderer){
- renderer.encodeEnd(context, this);
- }
- }
-
- @Override
- protected void addFacesListener(FacesListener listener) {
- }
-
- @Override
- protected FacesListener[] getFacesListeners(Class clazz) {
- return new FacesListener[0];
- }
-
- @Override
- protected void removeFacesListener(FacesListener listener) {
- }
-
- @Override
- public void queueEvent(FacesEvent event) {
- if (null != getParent()) {
- getParent().queueEvent(event);
- }
-
- }
-
- @Override
- public void processRestoreState(FacesContext context, Object state) {
- // Do nothing, this component does not have state.
-
- }
-
- @Override
- public void processDecodes(FacesContext context) {
- // Do nothing
-
- }
-
- @Override
- public void processValidators(FacesContext context) {
- // Do nothing
-
- }
-
- @Override
- public void processUpdates(FacesContext context) {
- // Do nothing
- }
-
- @Override
- public Object processSaveState(FacesContext context) {
- // Should never be used
- return null;
- }
-
- @Override
- protected FacesContext getFacesContext() {
- return FacesContext.getCurrentInstance();
- }
-
- @Override
- protected Renderer getRenderer(FacesContext context) {
- String rendererType = getRendererType();
- Renderer result = null;
- if (rendererType != null) {
- result = context.getRenderKit().getRenderer(getFamily(), rendererType);
- }
- return result;
- }
-
- final class AttributesMap implements Map<String, Object> {
-
- public void clear() {
- // do nothing
-
- }
-
- public boolean containsKey(Object key) {
-
- return
"target".equals(key)||"id".equals(key)||"clientId".equals(key)||hasAttribute(key);
- }
-
- public boolean containsValue(Object value) {
- return false;
- }
-
- public Set<java.util.Map.Entry<String, Object>> entrySet() {
- return Collections.emptySet();
- }
-
- public Object get(Object key) {
- if ("id".equals(key)) {
- return getId();
- } else if ("clientId".equals(key)) {
- return getClientId();
- } else {
- return getAttribute(key);
- }
- }
-
- public boolean isEmpty() {
- return false;
- }
-
- public Set<String> keySet() {
- return
ImmutableSet.of("target","id","clientId");
- }
-
- public Object put(String key, Object value) {
- if ("id".equals(key)) {
- String id = getId();
- setId((String) value);
- return id;
- } else {
- return setAttribute(key, value);
- }
- }
-
- public void putAll(Map<? extends String, ? extends Object> m) {
-
-
- }
-
- public Object remove(Object key) {
- return null;
- }
-
- public int size() {
- return 3;
- }
-
- public Collection<Object> values() {
- 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/javascript/JavaScriptServiceImpl.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/JavaScriptServiceImpl.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,112 +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.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();
- }
-
-}
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-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -2,13 +2,13 @@
import java.util.Collections;
-import javax.faces.context.FacesContext;
-
import org.richfaces.resource.ResourceKey;
public class AjaxOnlyScript extends ValidatorScriptBase {
+ public static final Iterable<ResourceKey>
AJAX_LIBRARIES=Collections.singleton(ResourceKey.create("ajax.reslib",
"org.richfaces"));
+
private final String ajaxScript;
public AjaxOnlyScript(String ajaxScript) {
@@ -18,7 +18,7 @@
}
public Iterable<ResourceKey> getResources() {
- return Collections.emptySet();
+ return AJAX_LIBRARIES;
}
@Override
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-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -3,8 +3,11 @@
import java.util.Collection;
import org.richfaces.javascript.ScriptWithDependencies;
+import org.richfaces.resource.ResourceKey;
+import com.google.common.collect.Iterables;
+
public class ClientAndAjaxScript extends ClientOnlyScript{
@@ -18,6 +21,11 @@
}
+ @Override
+ public Iterable<ResourceKey> getResources() {
+ return Iterables.concat(AjaxOnlyScript.AJAX_LIBRARIES,super.getResources());
+ }
+
protected void finishValidation(StringBuilder body) {
// AJAX callback
body.append("if(!").append(DISABLE_AJAX).append("){\n");
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-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -9,7 +9,7 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
-public class ClientOnlyScript extends ValidatorScriptBase{
+public class ClientOnlyScript extends ValidatorScriptBase {
protected final ScriptWithDependencies converter;
protected final Collection<? extends ScriptWithDependencies> validators;
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-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -10,7 +10,6 @@
import javax.faces.component.ActionSource;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
import javax.faces.component.behavior.ClientBehavior;
import javax.faces.component.behavior.ClientBehaviorContext;
import javax.faces.context.FacesContext;
@@ -21,14 +20,13 @@
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.application.ServiceTracker;
-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.ScriptWithDependencies;
import org.richfaces.javascript.ScriptNotFoundException;
+import org.richfaces.javascript.ScriptWithDependencies;
import org.richfaces.validator.ConverterDescriptor;
import org.richfaces.validator.FacesObjectDescriptor;
import org.richfaces.validator.ValidatorDescriptor;
Deleted:
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ScriptsRenderer.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,78 +0,0 @@
-/**
- *
- */
-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);
- }
-
-}
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-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/faces-config.xml 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,19 +1,10 @@
<?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.Scripts</component-type>
- <component-class>org.richfaces.component.UIScripts</component-class>
-</component>
<behavior>
<behavior-id>org.richfaces.behavior.ClientValidator</behavior-id>
<behavior-class>org.richfaces.component.behavior.ClientValidatorImpl</behavior-class>
</behavior>
<render-kit>
- <renderer>
- <component-family>org.richfaces.Script</component-family>
- <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>
<client-behavior-renderer-class>org.richfaces.renderkit.html.ClientValidatorRenderer</client-behavior-renderer-class>
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-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Bean.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,69 +1,9 @@
-/**
- *
- */
package org.richfaces.component;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Collections;
-
-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;
-
-/**
- * @author asmirnov
- *
- */
public class Bean {
- public static final String TEST_SCRIPT_NAME = "test_script";
-
- public static final String FOO_BAR = "foo.bar";
-
- public static final String FOO = "foo";
-
public static final String FOO_VALUE = "fooValue";
-
- public static final String TEST_SCRIPT = "function " + FOO +
"(id){alert(id);}";
-
- private static final ResourceKey TEST_RESOURCE = ResourceKey.create(TEST_SCRIPT_NAME
+ ".js",FOO_BAR);
- private static final ComponentValidatorScript SCRIPT = new ComponentValidatorScript()
{
-
- public String toScript() {
- return TEST_SCRIPT;
- }
-
- public void appendScript(Appendable target) throws IOException {
- target.append(TEST_SCRIPT);
- }
-
- public void appendScriptToStringBuilder(StringBuilder stringBuilder) {
- try {
- appendScript(stringBuilder);
- } catch (IOException e) {
- //ignore
- }
- }
-
- public Collection<ResourceKey> getResources() {
- return Collections.singleton(TEST_RESOURCE);
- }
-
- public String getName() {
- return FOO;
- }
-
- public String createCallScript(String clientId,String sourceId) {
- return FOO+"("+clientId+")";
- }
-
- };
-
private String value=FOO_VALUE;
/**
@@ -72,20 +12,11 @@
public String getValue() {
return value;
}
-
/**
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
-
- public String action() {
- JavaScriptService javaScriptService =
ServiceTracker.getService(JavaScriptService.class);
- FacesContext facesContext = FacesContext.getCurrentInstance();
- javaScriptService.addPageReadyScript(facesContext, SCRIPT);
- return null;
- }
-
}
Deleted:
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-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/UIViewResourceTest.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,70 +0,0 @@
-package org.richfaces.component;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.net.MalformedURLException;
-
-import org.jboss.test.faces.FacesEnvironment;
-import org.jboss.test.faces.FacesEnvironment.FacesRequest;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-
-/**
- * Test for dynamic add/remove {@link UIScripts} as view resource.
- * @author asmirnov
- *
- */
-public class UIViewResourceTest {
-
- private FacesEnvironment environment;
-
-
- @Before
- public void setUp() {
- environment =
FacesEnvironment.createEnvironment().withContent("/test.xhtml",
- "<html
xmlns=\"http://www.w3.org/1999/xhtml\"\n" +
- "
xmlns:ui=\"http://java.sun.com/jsf/facelets\"\n" +
- "
xmlns:h=\"http://java.sun.com/jsf/html\">"+
- "<h:form id=\"helloForm\" >"+
- " <h:inputText id=\"input\"
value=\"#{test.value}\" />\n" +
- " <h:commandButton id=\"command\"
value=\"Ok\" action=\"#{test.action}\"/>\n" +
- "</h:form>\n" +
- "</html>").
- withResource(FacesEnvironment.FACES_CONFIG_XML,
"org/richfaces/component/WEB-INF/faces-config.xml").
- start();
- }
-
- @After
- public void thearDown() throws Exception{
- environment.release();
- environment = null;
- }
-
- @Test
- public void testRequest() throws Exception {
- FacesRequest request =
environment.createFacesRequest("http://localhost/test.jsf?foo=bar");
- assertNotNull(request.execute());
- String contentAsString = request.getConnection().getContentAsString();
- assertFalse(contentAsString.contains(Bean.TEST_SCRIPT));
- FacesRequest request2 = submit(request).submit();
- request2.execute();
- String content2 = request2.getConnection().getContentAsString();
- assertFalse(content2.contains(Bean.TEST_SCRIPT));
- }
-
- private FacesRequest submit(FacesRequest request) throws MalformedURLException {
- FacesRequest request2 =
request.submit().withParameter("helloForm:input",
"BAZ").withParameter("helloForm:command", "Ok");
- request2.execute();
- String content2 = request2.getConnection().getContentAsString();
- assertTrue(content2.contains(Bean.TEST_SCRIPT));
- assertTrue(content2.contains(Bean.TEST_SCRIPT_NAME));
- assertTrue(content2.contains(Bean.FOO_BAR));
- return request2;
- }
-
-
-}
Deleted:
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 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/javascript/JavaScriptServiceTest.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,129 +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.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);
- }
-
-}
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererBuildScriptTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererBuildScriptTest.java 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererBuildScriptTest.java 2010-12-02
00:50:34 UTC (rev 20283)
@@ -3,12 +3,8 @@
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;
@@ -17,13 +13,9 @@
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;
-
@RunWith(MockTestRunner.class)
public class RendererBuildScriptTest extends RendererTestBase {
Deleted:
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/faces-config.xml
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/faces-config.xml 2010-12-01
20:22:27 UTC (rev 20282)
+++
branches/RF-8742-1/ui/validator/ui/src/test/resources/org/richfaces/component/faces-config.xml 2010-12-02
00:50:34 UTC (rev 20283)
@@ -1,8 +0,0 @@
-<?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">
-<managed-bean>
- <managed-bean-name>test</managed-bean-name>
- <managed-bean-class>org.richfaces.component.Bean</managed-bean-class>
- <managed-bean-scope>request</managed-bean-scope>
-</managed-bean>
-</faces-config>
\ No newline at end of file