Author: nbelaevski
Date: 2009-07-30 18:39:12 -0400 (Thu, 30 Jul 2009)
New Revision: 15070
Added:
root/framework/trunk/impl/src/main/java/org/richfaces/context/AttributesContext.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/context/SingletonsContext.java
root/framework/trunk/impl/src/main/resources/META-INF/components.faces-config.xml
Removed:
root/framework/trunk/impl/src/main/java/org/richfaces/context/AbstractContext.java
root/framework/trunk/impl/src/main/java/org/richfaces/context/ApplicationContext.java
root/framework/trunk/impl/src/main/java/org/richfaces/context/RequestContext.java
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.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/faces-config.xml
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js
Log:
Further work on framework
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-07-30
16:13:54 UTC (rev 15069)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -196,47 +196,88 @@
public static StringBuffer buildOnEvent(UIComponent uiComponent,
FacesContext facesContext, String eventName, boolean omitDefaultActionUrl) {
StringBuffer onEvent = new StringBuffer();
- if (null != eventName) {
- String commandOnEvent = (String) uiComponent.getAttributes().get(
- eventName);
- if (commandOnEvent != null) {
- onEvent.append(commandOnEvent);
- onEvent.append(';');
- }
- }
- JSFunction ajaxFunction = buildAjaxFunction(uiComponent, facesContext);
- // Create formal parameter for non-input elements ???
- // Link Control pseudo-object
- // Options map. Possible options for function call :
- // control - name of form control for submit.
- // name - name for link control \
- // value - value of control. - possible replace by parameters ?
- // single true/false - submit all form or only one control.
- // affected - array of element's ID for update on responce.
- // oncomplete - function for call after complete request.
- // status - id of request status component.
- // parameters - map of parameters name/value for append on request.
- // ..........
- ajaxFunction.addParameter(buildEventOptions(facesContext, uiComponent,
omitDefaultActionUrl));
+// if (null != eventName) {
+// String commandOnEvent = (String) uiComponent.getAttributes().get(
+// eventName);
+// if (commandOnEvent != null) {
+// onEvent.append(commandOnEvent);
+// onEvent.append(';');
+// }
+// }
+// JSFunction ajaxFunction = buildAjaxFunction(uiComponent, facesContext);
+// // Create formal parameter for non-input elements ???
+// // Link Control pseudo-object
+// // Options map. Possible options for function call :
+// // control - name of form control for submit.
+// // name - name for link control \
+// // value - value of control. - possible replace by parameters ?
+// // single true/false - submit all form or only one control.
+// // affected - array of element's ID for update on responce.
+// // oncomplete - function for call after complete request.
+// // status - id of request status component.
+// // parameters - map of parameters name/value for append on request.
+// // ..........
+// ajaxFunction.addParameter(buildEventOptions(facesContext, uiComponent,
omitDefaultActionUrl));
+//
+// // appendAjaxSubmitParameters(facesContext, uiComponent, onEvent);
+// ajaxFunction.appendScript(onEvent);
+// if (uiComponent instanceof AjaxSupport) {
+// AjaxSupport support = (AjaxSupport) uiComponent;
+// if (support.isDisableDefault()) {
+// onEvent.append("; return false;");
+// }
+// }
+// log.debug(Messages.getMessage(Messages.BUILD_ONCLICK_INFO, uiComponent
+// .getId(), onEvent.toString()));
+ return onEvent;
- // appendAjaxSubmitParameters(facesContext, uiComponent, onEvent);
- ajaxFunction.appendScript(onEvent);
- if (uiComponent instanceof AjaxSupport) {
- AjaxSupport support = (AjaxSupport) uiComponent;
- if (support.isDisableDefault()) {
- onEvent.append("; return false;");
+ }
+
+ private static void appendParameters(FacesContext context, UIComponent component,
Map<String, Object> parameters) {
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : component.getChildren()) {
+ if (child instanceof UIParameter) {
+ UIParameter parameter = (UIParameter) child;
+
+ String name = parameter.getName();
+ Object value = parameter.getValue();
+
+ if (null == name) {
+ throw new IllegalArgumentException(Messages.getMessage(
+ Messages.UNNAMED_PARAMETER_ERROR, component
+ .getClientId(context)));
+ }
+
+ boolean escape = true;
+ if (child instanceof JavaScriptParameter) {
+ JavaScriptParameter actionParam = (JavaScriptParameter) child;
+ escape = !actionParam.isNoEscape();
+ }
+ if (escape) {
+ if(value == null) {
+ value = "";
+ }
+ parameters.put(name, value);
+ } else {
+ parameters.put(name, new JSReference(value.toString()));
+ // if(it.hasNext()){onEvent.append(',');};
+ // renderAjaxLinkParameter( name,
+ // value, onClick, jsForm, nestingForm);
+ }
+ }
}
}
- log.debug(Messages.getMessage(Messages.BUILD_ONCLICK_INFO, uiComponent
- .getId(), onEvent.toString()));
- return onEvent;
-
}
-
+
public static Map<String, Object> buildEventOptions(FacesContext facesContext,
UIComponent component) {
- return buildEventOptions(facesContext, component, null);
+ Map<String,Object> options = new HashMap<String, Object>();
+ appendParameters(facesContext, component, options);
+
+ String clientId = component.getClientId(facesContext);
+ options.put(clientId, clientId);
+ return options;
}
public static Map<String, Object> buildEventOptions(FacesContext facesContext,
@@ -245,12 +286,6 @@
return buildEventOptions(facesContext, uiComponent, params, false);
}
- public static Map<String, Object> buildEventOptions(FacesContext facesContext,
- UIComponent component, boolean omitDefaultActionUrl) {
-
- return buildEventOptions(facesContext, component, null, omitDefaultActionUrl);
- }
-
/**
* @param facesContext
* @param uiComponent
@@ -317,34 +352,7 @@
// Add application-wide Ajax parameters
parameters.putAll(ajaxContext.getCommonAjaxParameters());
// add child parameters
- for (Iterator<UIComponent> it = uiComponent.getChildren().iterator();
it.hasNext();) {
- UIComponent child = it.next();
- if (child instanceof UIParameter) {
- String name = ((UIParameter) child).getName();
- Object value = ((UIParameter) child).getValue();
- if (null == name) {
- throw new IllegalArgumentException(Messages.getMessage(
- Messages.UNNAMED_PARAMETER_ERROR, uiComponent
- .getClientId(facesContext)));
- }
- boolean escape = true;
- if (child instanceof JavaScriptParameter) {
- JavaScriptParameter actionParam = (JavaScriptParameter) child;
- escape = !actionParam.isNoEscape();
- }
- if (escape) {
- if(value == null) {
- value = "";
- }
- parameters.put(name, value);
- } else {
- parameters.put(name, new JSReference(value.toString()));
- // if(it.hasNext()){onEvent.append(',');};
- // renderAjaxLinkParameter( name,
- // value, onClick, jsForm, nestingForm);
- }
- }
- }
+ appendParameters(facesContext, uiComponent, parameters);
if (params != null) {
parameters.putAll(params);
@@ -468,13 +476,8 @@
public static JSFunction buildAjaxFunction(UIComponent uiComponent,
FacesContext facesContext, String functionName) {
JSFunction ajaxFunction = new JSFunction(functionName);
- // build form name or ActionUrl for script
- UIComponent nestingForm = getNestingForm(uiComponent);
- if (null == nestingForm) {
- ajaxFunction.addParameter(JSReference.NULL);
- } else {
- ajaxFunction.addParameter(nestingForm.getClientId(facesContext));
- }
+ ajaxFunction.addParameter(uiComponent.getClientId(facesContext));
+ ajaxFunction.addParameter("event");
return ajaxFunction;
}
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java 2009-07-30
16:13:54 UTC (rev 15069)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -29,6 +29,7 @@
import javax.faces.render.Renderer;
import org.ajax4jsf.Messages;
+import org.ajax4jsf.resource.InternetResource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.richfaces.skin.Skin;
@@ -247,4 +248,8 @@
child.encodeEnd(facesContext);
}
+ //TODO method stub - replace with JSF 2.0 annotations
+ public InternetResource getResource(String name) {
+ return null;
+ }
}
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-07-30
16:13:54 UTC (rev 15069)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -961,6 +961,18 @@
writer.endElement(HTML.SCRIPT_ELEM);
}
+ /**
+ * @param context
+ * @param component
+ * @param shortIds
+ * @since 4.0
+ * @return
+ */
+ public Collection<String> findComponentsFor(FacesContext context, UIComponent
component, Collection<String> shortIds) {
+ //TODO - implement
+ return shortIds;
+ }
+
public UIComponent findComponentFor(FacesContext context,
UIComponent component, String id) {
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.java 2009-07-30
16:13:54 UTC (rev 15069)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/webapp/PollEventsManager.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -30,6 +30,7 @@
* @author asmirnov
*
*/
+//TODO: deprecate
public class PollEventsManager implements Serializable {
/**
@@ -39,6 +40,7 @@
public static final String EVENTS_MANAGER_KEY = PollEventsManager.class.getName();
+ //TODO should use cache - push is application-scoped, not session-scoped
private ConcurrentMap<String, PushEventsCounter> counters = new
ConcurrentHashMap<String, PushEventsCounter>();
public void init(ServletContext servletContext) {
Deleted:
root/framework/trunk/impl/src/main/java/org/richfaces/context/AbstractContext.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/AbstractContext.java 2009-07-30
16:13:54 UTC (rev 15069)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/AbstractContext.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -1,34 +0,0 @@
-package org.richfaces.context;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public abstract class AbstractContext {
-
- private Map<String, Object> attributesMap = null;
-
- public Object getAttribute(String name) {
- Object result = null;
-
- if (attributesMap != null) {
- result = attributesMap.get(name);
- }
-
- return result;
- }
-
- public void setAttribute(String name, Object value) {
- if (value != null) {
- if (attributesMap == null) {
- attributesMap = new HashMap<String, Object>();
- }
-
- attributesMap.put(name, value);
- } else {
- if (attributesMap != null) {
- attributesMap.remove(name);
- }
- }
- }
-
-}
Deleted:
root/framework/trunk/impl/src/main/java/org/richfaces/context/ApplicationContext.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/ApplicationContext.java 2009-07-30
16:13:54 UTC (rev 15069)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/ApplicationContext.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -1,42 +0,0 @@
-/**
- *
- */
-package org.richfaces.context;
-
-import java.util.Map;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-
-/**
- * @author Nick Belaevski
- * @since 4.0
- */
-public final class ApplicationContext extends AbstractContext {
-
- private static final String APPLICATION_ATTRIBUTE_NAME =
ApplicationContext.class.getName();
-
- private ApplicationContext() {
- super();
- }
-
- public static ApplicationContext getInstance() {
- return getInstance(FacesContext.getCurrentInstance());
- }
-
- public static ApplicationContext getInstance(FacesContext context) {
- ExternalContext externalContext = context.getExternalContext();
- Map<String, Object> applicationMap = externalContext.getApplicationMap();
-
- ApplicationContext applicationContext = (ApplicationContext)
applicationMap.get(APPLICATION_ATTRIBUTE_NAME);
- if (applicationContext == null) {
- applicationContext = new ApplicationContext();
-
- applicationMap.put(APPLICATION_ATTRIBUTE_NAME, applicationContext);
- }
-
- return applicationContext;
- }
-
-
-}
Copied:
root/framework/trunk/impl/src/main/java/org/richfaces/context/AttributesContext.java (from
rev 15069,
root/framework/trunk/impl/src/main/java/org/richfaces/context/AbstractContext.java)
===================================================================
--- root/framework/trunk/impl/src/main/java/org/richfaces/context/AttributesContext.java
(rev 0)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/AttributesContext.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -0,0 +1,22 @@
+package org.richfaces.context;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class AttributesContext {
+
+ private Map<String, Object> attributesMap = new HashMap<String, Object>();
+
+ public Object getAttribute(String name) {
+ return attributesMap.get(name);
+ }
+
+ public Object setAttribute(String name, Object value) {
+ if (value != null) {
+ return attributesMap.put(name, value);
+ } else {
+ return attributesMap.remove(name);
+ }
+ }
+
+}
Added:
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextFactoryImpl.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextFactoryImpl.java
(rev 0)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextFactoryImpl.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -0,0 +1,61 @@
+/**
+ * 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 javax.faces.context.FacesContext;
+import javax.faces.context.PartialViewContext;
+import javax.faces.context.PartialViewContextFactory;
+
+/**
+ * @author Nick Belaevski
+ * @since 4.0
+ */
+public class PartialViewContextFactoryImpl extends PartialViewContextFactory {
+
+ private PartialViewContextFactory parentFactory;
+
+ public PartialViewContextFactoryImpl(PartialViewContextFactory parentFactory) {
+ super();
+ this.parentFactory = parentFactory;
+ }
+
+ @Override
+ public PartialViewContext getPartialViewContext(final FacesContext context) {
+ PartialViewContext partialViewContext = parentFactory.getPartialViewContext(context);
+
+ String clientId =
context.getExternalContext().getRequestParameterMap().get("RICHFACES_AJAX");
+ if (clientId != null) {
+ partialViewContext = new PartialViewContextImpl(partialViewContext, clientId);
+ }
+
+ return partialViewContext;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.context.PartialViewContextFactory#getWrapped()
+ */
+ @Override
+ public PartialViewContextFactory getWrapped() {
+ return parentFactory;
+ }
+
+}
Added:
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java
(rev 0)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/PartialViewContextImpl.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -0,0 +1,138 @@
+/**
+ * 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.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+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;
+import javax.faces.component.visit.VisitResult;
+import javax.faces.context.FacesContext;
+import javax.faces.context.PartialViewContext;
+import javax.faces.context.PartialViewContextWrapper;
+import javax.faces.event.PhaseId;
+
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.RendererUtils;
+
+/**
+ * @author Nick Belaevski
+ * @since 4.0
+ */
+public class PartialViewContextImpl extends PartialViewContextWrapper {
+
+ private final PartialViewContext wrappedContext;
+
+ private final String activatorId;
+
+ public PartialViewContextImpl(PartialViewContext wrappedContext, String activatorId) {
+ super();
+
+ this.wrappedContext = wrappedContext;
+ this.activatorId = activatorId;
+ }
+
+ @Override
+ public PartialViewContext getWrapped() {
+ return wrappedContext;
+ }
+
+ private VisitContext createVisitContext(FacesContext facesContext) {
+ return VisitContext.createVisitContext(facesContext,
+ Collections.singleton(activatorId),
+ Collections.singleton(VisitHint.SKIP_UNRENDERED)
+ );
+ }
+
+ private static final class ComponentIdsCallback implements VisitCallback {
+
+ private final String targetAttributeName;
+
+ public ComponentIdsCallback(String targetAttributeName) {
+ super();
+
+ this.targetAttributeName = targetAttributeName;
+ }
+
+ private Collection<String> componentIds = new LinkedHashSet<String>();
+
+ public Collection<String> getComponentIds() {
+ return componentIds;
+ }
+
+ public VisitResult visit(VisitContext context, UIComponent target) {
+ Object attributeValue = target.getAttributes().get(targetAttributeName);
+ Set<String> attributeIds = AjaxRendererUtils.asSet(attributeValue);
+ if (attributeIds != null) {
+ componentIds.addAll(RendererUtils.getInstance().findComponentsFor(context.getFacesContext(),
target, attributeIds));
+ }
+
+ return VisitResult.COMPLETE;
+ }
+ }
+
+ private Collection<String> getComponentIds(String targetAttributeName) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ ComponentIdsCallback componentIdsCallback = new
ComponentIdsCallback(targetAttributeName);
+
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+
+ boolean visitResult = viewRoot.visitTree(
+ createVisitContext(facesContext),
+ componentIdsCallback);
+
+ if (!visitResult) {
+ //TODO
+ }
+
+ return componentIdsCallback.getComponentIds();
+ }
+
+ @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"));
+ } else if (PhaseId.RENDER_RESPONSE.equals(phaseId)) {
+ Collection<String> renderIds = wrapped.getRenderIds();
+ renderIds.clear();
+ renderIds.addAll(getComponentIds("render"));
+ }
+
+ wrapped.processPartial(phaseId);
+ }
+
+ @Override
+ public void setPartialRequest(boolean isPartialRequest) {
+ // TODO Auto-generated method stub
+
+ }
+}
Deleted:
root/framework/trunk/impl/src/main/java/org/richfaces/context/RequestContext.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/RequestContext.java 2009-07-30
16:13:54 UTC (rev 15069)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/RequestContext.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -1,60 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * 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.Map;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-
-/**
- * @author Nick Belaevski
- * @since 3.3.1
- */
-
-public final class RequestContext extends AbstractContext {
-
- private static final String REQUEST_ATTRIBUTE_NAME = RequestContext.class.getName();
-
- private RequestContext() {
- super();
- }
-
- public static RequestContext getInstance() {
- return getInstance(FacesContext.getCurrentInstance());
- }
-
- public static RequestContext getInstance(FacesContext context) {
- ExternalContext externalContext = context.getExternalContext();
- Map<String, Object> requestMap = externalContext.getRequestMap();
-
- RequestContext requestContext = (RequestContext)
requestMap.get(REQUEST_ATTRIBUTE_NAME);
- if (requestContext == null) {
- requestContext = new RequestContext();
-
- requestMap.put(REQUEST_ATTRIBUTE_NAME, requestContext);
- }
-
- return requestContext;
- }
-
-}
Added:
root/framework/trunk/impl/src/main/java/org/richfaces/context/SingletonsContext.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/richfaces/context/SingletonsContext.java
(rev 0)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/SingletonsContext.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -0,0 +1,85 @@
+/**
+ * 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.Map;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ * @since 4.0
+ */
+public class SingletonsContext {
+
+ public static abstract class ContextProvider {
+
+ protected final String singletonContextAttributeName;
+
+ protected ContextProvider(String attributeSuffixName) {
+ this.singletonContextAttributeName = SingletonsContext.class.getName() + ":"
+ attributeSuffixName;
+ }
+
+ protected AttributesContext createContext() {
+ return new AttributesContext();
+ }
+
+ protected abstract Map<? super String, Object> getContextMap(FacesContext
facesContext);
+
+ protected AttributesContext createAndStoreContext(FacesContext context) {
+ AttributesContext instance = createContext();
+ getContextMap(context).put(singletonContextAttributeName, instance);
+
+ return instance;
+ }
+
+ public AttributesContext get(FacesContext context) {
+ Map<? super String, Object> contextMap = getContextMap(context);
+
+ AttributesContext instance = (AttributesContext)
contextMap.get(singletonContextAttributeName);
+ if (instance == null) {
+ instance = createAndStoreContext(context);
+ }
+
+ return instance;
+ }
+ }
+
+ public static final ContextProvider APPLICATION = new
ContextProvider("Application") {
+
+ @Override
+ protected Map<String, Object> getContextMap(FacesContext facesContext) {
+ return facesContext.getExternalContext().getApplicationMap();
+ }
+
+ };
+
+ public static final ContextProvider FACES_CONTEXT = new
ContextProvider("FacesContext") {
+
+ @Override
+ protected Map<? super String, Object> getContextMap(FacesContext facesContext) {
+ return facesContext.getAttributes();
+ }
+
+ };
+
+}
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-07-30
16:13:54 UTC (rev 15069)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/resource/AbstractBaseResource.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -39,7 +39,7 @@
import org.ajax4jsf.resource.InternetResource;
import org.ajax4jsf.resource.ResourceContext;
-import org.richfaces.context.ApplicationContext;
+import org.richfaces.context.SingletonsContext;
import org.richfaces.util.RichfacesLogger;
import org.richfaces.util.Util;
import org.slf4j.Logger;
@@ -134,11 +134,11 @@
//TODO - originally lastModified was set during resource creation.
//as resources can be managed beans this approach does not seem good
if (lastModified == null) {
- lastModified = (Date) ApplicationContext.getInstance(context).
+ lastModified = (Date) SingletonsContext.APPLICATION.get(context).
getAttribute(ResourceHandlerImpl.HANDLER_START_TIME_ATTRIBUTE);
if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(MessageFormat.format("Using resource handler start time as last
modified date: {0,date}", lastModified));
+ LOGGER.debug(MessageFormat.format("Using resource handler start time as last
modified date: {0,date,dd MMM yyyy HH:mm:ss zzz}", lastModified));
}
}
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-07-30
16:13:54 UTC (rev 15069)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2009-07-30
22:39:12 UTC (rev 15070)
@@ -38,11 +38,13 @@
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.ajax4jsf.cache.Cache;
import org.ajax4jsf.cache.CacheManager;
-import org.richfaces.context.ApplicationContext;
+import org.richfaces.context.AttributesContext;
+import org.richfaces.context.SingletonsContext;
import org.richfaces.util.RichfacesLogger;
import org.richfaces.util.Util;
import org.richfaces.util.RequestStateManager.BooleanRequestStateVariable;
@@ -103,7 +105,7 @@
}
private void markStartTime(FacesContext facesContext) {
- ApplicationContext applicationContext = ApplicationContext.getInstance(facesContext);
+ AttributesContext applicationContext =
SingletonsContext.APPLICATION.get(facesContext);
applicationContext.setAttribute(HANDLER_START_TIME_ATTRIBUTE, new Date());
}
@@ -338,26 +340,30 @@
if (contentType != null) {
externalContext.setResponseContentType(contentType);
}
-
- //TODO 'HEAD' HTTP method resources - ?
- //TODO setup output buffer size according to configuration parameter
- InputStream is = resource.getInputStream();
- OutputStream os = externalContext.getResponseOutputStream();
+
+ //TODO - portlets
+ HttpServletRequest httpServletRequest = (HttpServletRequest)
externalContext.getRequest();
+ if (!"HEAD".equals(httpServletRequest.getMethod())) {
+ //TODO 'HEAD' HTTP method resources - ?
+ //TODO setup output buffer size according to configuration parameter
+ InputStream is = resource.getInputStream();
+ OutputStream os = externalContext.getResponseOutputStream();
- try {
- Util.copyStreamContent(is, os);
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(e.getMessage(), e);
+ try {
+ Util.copyStreamContent(is, os);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(e.getMessage(), e);
+ }
}
}
+ //TODO flush resource
+ //TODO dispose resource
}
- //TODO flush resource
- //TODO dispose resource
}
if (LOGGER.isDebugEnabled()) {
Added: 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
(rev 0)
+++
root/framework/trunk/impl/src/main/resources/META-INF/components.faces-config.xml 2009-07-30
22:39:12 UTC (rev 15070)
@@ -0,0 +1,10 @@
+<?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">
+
+ <factory>
+ <partial-view-context-factory>org.richfaces.context.PartialViewContextFactoryImpl</partial-view-context-factory>
+ </factory>
+
+</faces-config>
Modified: root/framework/trunk/impl/src/main/resources/META-INF/faces-config.xml
===================================================================
--- root/framework/trunk/impl/src/main/resources/META-INF/faces-config.xml 2009-07-30
16:13:54 UTC (rev 15069)
+++ root/framework/trunk/impl/src/main/resources/META-INF/faces-config.xml 2009-07-30
22:39:12 UTC (rev 15070)
@@ -44,7 +44,7 @@
<managed-bean-name>ajaxContext</managed-bean-name>
<managed-bean-class>org.ajax4jsf.context.AjaxContextImpl</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
- </managed-bean>
+ </managed-bean>
<!-- component>
<component-type>javax.faces.ViewRoot</component-type>
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js
===================================================================
---
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js 2009-07-30
16:13:54 UTC (rev 15069)
+++
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js 2009-07-30
22:39:12 UTC (rev 15070)
@@ -1,6 +1,6 @@
-(function(richFaces, jQuery) {
+(function(richfaces, jQuery) {
//form.js
- richFaces.submitForm = function(form, parameters, target) {
+ richfaces.submitForm = function(form, parameters, target) {
if (typeof form === "string") { form = jQuery(form) };
var initialTarget = form.attr("target");
var parameterInputs = new Array();
@@ -13,7 +13,7 @@
var input = jQuery("input[name='" + parameterName +
"']", form);
if (input.length == 0) {
- var newInput = jQuery("<input type='hidden' name='" +
parameterName + "' id='" + parameterName + "'
/>").val(parameterValue);
+ var newInput = jQuery("<input />").attr({type: 'hidden',
name: parameterName, value: parameterValue});
if (parameterName === 'javax.faces.portletbridge.STATE_ID' /* fix for
fileUpload in portlets */) {
input = newInput.prependTo(form);
} else {
@@ -37,9 +37,178 @@
//
//utils.js
+ richfaces.console = (function(jQuery) {
+ var getConsole = function() {
+ var console = jQuery('#richfaces\\.console');
+ if (console.length == 0) {
+ console = jQuery("<div
id='richfaces.console'><button>Clear</button></div>").appendTo("body");
+ }
+ console.find("button:first").click(function()
{jQuery(this).nextAll().remove();});
+ return console;
+ };
+
+ var LOG_LEVEL_COLORS = {'debug': 'darkblue', 'info':
'blue', 'warn': 'yellow', 'error': 'red'};
+
+ var formatMessage = function(level, message) {
+ return level + '[' + new Date().toLocaleTimeString() + ']: ' +
message;
+ };
+
+ var appendLogEntry = function(level, text) {
+ jQuery("<div style='color: " + LOG_LEVEL_COLORS[level] +
"'></div>").appendTo(getConsole()).text(text);
+ };
+
+ var useFirebugConsole = true;
+
+ var loggers = {};
+ for (var logLevel in LOG_LEVEL_COLORS) {
+ loggers[logLevel] = (function() {
+ var _logLevel = logLevel;
+
+ if (window.console && useFirebugConsole) {
+ return function(message) {
+ window.console[_logLevel](formatMessage(_logLevel, message));
+ };
+ } else {
+ return function() {
+ appendLogEntry(_logLevel, formatMessage(_logLevel, message))
+ };
+ }
+ }());
+ }
+ return loggers;
+ }(jQuery));
+
+ /**
+ * Evaluates chained properties for the "base" object.
+ * For example, window.document.location is equivalent to
+ * "propertyNamesString" = "document.location" and "base"
= window
+ * Evaluation is safe, so it stops on the first null or undefined object
+ *
+ * @param propertyNamesArray - array of strings that contains names of the properties to
evaluate
+ * @param base - base object to evaluate properties on
+ * @return returns result of evaluation or empty string
+ */
+ richfaces.getValue = function(propertyNamesArray, base) {
+ var result = base;
+ var c = 0;
+ do {
+ result = result[propertyNamesArray[c++]];
+ } while (result && c != propertyNamesArray.length);
+
+ return result;
+ };
+
+ var VARIABLE_NAME_PATTERN_STRING = "[_A-Z,a-z]\\w*";
+ var VARIABLES_CHAIN = new
RegExp("^\\s*"+VARIABLE_NAME_PATTERN_STRING+"(?:\\s*\\.\\s*"+VARIABLE_NAME_PATTERN_STRING+")*\\s*$");
+ var DOT_SEPARATOR = /\s*\.\s*/;
+
+ richfaces.evalMacro = function(macro, base) {
+ var value = "";
+ // variable evaluation
+ if (VARIABLES_CHAIN.test(macro)) {
+ // object's variable evaluation
+ var propertyNamesArray = jQuery.trim(macro).split(DOT_SEPARATOR);
+ value = richfaces.getValue(propertyNamesArray, base);
+ if (!value) {
+ value = richfaces.getValue(propertyNamesArray, window);
+ }
+ } else {
+ //js string evaluation
+ try {
+ if (base.eval) {
+ value = base.eval(macro);
+ } else with (base) {
+ value = eval(macro) ;
+ }
+ } catch (e) {
+ richfaces.console.warn("Exception: " + e.message + "\n[" + macro
+ "]");
+ }
+ }
+
+ if (typeof value == 'function') {
+ value = value(base);
+ }
+ //TODO 0 and false are also treated as null values
+ return value || "";
+ };
+
+ richfaces.interpolate = function (placeholders, context) {
+ var contextVarsArray = new Array();
+ for (var contextVar in context) {
+ if (/^\w+$/.test(contextVar)) {
+ //guarantees that no escaping for the below RegExp is necessary
+ contextVarsArray.push(contextVar);
+ }
+ }
+
+ var regexp = new RegExp("\\{(" + contextVarsArray.join("|") +
")\\}", "g");
+ return placeholders.replace(regexp, function(str, contextVar) {return
context[contextVar];});
+ };
+
richfaces.clonePosition = function(element, baseElement, positioning, offset) {
};
//
+
+ var PUSH_RESOURCE_URL =
"#{resource['org.richfaces.resource.PushResource']}";
+ var pushTracker = {};
+
+ richfaces.startPush = function(options) {
+ var pushId = options.pushId;
+ var interval = options.interval;
+ var ondataavailable = options.ondataavailable;
+
+ richfaces.stopPush(pushId);
+
+ pushTracker[pushId] = setTimeout(function() {
+ var ajaxOptions = {
+ type: "HEAD",
+ //TODO - encodeURIComponent; URL sessionId handling check
+ url: PUSH_RESOURCE_URL + "?id=" + pushId,
+ dataType: "text",
+ complete: function(xhr) {
+ var isPushActive = !!pushTracker[pushId];
+
+ delete pushTracker[pushId];
+
+ if (xhr.status == 200 && xhr.getResponseHeader("Ajax-Push-Status")
== "READY") {
+ try {
+ ondataavailable();
+ } catch (e) {
+ // TODO: handle exception
+ }
+ }
+
+ if (isPushActive) {
+ richfaces.startPush(options);
+ }
+ }
+ };
+
+ if (options.timeout) {
+ ajaxOptions.timeout = options.timeout;
+ }
+
+ jQuery.ajax(ajaxOptions);
+ }, interval);
+ };
+
+ richfaces.stopPush = function(id) {
+ if (pushTracker[id]){
+ window.clearTimeout(pushTracker[id]);
+ delete pushTracker[id];
+ }
+ };
+
+ richfaces.ajax = function(source, event, options) {
+ var sourceId = source;
+
+ options.execute = "@component";
+ options.render = "@component";
+ options.RICHFACES_AJAX = sourceId;
+
+ jsf.ajax.request(source, event, options);
+ };
+
}(window.RichFaces = {}, jQuery));