Author: nbelaevski
Date: 2009-08-17 11:48:55 -0400 (Mon, 17 Aug 2009)
New Revision: 15186
Added:
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextAjaxOutputTracker.java
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextFactoryImpl.java
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java
root/framework/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java
root/framework/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
root/framework/trunk/impl/src/main/resources/META-INF/components.faces-config.xml
root/framework/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
root/framework/trunk/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java
Log:
Dynamic execute/render updated
Small resources refactoring
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2009-08-17
13:01:57 UTC (rev 15185)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2009-08-17
15:48:55 UTC (rev 15186)
@@ -25,6 +25,7 @@
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
@@ -127,6 +128,19 @@
public static final String SIMILARITY_GROUPING_ID_ATTR =
"similarityGroupingId";
private static final RendererUtils rendererUtils = RendererUtils.getInstance();
+
+ public static final String ALL = "@all";
+
+ public static final Collection<String> ALL_SET = Collections.singleton(ALL);
+
+ public static final String FORM = "@form";
+
+ public static final String THIS = "@this";
+
+ public static final String NONE = "@none";
+
+ public static final Collection<String> NONE_SET = Collections.singleton(NONE);
+
/**
* Static class - protect constructor
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2009-08-17
13:01:57 UTC (rev 15185)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2009-08-17
15:48:55 UTC (rev 15186)
@@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
@@ -970,7 +971,19 @@
*/
public Collection<String> findComponentsFor(FacesContext context, UIComponent
component, Collection<String> shortIds) {
//TODO - implement
- return shortIds;
+ //TODO add support for @*
+ Set<String> result = new LinkedHashSet<String>();
+ for (String id : shortIds) {
+ if (AjaxRendererUtils.THIS.equals(id)) {
+ result.add(component.getClientId(context));
+ } else if (AjaxRendererUtils.FORM.equals(id)) {
+ result.add(getNestingForm(context, component).getClientId(context));
+ } else {
+ result.add(id);
+ }
+ }
+
+ return result;
}
Added:
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextAjaxOutputTracker.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextAjaxOutputTracker.java
(rev 0)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextAjaxOutputTracker.java 2009-08-17
15:48:55 UTC (rev 15186)
@@ -0,0 +1,69 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.context;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+
+import org.ajax4jsf.component.AjaxOutput;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class PartialViewContextAjaxOutputTracker implements SystemEventListener {
+
+ private static final String AJAX_OUTPUT_COMPONENTS_SET_ATTRIBUTE =
+ PartialViewContextAjaxOutputTracker.class + ":AjaxOutputComponentsSet";
+
+ static Collection<AjaxOutput> getAjaxOutputComponentsSet(FacesContext context) {
+ AttributesContext attributes = SingletonsContext.FACES_CONTEXT.get(context);
+ Collection<AjaxOutput> components = (Collection<AjaxOutput>)
attributes.getAttribute(AJAX_OUTPUT_COMPONENTS_SET_ATTRIBUTE);
+ if (components == null) {
+ components = new ArrayList<AjaxOutput>();
+ attributes.setAttribute(AJAX_OUTPUT_COMPONENTS_SET_ATTRIBUTE, components);
+ }
+
+ return components;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.event.SystemEventListener#isListenerForSource(java.lang.Object)
+ */
+ public boolean isListenerForSource(Object source) {
+ return source instanceof AjaxOutput;
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.event.SystemEventListener#processEvent(javax.faces.event.SystemEvent)
+ */
+ public void processEvent(SystemEvent event) throws AbortProcessingException {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ getAjaxOutputComponentsSet(facesContext).add((AjaxOutput) event.getSource());
+ }
+
+}
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextFactoryImpl.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextFactoryImpl.java 2009-08-17
13:01:57 UTC (rev 15185)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextFactoryImpl.java 2009-08-17
15:48:55 UTC (rev 15186)
@@ -50,9 +50,6 @@
return partialViewContext;
}
- /* (non-Javadoc)
- * @see javax.faces.context.PartialViewContextFactory#getWrapped()
- */
@Override
public PartialViewContextFactory getWrapped() {
return parentFactory;
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java 2009-08-17
13:01:57 UTC (rev 15185)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java 2009-08-17
15:48:55 UTC (rev 15186)
@@ -21,13 +21,14 @@
package org.richfaces.context;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Set;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitHint;
@@ -37,6 +38,7 @@
import javax.faces.context.PartialViewContextWrapper;
import javax.faces.event.PhaseId;
+import org.ajax4jsf.component.AjaxOutput;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.RendererUtils;
@@ -50,6 +52,10 @@
private final String activatorId;
+ private boolean hasProcessedExecute = false;
+
+ private boolean executeAll = true;
+
public PartialViewContextImpl(PartialViewContext wrappedContext, String activatorId) {
super();
@@ -69,62 +75,189 @@
);
}
- private static final class ComponentIdsCallback implements VisitCallback {
+ private static class ComponentCallback implements VisitCallback {
+
+ private final String attributeName;
- private final String targetAttributeName;
+ private boolean handleAll;
- public ComponentIdsCallback(String targetAttributeName) {
+ private boolean handleNone;
+
+ private Collection<String> componentIds = new LinkedHashSet<String>();
+
+ public ComponentCallback(String attributeName, boolean handleNone,
+ boolean handleAll) {
super();
-
- this.targetAttributeName = targetAttributeName;
+ this.attributeName = attributeName;
+ this.handleNone = handleNone;
+ this.handleAll = handleAll;
}
-
- private Collection<String> componentIds = new LinkedHashSet<String>();
- public Collection<String> getComponentIds() {
- return componentIds;
+ protected void addDefaultComponents(Collection<String> ids) {
+
}
-
+
public VisitResult visit(VisitContext context, UIComponent target) {
- Object attributeValue = target.getAttributes().get(targetAttributeName);
+ Object attributeValue = target.getAttributes().get(attributeName);
Set<String> attributeIds = AjaxRendererUtils.asSet(attributeValue);
- if (attributeIds != null) {
- componentIds.addAll(RendererUtils.getInstance().findComponentsFor(context.getFacesContext(),
target, attributeIds));
+ if (attributeIds != null && !attributeIds.isEmpty()) {
+ if (attributeIds.contains(AjaxRendererUtils.ALL)) {
+ if (!AjaxRendererUtils.ALL_SET.equals(attributeIds)) {
+ //TODO: log
+ }
+
+ handleAll = true;
+ } else {
+ handleAll = false;
+
+ if (attributeIds.contains(AjaxRendererUtils.NONE)) {
+ if (!AjaxRendererUtils.NONE_SET.equals(attributeIds)) {
+ //TODO: log
+ }
+
+ handleNone = true;
+ } else {
+ //asSet() returns copy of original set and we're free to modify it
+ addDefaultComponents(attributeIds);
+
+ componentIds.addAll(RendererUtils.getInstance().findComponentsFor(
+ context.getFacesContext(), target, attributeIds));
+ }
+ }
}
return VisitResult.COMPLETE;
}
+
+ public Collection<String> getComponentIds() {
+ return componentIds;
+ }
+
+ public boolean isHandleAll() {
+ return handleAll;
+ }
+
+ public boolean isHandleNone() {
+ return handleNone;
+ }
}
- private Collection<String> getComponentIds(String targetAttributeName) {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- ComponentIdsCallback componentIdsCallback = new
ComponentIdsCallback(targetAttributeName);
+ private static class ExecuteComponentCallback extends ComponentCallback {
+
+ public ExecuteComponentCallback() {
+ super("execute", false, true);
+ }
+
+ @Override
+ protected void addDefaultComponents(Collection<String> ids) {
+ super.addDefaultComponents(ids);
+ ids.add(AjaxRendererUtils.THIS);
+ }
+
+ }
+
+ private static class RenderComponentCallback extends ComponentCallback {
- UIViewRoot viewRoot = facesContext.getViewRoot();
+ public RenderComponentCallback() {
+ super("render", false, false);
+ }
+
+ private boolean limitToList = false;
- boolean visitResult = viewRoot.visitTree(
- createVisitContext(facesContext),
- componentIdsCallback);
-
- if (!visitResult) {
- //TODO
+ public boolean isLimitToList() {
+ return limitToList;
}
+
+ public VisitResult visit(VisitContext context, UIComponent target) {
+ VisitResult visitResult = super.visit(context, target);
+
+ limitToList = AjaxRendererUtils.isAjaxLimitToList(target);
+
+ return visitResult;
+ }
+ }
+
+ //TODO: data table support
+ private Collection<String> getAjaxOutputComponentIds(FacesContext facesContext) {
+ List<String> ids = new ArrayList<String>();
+ Collection<AjaxOutput> ajaxOutputComponentsSet =
PartialViewContextAjaxOutputTracker.getAjaxOutputComponentsSet(facesContext);
+ for (AjaxOutput ajaxOutput : ajaxOutputComponentsSet) {
+ UIComponent ajaxOutputComponent = (UIComponent) ajaxOutput;
+ ids.add(ajaxOutputComponent.getClientId(facesContext));
+ }
- return componentIdsCallback.getComponentIds();
+ return ids;
}
+
+ private void processExecute(PartialViewContext partialViewContext) {
+ if (!hasProcessedExecute) {
+ hasProcessedExecute = true;
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ ExecuteComponentCallback executeCallback = new ExecuteComponentCallback();
+
+ boolean visitResult = facesContext.getViewRoot().visitTree(
+ createVisitContext(facesContext),
+ executeCallback);
+
+ if (!visitResult) {
+ //TODO:
+ }
+
+ executeAll = executeCallback.isHandleAll();
+ if (!executeAll) {
+ Collection<String> executeIds = partialViewContext.getExecuteIds();
+ executeIds.clear();
+
+ if (!executeCallback.isHandleNone()) {
+ executeIds.addAll(executeCallback.getComponentIds());
+ //TODO ids from wrapped object?
+ }
+ }
+ }
+ }
+ private void processRender(PartialViewContext partialViewContext) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if (!partialViewContext.isRenderAll()) {
+ RenderComponentCallback renderCallback = new RenderComponentCallback();
+ boolean visitResult = facesContext.getViewRoot().visitTree(
+ createVisitContext(facesContext),
+ renderCallback);
+
+ if (!visitResult) {
+ //TODO:
+ }
+
+ boolean renderAll = renderCallback.isHandleAll();
+ partialViewContext.setRenderAll(renderAll);
+ if (!renderAll) {
+ Collection<String> renderIds = partialViewContext.getRenderIds();
+ renderIds.clear();
+
+ if (!renderCallback.isHandleNone()) {
+ renderIds.addAll(renderCallback.getComponentIds());
+
+ if (!renderCallback.isLimitToList()) {
+ Collection<String> ajaxOutputComponentIds =
getAjaxOutputComponentIds(facesContext);
+ renderIds.addAll(ajaxOutputComponentIds);
+ //TODO ids from wrapped object?
+ }
+ }
+ }
+ }
+ }
+
@Override
public void processPartial(PhaseId phaseId) {
PartialViewContext wrapped = getWrapped();
if (PhaseId.APPLY_REQUEST_VALUES.equals(phaseId)) {
- Collection<String> executeIds = wrapped.getExecuteIds();
- executeIds.clear();
- executeIds.addAll(getComponentIds("execute"));
+ processExecute(wrapped);
} else if (PhaseId.RENDER_RESPONSE.equals(phaseId)) {
- Collection<String> renderIds = wrapped.getRenderIds();
- renderIds.clear();
- renderIds.addAll(getComponentIds("render"));
+ processRender(wrapped);
}
wrapped.processPartial(phaseId);
@@ -132,7 +265,39 @@
@Override
public void setPartialRequest(boolean isPartialRequest) {
- // TODO Auto-generated method stub
-
+ getWrapped().setPartialRequest(isPartialRequest);
}
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.PartialViewContextWrapper#getRenderIds()
+ */
+ @Override
+ public Collection<String> getRenderIds() {
+ return getWrapped().getRenderIds();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.PartialViewContextWrapper#getExecuteIds()
+ */
+ @Override
+ public Collection<String> getExecuteIds() {
+ return getWrapped().getExecuteIds();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.PartialViewContextWrapper#isExecuteAll()
+ */
+ @Override
+ public boolean isExecuteAll() {
+ processExecute(getWrapped());
+ return executeAll;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.PartialViewContextWrapper#isRenderAll()
+ */
+ @Override
+ public boolean isRenderAll() {
+ return getWrapped().isRenderAll();
+ }
}
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2009-08-17
13:01:57 UTC (rev 15185)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2009-08-17
15:48:55 UTC (rev 15186)
@@ -79,7 +79,7 @@
* <b>IMPORTANT:</b> this method returned TTL in RF 3.x, now it returns
expiration time
* @return Returns the expired.
*/
- protected Date getExpired(FacesContext context) {
+ protected Date getExpires(FacesContext context) {
return null;
}
@@ -252,7 +252,7 @@
if (maxAge > 0) {
formattedExpireDate = Util.formatHttpDate(currentTime + maxAge * 1000L);
} else {
- Date expired = getExpired(facesContext);
+ Date expired = getExpires(facesContext);
if (expired != null) {
formattedExpireDate = Util.formatHttpDate(expired);
maxAge = (expired.getTime() - currentTime) / 1000L;
@@ -327,7 +327,7 @@
return System.currentTimeMillis() + ttl * 1000;
}
- Date date = AbstractBaseResource.this.getExpired(facesContext);
+ Date date = AbstractBaseResource.this.getExpires(facesContext);
if (date != null) {
return date.getTime();
}
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2009-08-17
13:01:57 UTC (rev 15185)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2009-08-17
15:48:55 UTC (rev 15186)
@@ -102,6 +102,7 @@
CacheManager cacheManager = CacheManager.getInstance();
Map<?,?> envMap = facesContext.getExternalContext().getInitParameterMap();
cacheManager.createCache(RESOURCE_CACHE_NAME, envMap);
+ cache = cacheManager.getCache(RESOURCE_CACHE_NAME);
}
private void markStartTime(FacesContext facesContext) {
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/components.faces-config.xml
===================================================================
---
root/framework/trunk/impl/src/main/resources/META-INF/components.faces-config.xml 2009-08-17
13:01:57 UTC (rev 15185)
+++
root/framework/trunk/impl/src/main/resources/META-INF/components.faces-config.xml 2009-08-17
15:48:55 UTC (rev 15186)
@@ -6,5 +6,12 @@
<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.PostAddToViewEvent</system-event-class>
+ </system-event-listener>
+ </application>
</faces-config>
Modified:
root/framework/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
===================================================================
---
root/framework/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2009-08-17
13:01:57 UTC (rev 15185)
+++
root/framework/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2009-08-17
15:48:55 UTC (rev 15186)
@@ -164,7 +164,7 @@
}
@Override
- protected Date getExpired(FacesContext context) {
+ protected Date getExpires(FacesContext context) {
return expired;
}
@@ -362,7 +362,7 @@
assertEquals(-1, defaultResource.getContentLength(facesContext));
assertNull(defaultResource.getEntityTag(facesContext));
assertNull(defaultResource.getVersion());
- assertNull(defaultResource.getExpired(facesContext));
+ assertNull(defaultResource.getExpires(facesContext));
Date lastModified = defaultResource.getLastModified(facesContext);
assertNotNull(lastModified);
assertTrue(System.currentTimeMillis() >= lastModified.getTime());
Modified:
root/framework/trunk/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java
===================================================================
---
root/framework/trunk/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java 2009-08-17
13:01:57 UTC (rev 15185)
+++
root/framework/trunk/impl/src/test/java/org/richfaces/resource/CacheableResourceImpl.java 2009-08-17
15:48:55 UTC (rev 15186)
@@ -77,7 +77,7 @@
}
@Override
- protected Date getExpired(FacesContext context) {
+ protected Date getExpires(FacesContext context) {
return ResourceHandlerImplTest.expires;
}
}