Author: alexsmirnov
Date: 2007-07-09 20:08:19 -0400 (Mon, 09 Jul 2007)
New Revision: 1555
Added:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java
trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugLifecycle.java
trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugLifecycleFactory.java
trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugOutputMaker.java
trunk/framework/impl/src/main/java/org/ajax4jsf/application/FacesErrorStateHolder.java
trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java
trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
trunk/framework/impl/src/main/java/org/ajax4jsf/context/
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
trunk/framework/impl/src/main/java/org/ajax4jsf/context/ComponentInvoker.java
trunk/framework/impl/src/main/java/org/ajax4jsf/context/InvokerCallback.java
trunk/framework/impl/src/main/java/org/ajax4jsf/context/JsfOneOneInvoker.java
trunk/ui/core/src/main/java/org/ajax4jsf/component/EventValueBinding.java
Removed:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugLifecycle.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugLifecycleFactory.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugOutputMaker.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/FacesErrorStateHolder.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxContextImpl.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxRegionBrige.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxStateManager.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxViewHandler.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxViewRoot.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/ComponentInvoker.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/EventValueBinding.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/InvokerCallback.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/JsfOneOneInvoker.java
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/InitPhaseListener.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseXMLFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoParser.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/tidy/TidyParser.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxRendererUtils.java
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxViewRootRenderer.java
trunk/framework/impl/src/main/resources/META-INF/faces-config.xml
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractThreadedAjax4JsfTestCase.java
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockViewRoot.java
trunk/samples/dragDropDemo/src/main/java/org/richfaces/Bean.java
trunk/samples/suggestionbox-sample/src/main/java/org/richfaces/AjaxListener.java
trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxRegion.java
trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxSupport.java
Log:
packages and classes refactor in the "impl" project
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxStateManager.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,102 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.application;
+
+import java.io.IOException;
+
+import javax.faces.application.StateManager;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.framework.renderer.AjaxPhaseListener;
+
+/**
+ * @author shura
+ *
+ */
+public class AjaxStateManager extends StateManager {
+
+ private StateManager parent;
+
+ /**
+ * @param parent
+ */
+ public AjaxStateManager(StateManager parent) {
+ super();
+ this.parent = parent;
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.application.StateManager#getComponentStateToSave(javax.faces.context.FacesContext)
+ */
+ protected Object getComponentStateToSave(FacesContext context) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.application.StateManager#getTreeStructureToSave(javax.faces.context.FacesContext)
+ */
+ protected Object getTreeStructureToSave(FacesContext context) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.application.StateManager#restoreComponentState(javax.faces.context.FacesContext,
javax.faces.component.UIViewRoot, java.lang.String)
+ */
+ protected void restoreComponentState(FacesContext context,
+ UIViewRoot viewRoot, String renderKitId) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.application.StateManager#restoreTreeStructure(javax.faces.context.FacesContext,
java.lang.String, java.lang.String)
+ */
+ protected UIViewRoot restoreTreeStructure(FacesContext context,
+ String viewId, String renderKitId) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.application.StateManager#restoreView(javax.faces.context.FacesContext,
java.lang.String, java.lang.String)
+ */
+ public UIViewRoot restoreView(FacesContext context, String viewId,
+ String renderKitId) {
+ return parent.restoreView(context, viewId, renderKitId);
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.application.StateManager#saveSerializedView(javax.faces.context.FacesContext)
+ */
+ public SerializedView saveSerializedView(FacesContext context) {
+ return parent.saveSerializedView(context);
+ }
+
+ /* (non-Javadoc)
+ * @see
javax.faces.application.StateManager#writeState(javax.faces.context.FacesContext,
javax.faces.application.StateManager.SerializedView)
+ */
+ public void writeState(FacesContext context, SerializedView state)
+ throws IOException {
+ parent.writeState(context, state);
+ context.getExternalContext().getRequestMap().put(AjaxPhaseListener.VIEW_STATE_SAVED_PARAM,
Boolean.TRUE);
+ }
+
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxViewHandler.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxViewHandler.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,279 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.application;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.faces.FacesException;
+import javax.faces.application.ViewHandler;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.servlet.http.HttpServletResponse;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.application.ViewHandlerWrapper;
+import org.ajax4jsf.component.AjaxViewRoot;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.context.ViewIdHolder;
+import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
+import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
+import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
+import org.ajax4jsf.resource.InternetResource;
+import org.ajax4jsf.resource.InternetResourceBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.5 $ $Date: 2007/02/08 15:02:04 $
+ *
+ */
+public class AjaxViewHandler extends ViewHandlerWrapper {
+
+ public static final String STATE_MARKER_KEY = "org.ajax4jsf.view.state";
+
+ public static final String SERIALIZED_STATE_KEY =
"org.ajax4jsf.view.serializedstate";
+
+ private static final Log _log = LogFactory.getLog(AjaxViewHandler.class);
+
+ private static final String REDIRECTED = "org.ajax4jsf.view.REDIRECTED";
+
+ /**
+ * @param parent
+ */
+ public AjaxViewHandler(ViewHandler parent) {
+ super(parent);
+ if (_log.isDebugEnabled()) {
+ _log.debug("Create instance of Ajax ViewHandler");
+ }
+ }
+
+ /*
+ * (non-Javadoc) For creating ViewRoot by Application Instead of new . Not
+ * nessesary for MyFaces ( simple copy from it ) or RI 1.2
+ *
+ * @see
javax.faces.application.ViewHandler#createView(javax.faces.context.FacesContext,
+ * java.lang.String)
+ */
+ public UIViewRoot createView(FacesContext facesContext, String viewId) {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
+ // Check for simple keep new ViewId in navigation cases.
+ ViewIdHolder viewIdHolder = ajaxContext.getViewIdHolder();
+ UIViewRoot riRoot;
+ if (null != viewIdHolder && viewIdHolder.skipNavigation(viewId)) {
+ viewIdHolder.setViewId(viewId);
+ riRoot = facesContext.getViewRoot();
+ } else {
+ UIViewRoot root = super.createView(facesContext, viewId);
+ // TODO -setup render-kit where instead of Listener ?
+ if (null == root || root instanceof AjaxViewRoot) {
+ riRoot = root;
+ } else {
+ // HACK - since only RI 1.1 use new for create ViewRoot instead
+ // of Application.createComponent,
+ // we can use it as flag for custom creation.
+ riRoot = (UIViewRoot)
facesContext.getApplication().createComponent(UIViewRoot.COMPONENT_TYPE);
+ // fill properties from default.
+ riRoot.setViewId(root.getViewId());
+ riRoot.setLocale(root.getLocale());
+ String renderKitId = root.getRenderKitId();
+ // Fix facelets bug - for debug requests renderKitId is null !
+ if (null == renderKitId) {
+ renderKitId = calculateRenderKitId(facesContext);
+ }
+ riRoot.setRenderKitId(renderKitId);
+ }
+ if (ajaxContext.isAjaxRequest(facesContext)) {
+ // Remove ajax status - for navigation states, full page will be
+ // send.
+ ajaxContext.setAjaxRequest(false);
+ }
+ }
+ return riRoot;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ViewHandlerWrapper#writeState(javax.faces.context.FacesContext)
+ */
+ public void writeState(FacesContext context) throws IOException {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ if (ajaxContext.isAjaxRequest(context)) {
+ // TODO - detect case of JSF 1.1 + JSP. for all other we need own
+ // state marker for
+ // self-rendered regions only.
+ // write marker html element - input field. Will be parsed in filter
+ // and
+ // replaced with real state.
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement(HTML.SPAN_ELEM, null);
+ writer.writeAttribute(HTML.id_ATTRIBUTE, STATE_MARKER_KEY, null);
+ writer.writeAttribute(HTML.NAME_ATTRIBUTE, STATE_MARKER_KEY, null);
+// writer.writeAttribute("style", "display:none;", null);
+ if (!ajaxContext.isSelfRender()) {
+ super.writeState(context);
+ }
+ writer.endElement(HTML.SPAN_ELEM);
+ } else {
+ super.writeState(context);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ViewHandlerWrapper#restoreView(javax.faces.context.FacesContext,
+ * java.lang.String)
+ */
+ public UIViewRoot restoreView(FacesContext context, String viewId) {
+ UIViewRoot viewRoot = super.restoreView(context, viewId);
+ ExternalContext externalContext = context.getExternalContext();
+ Map requestParameterMap = externalContext.getRequestParameterMap();
+ Map requestMap = externalContext.getRequestMap();
+ if (null == viewRoot) {
+ if (requestParameterMap
+ .containsKey(AjaxContainerRenderer.AJAX_PARAMETER_NAME)
+ && !requestMap.containsKey(REDIRECTED)) {
+ // New view created for AJAX request - indicate session
+ // expiration.
+ // We need send special response to client and suggest reload
+ // page.
+ String actionURL = getActionURL(context, viewId);
+ // To avoid double call to redirect, if we have more then one
+ // handler in chain.
+ requestMap.put(REDIRECTED, Boolean.TRUE);
+ if (_log.isDebugEnabled()) {
+ _log
+ .debug("Detect session expiration in AJAX request - view don't restored,
action URL is "
+ + actionURL);
+ }
+ try {
+ Object response = externalContext.getResponse();
+ if (response instanceof HttpServletResponse) {
+ HttpServletResponse httpResponse = (HttpServletResponse) response;
+ // TODO - get locale from request ?
+ httpResponse.setHeader("Ajax-Expired", Messages
+ .getMessage(Messages.AJAX_VIEW_EXPIRED));
+ }
+ actionURL = externalContext.encodeActionURL(actionURL);
+ externalContext.redirect(actionURL);
+ context.responseComplete();
+ } catch (IOException e) {
+ throw new FacesException(
+ "Error on redirect for reload expired page", e);
+ }
+ }
+ }
+ return viewRoot;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ViewHandlerWrapper#getResourceURL(javax.faces.context.FacesContext,
+ * java.lang.String)
+ */
+ public String getResourceURL(FacesContext context, String url) {
+ String resourceURL;
+ if (url.startsWith(InternetResource.RESOURCE_URI_PREFIX)) {
+ InternetResource resource = InternetResourceBuilder
+ .getInstance()
+ .createResource(
+ null,
+ url
+ .substring(InternetResource.RESOURCE_URI_PREFIX_LENGTH));
+ resourceURL = resource.getUri(context, null);
+ } else {
+ resourceURL = super.getResourceURL(context, url);
+ }
+ return resourceURL;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ViewHandlerWrapper#renderView(javax.faces.context.FacesContext,
+ * javax.faces.component.UIViewRoot)
+ */
+ public void renderView(FacesContext context, UIViewRoot root)
+ throws IOException, FacesException {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ // Broadcast Ajax events before rendering, to setup areas to update.
+ if (root instanceof AjaxViewRoot) {
+ AjaxViewRoot ajaxRoot = (AjaxViewRoot) root;
+ Map requestMap = context.getExternalContext().getRequestMap();
+ // broadcast ajax events before render response.
+ if (ajaxContext.isAjaxRequest(context)
+ && null == requestMap
+ .get(AjaxRendererUtils.AJAX_AREAS_RENDERED)) {
+ processAjaxEvents(context, ajaxRoot);
+ }
+ if (!context.getResponseComplete()) {
+ super.renderView(context, root);
+ if (ajaxContext.isAjaxRequest(context)
+ && null == requestMap
+ .get(AjaxRendererUtils.AJAX_AREAS_RENDERED)) {
+ // HACK for MyFaces ( <f:view> tag not call renderers )
+ if (_log.isDebugEnabled()) {
+ _log
+ .debug(Messages
+ .getMessage(Messages.AJAX_RESPONSE_NOT_RENDERED_INFO));
+ }
+ ajaxContext.setSelfRender(true);
+ //ServletResponse response = (ServletResponse) context
+ // .getExternalContext().getResponse();
+ Object response = (Object) context
+ .getExternalContext().getResponse();
+ try {
+ response.getClass().getDeclaredMethod("reset",
+ new Class[0]).invoke(response, new Object[0]);
+ //response.reset();
+ } catch (Exception e) {
+ // Do nothing - we will use directly and reset
+ // wrapper
+ }
+ ajaxContext.renderSubmittedAjaxRegion(context,true);
+ }
+ }
+ } else {
+ super.renderView(context, root);
+ }
+ ajaxContext.processHeadResources(context);
+ }
+
+ /**
+ * @param context
+ * @param ajaxRoot
+ */
+ private void processAjaxEvents(FacesContext context, AjaxViewRoot ajaxRoot) {
+ // First - process reRender from active components.
+ if (_log.isDebugEnabled()) {
+ _log.debug(Messages.getMessage(Messages.PROCESS_AJAX_EVENTS_INFO));
+ }
+ ajaxRoot.broadcastAjaxEvents(context);
+ }
+
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugLifecycle.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugLifecycle.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugLifecycle.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugLifecycle.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,170 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.application;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:12 $
+ *
+ */
+public class DebugLifecycle extends Lifecycle implements PhaseListener{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3247965217553145312L;
+
+ private Lifecycle _default;
+
+ private static Log _log = LogFactory.getLog(DebugLifecycle.class);
+
+ public static final String DEBUG_LYFECYCLE_ID = "DEBUG";
+
+ public static final String LIFECYCLE_ID_ATTR = "javax.faces.LIFECYCLE_ID";
+
+
+ public static final String PHASE_ID_PARAM = "org.ajax4jsf.CURRENT_PHASE";
+
+ private static final DebugOutputMaker debugOutput = new DebugOutputMaker();
+
+ /**
+ * @param default1
+ */
+ public DebugLifecycle(Lifecycle default1) {
+ super();
+ // TODO Auto-generated constructor stub
+ this._default = default1;
+ }
+
+ /**
+ *
+ */
+ public DebugLifecycle(LifecycleFactory defaultFactory) {
+ super();
+ _default = defaultFactory
+ .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+ _default.addPhaseListener(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.lifecycle.Lifecycle#addPhaseListener(javax.faces.event.PhaseListener)
+ */
+ public void addPhaseListener(PhaseListener arg0) {
+ _default.addPhaseListener(arg0);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.lifecycle.Lifecycle#execute(javax.faces.context.FacesContext)
+ */
+ public void execute(FacesContext context) throws FacesException {
+ try {
+ _default.execute(context);
+ } catch (Throwable e) {
+// DebugOutputMaker debugOutput = new DebugOutputMaker();
+ debugOutput.writeErrorMessage(context, e, "execute");
+ context.responseComplete();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.lifecycle.Lifecycle#getPhaseListeners()
+ */
+ public PhaseListener[] getPhaseListeners() {
+ // TODO Auto-generated method stub
+ return _default.getPhaseListeners();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.lifecycle.Lifecycle#removePhaseListener(javax.faces.event.PhaseListener)
+ */
+ public void removePhaseListener(PhaseListener arg0) {
+ _default.removePhaseListener(arg0);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.lifecycle.Lifecycle#render(javax.faces.context.FacesContext)
+ */
+ public void render(FacesContext context) throws FacesException {
+ try {
+ _default.render(context);
+ } catch (Throwable e) {
+// DebugOutputMaker debugOutput = new DebugOutputMaker();
+ debugOutput.writeErrorMessage(context, e, "render");
+ context.responseComplete();
+ }
+ }
+
+
+
+
+ /* (non-Javadoc)
+ * @see javax.faces.event.PhaseListener#afterPhase(javax.faces.event.PhaseEvent)
+ */
+ public void afterPhase(PhaseEvent event) {
+ if (_log.isDebugEnabled()) {
+ _log.debug("End phase "+event.getPhaseId().toString());
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
+ */
+ public void beforePhase(PhaseEvent event) {
+ if (_log.isDebugEnabled()) {
+ _log.debug("Start phase "+event.getPhaseId().toString());
+ }
+ event.getFacesContext().getExternalContext().getRequestMap().put(PHASE_ID_PARAM,event.getPhaseId());
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.event.PhaseListener#getPhaseId()
+ */
+ public PhaseId getPhaseId() {
+ // TODO Auto-generated method stub
+ return PhaseId.ANY_PHASE;
+ }
+}
Copied:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugLifecycleFactory.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugLifecycleFactory.java)
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugLifecycleFactory.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugLifecycleFactory.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,99 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.application;
+
+import java.util.Iterator;
+
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:12 $
+ *
+ */
+public class DebugLifecycleFactory extends LifecycleFactory {
+
+ private static final Log _log = LogFactory
+ .getLog(DebugLifecycleFactory.class);
+
+ private LifecycleFactory _defaultFactory;
+
+ private DebugLifecycle _debugLifecycle ;
+
+// private Map _lifecycles = new HashMap();
+
+ /**
+ * @return the debugLifecycle
+ */
+ private DebugLifecycle getDebugLifecycle() {
+ if (_debugLifecycle == null) {
+ _debugLifecycle = new DebugLifecycle(_defaultFactory);
+ }
+ return _debugLifecycle;
+ }
+
+ /**
+ * @param defaultFactory
+ */
+ public DebugLifecycleFactory(LifecycleFactory defaultFactory) {
+ super();
+ this._defaultFactory = defaultFactory;
+ if (_log.isDebugEnabled()) {
+ _log.debug("Created Lifecycle instance");
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.lifecycle.LifecycleFactory#addLifecycle(java.lang.String,
javax.faces.lifecycle.Lifecycle)
+ */
+ public void addLifecycle(String lifecycleId, Lifecycle lifecycle) {
+ this._defaultFactory.addLifecycle(lifecycleId, lifecycle);
+ if (_log.isDebugEnabled()) {
+ _log.debug("Added lifecycle with ID "+lifecycleId);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.lifecycle.LifecycleFactory#getLifecycle(java.lang.String)
+ */
+ public Lifecycle getLifecycle(String lifecycleId) {
+ Lifecycle life;
+ if(DebugLifecycle.DEBUG_LYFECYCLE_ID.equals(lifecycleId)) {
+ life = getDebugLifecycle();
+ } else {
+ life = this._defaultFactory.getLifecycle(lifecycleId);
+ }
+ return life;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.lifecycle.LifecycleFactory#getLifecycleIds()
+ */
+ public Iterator getLifecycleIds() {
+ return this._defaultFactory.getLifecycleIds();
+ }
+
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugOutputMaker.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugOutputMaker.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugOutputMaker.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/DebugOutputMaker.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,465 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.application;
+
+import java.beans.PropertyDescriptor;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+import javax.faces.el.ValueBinding;
+import javax.faces.event.PhaseId;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.resource.InternetResource;
+import org.ajax4jsf.resource.InternetResourceBuilder;
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.beanutils.PropertyUtils;
+
+
+/**
+ * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:11 $
+ *
+ */
+public class DebugOutputMaker {
+ private final static String LT = "<";
+ private final static String GT = ">";
+ // Attributes that should not be printed
+ static public final HashSet IGNORE_ATTRIBUTES;
+
+ static {
+ IGNORE_ATTRIBUTES = new HashSet();
+ IGNORE_ATTRIBUTES.add("attributes");
+ IGNORE_ATTRIBUTES.add("children");
+ IGNORE_ATTRIBUTES.add("childCount");
+ IGNORE_ATTRIBUTES.add("class");
+ IGNORE_ATTRIBUTES.add("facets");
+ IGNORE_ATTRIBUTES.add("facetsAndChildren");
+ IGNORE_ATTRIBUTES.add("parent");
+ IGNORE_ATTRIBUTES.add("actionListeners");
+ IGNORE_ATTRIBUTES.add("valueChangeListeners");
+ IGNORE_ATTRIBUTES.add("validators");
+ IGNORE_ATTRIBUTES.add("rowData");
+ IGNORE_ATTRIBUTES.add("javax.faces.webapp.COMPONENT_IDS");
+ IGNORE_ATTRIBUTES.add("javax.faces.webapp.FACET_NAMES");
+ IGNORE_ATTRIBUTES.add("javax.faces.webapp.CURRENT_VIEW_ROOT");
+ }
+
+ private static final String LOGFILE_PARAM = "org.ajax4jsf.LOGFILE";
+
+ /**
+ * Output error state for lifecycle.
+ *
+ * @param context
+ * @param phase
+ * TODO
+ * @param error
+ * @throws IOException
+ */
+ public void writeErrorMessage(FacesContext context, Throwable e, String phase)
+ throws FacesException {
+ if (null == context) {
+ throw new FacesException(Messages.getMessage(Messages.FACES_CONTEXT_NOT_CREATED), e);
+ }
+ ExternalContext externalContext = context
+ .getExternalContext();
+ if (null == externalContext) {
+ throw new FacesException(Messages.getMessage(Messages.FACES_CONTEXT_HAS_NOT_EXTERNAL),
e);
+ }
+ // debug for http servlet environment, portlets needs other debugger
+ HttpServletResponse response;
+ HttpServletRequest request;
+ try {
+ response = (HttpServletResponse) externalContext
+ .getResponse();
+ request = (HttpServletRequest) externalContext.getRequest();
+ response.setContentType("text/html;charset=UTF-8");
+ // set internal server error status
+ response.setStatus(500);
+ } catch (Exception er) {
+ throw new FacesException(Messages.getMessage(Messages.FACES_CONTEXT_HAS_NOT_RESPONSE),
e);
+ }
+ PrintWriter out;
+ try {
+ out = response.getWriter();
+ } catch (IOException e1) {
+ throw new FacesException(e1.getMessage(), e);
+ }
+ UIViewRoot viewRoot = context.getViewRoot();
+ String viewId;
+ if (null != viewRoot) {
+ viewId = viewRoot.getViewId();
+ } else {
+ viewId = request.getRequestURL().toString();
+ }
+ // output html prolog
+ out.println("<html><head><title>" +
+ Messages.getMessage(Messages.ERROR_ON_PAGE, viewId) +
+ "</title></head><body>");
+ // write script
+ writeScriptAndStyle(out);
+ // Header
+ PhaseId facesPhase = (PhaseId)
context.getExternalContext().getRequestMap().get(DebugLifecycle.PHASE_ID_PARAM);
+
+ String errorMessage =
+ (facesPhase == null)
+ ? Messages.getMessage(Messages.LIFECYCLE_ERROR, viewId, phase)
+ : Messages.getMessage(Messages.LIFECYCLE_ERROR_AT_PHASE, new Object[]{viewId, phase,
facesPhase.toString()});
+ out.println("<h1 >");
+ out.println(errorMessage);
+ out.println("</h1>");
+ response.setHeader("Ajax-Error-Message", errorMessage+",\n caused by
"+e.getClass().getName()+", with message: "+e.getMessage());
+ // Output exceptions
+ writeExceptionStack(e, out);
+ // Output view tree :
+ if (null != viewRoot) {
+ writeComponentsTree(context, out);
+ } else {
+ out.print("<h2 class=' a4j_debug'> " +
+ Messages.getMessage(Messages.COMPONENT_TREE_NOT_CREATED) +
+ " </h2>");
+ }
+ // Out scope variables
+ writeContextVariables(context, out);
+ // Write log output iframe :
+ writeLog(context, out);
+ // out html tail
+ out.println("</body></html>");
+ out.flush();
+ out.close();
+ }
+ /**
+ * @param e
+ * @param out
+ */
+ public void writeExceptionStack(Throwable e, PrintWriter out) {
+ out.println("<h2 class=\"a4j_debug\">Exceptions:
</h2>");
+ Throwable error = e;
+ int errorId = 0;
+ String caused = "exception ";
+ while (null != error) {
+ out.print("<h3 onclick=\"toggle('exception" + errorId +
"')\" class='exception a4j_debug'>");
+ writeToggleMark(out,"exception" + errorId);
+ out.print( caused + error.getClass().getName() + " : "
+ + error.getMessage() + "</h3>");
+ out.println("<div id='exception" + errorId
+ + "' style='display: none;'
class='exception'><p>Exception stack :</p><pre>");
+ StackTraceElement[] stackTrace = error.getStackTrace();
+ for (int i = 0; i < stackTrace.length; i++) {
+ out.print(" at " + stackTrace[i].getClassName());
+ out.print("." + stackTrace[i].getMethodName());
+ out.println(" in " + stackTrace[i].getFileName() + " line "
+ + stackTrace[i].getLineNumber());
+ }
+ // error.printStackTrace(out);
+ out.println("</pre></div>");
+ error = error.getCause();
+ caused = "caused by ";
+ errorId++;
+ }
+ }
+
+ /**
+ * @param context
+ * @param out
+ */
+ public void writeContextVariables(FacesContext context, PrintWriter out) {
+ out.print("<h2 class=\"a4j_debug\"
onclick=\"toggle('variables')\">");
+ writeToggleMark(out,"variables");
+ out.println("Faces variables: </h2><div id='variables'
style='display: none;' class='variables a4j_debug'>");
+ writeVariables(out,context);
+ out.println("</div>");
+ }
+
+ /**
+ * @param context
+ * @param out
+ */
+ public void writeComponentsTree(FacesContext context, PrintWriter out) {
+ out
+ .print("<h2 class=\"a4j_debug\"
onclick=\"toggle('tree')\">");
+ writeToggleMark(out,"tree");
+ out.println("Component tree: </h2><div id='tree'
style='display: none;' class='tree a4j_debug'><dl>");
+ writeComponent(context, out, context.getViewRoot(), null);
+ out.println("</dl></div>");
+ }
+
+ public void writeScriptAndStyle(PrintWriter out) {
+ writeScript(out);
+ writeStyleSheet(out);
+ }
+
+ /**
+ * @param context
+ * @param out
+ * @throws FacesException
+ */
+ public void writeLog(FacesContext context, PrintWriter out) throws FacesException {
+ String logname = context.getExternalContext().getInitParameter(LOGFILE_PARAM);
+ if (null != logname) {
+ InternetResource logResource =
InternetResourceBuilder.getInstance().createResource(this,logname);
+ out.print("<h2 onclick=\"toggle('log')\"
class=\"a4j_debug\">");
+ writeToggleMark(out, "log");
+ out
+ .println("Faces log: </h2><div id='log' style='display:
none;' class='log a4j_debug'>");
+ out.print("<iframe name='log' class='log'
src='"+logResource.getUri(context,null)+"'><a
href='src='"+logResource.getUri(context,null)+"'>Faces log file
</a> </iframe>");
+ out.println("</div>");
+ }
+ }
+
+ public void writeToggleMark(PrintWriter out,String id) {
+ out.print("<span style=\"display:none;\"
id=\""+id+"_expanded\" >- </span>");
+ out.print("<span style=\"display:inline;\"
id=\""+id+"_collapsed\" >+</span> ");
+ }
+
+
+ /**
+ * Out component with properties and it's facets and childrens
+ * @param context TODO
+ * @param out
+ * @param viewRoot
+ */
+ private void writeComponent(FacesContext context, PrintWriter out,
+ UIComponent component, String facetName) {
+ String clientId = "_tree:"+component.getClientId(context);
+ out.println("<dt onclick=\"toggle('"+clientId+"')\"
class='tree'>");
+ writeToggleMark(out,clientId);
+ // out component name
+ if (null != facetName) {
+ out.print("Facet:'" + facetName + "' ");
+ }
+ out.println("<code>" + component.getClass().getName() +
"</code> Id:["+component.getId()+"]");
+ out.println("</dt>");
+ out.println("<dd id='"+clientId+"'
style='display:none;' class='tree' ><ul
class='tree'>");
+ // out bean properties
+ try {
+ PropertyDescriptor propertyDescriptors[] =
PropertyUtils.getPropertyDescriptors(component);
+ for (int i = 0; i < propertyDescriptors.length; i++) {
+ if (PropertyUtils.isReadable(component,propertyDescriptors[i].getName())) {
+ String name = propertyDescriptors[i].getName();
+ ValueBinding vb = component.getValueBinding(name);
+ if (vb != null) {
+ writeAttribute(out, name, vb.getExpressionString());
+ } else {
+ if (!IGNORE_ATTRIBUTES.contains(name)) {
+ try {
+ String value = BeanUtils.getProperty(component,name);
+ writeAttribute(out, name, value);
+ } catch (Exception e) {
+ writeAttribute(out, name, null);
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ // Do nothing - we in error page.
+ }
+
+ // out bindings
+ // out attributes map
+ for (Iterator it = component.getAttributes().entrySet().iterator(); it
+ .hasNext();) {
+ Map.Entry entry = (Map.Entry) it.next();
+ writeAttribute(out, (String) entry.getKey(), entry.getValue());
+ }
+ // out listeners
+ out.println("</ul></dd>");
+ if (component.getFacetsAndChildren().hasNext()) {
+ out.println("<dd class='tree_childs'><dl
class='tree_childs'>");
+ // out childs of this component
+ // facets
+ for (Iterator facetEntry = component.getFacets().entrySet()
+ .iterator(); facetEntry.hasNext();) {
+ Map.Entry entry = (Map.Entry) facetEntry.next();
+ writeComponent(context, out,
+ (UIComponent) entry.getValue(), (String) entry.getKey());
+ }
+ // childs components
+ for (Iterator childIter = component.getChildren().iterator(); childIter
+ .hasNext();) {
+ UIComponent child = (UIComponent) childIter.next();
+ writeComponent(context, out, child, null);
+ }
+ out.println("</dl></dd>");
+ }
+
+ }
+
+ private void writeAttribute(PrintWriter out, String name, Object value) {
+ if (IGNORE_ATTRIBUTES.contains(name))
+ return;
+ if (name.startsWith("javax.faces.webapp.UIComponentTag.")) {
+ name = name
+ .substring("javax.faces.webapp.UIComponentTag.".length());
+ }
+ out.print("<li>");
+ out.print(name);
+ out.print("=\"");
+ if (value != null) {
+ if (value instanceof UIComponent) {
+ out.print("[id:");
+ out.print(((UIComponent) value).getId());
+ out.print(']');
+ } else if (value instanceof MethodBinding) {
+ out.print(((MethodBinding) value).getExpressionString());
+ } else if (value instanceof ValueBinding) {
+ out.print(((ValueBinding) value).getExpressionString());
+ } else {
+ out.print(value.toString());
+ }
+ } else {
+ out.print("NULL");
+ }
+ out.println("\"</li>");
+ }
+
+ private void writeVariables(PrintWriter out, FacesContext faces) {
+ ExternalContext ctx = faces.getExternalContext();
+ writeVariables(out, ctx.getRequestParameterMap(), "Request
Parameters");
+ writeVariables(out, ctx.getRequestMap(), "Request Attributes");
+ if (ctx.getSession(false) != null) {
+ writeVariables(out, ctx.getSessionMap(), "Session Attributes");
+ }
+ writeVariables(out, ctx.getApplicationMap(), "Application
Attributes");
+ }
+
+ private void writeVariables(PrintWriter out, Map vars, String caption) {
+ out.print("<table><caption>");
+ out.print(caption);
+ out.println("</caption><thead><tr><th
style=\"width: 10%; \">Name</th><th style=\"width: 90%;
\">Value</th></tr></thead><tbody>");
+ boolean written = false;
+ if (!vars.isEmpty()) {
+ SortedMap map = new TreeMap(vars);
+ Map.Entry entry = null;
+ String key = null;
+ for (Iterator itr = map.entrySet().iterator(); itr.hasNext(); ) {
+ entry = (Map.Entry) itr.next();
+ key = entry.getKey().toString();
+ if (key.indexOf('.') == -1) {
+ out.println("<tr><td>");
+ out.println(key.replaceAll("<",
LT).replaceAll(">", GT));
+ out.println("</td><td><span
class='value'>");
+ Object value = entry.getValue();
+ out.println(value.toString().replaceAll("<",
LT).replaceAll(">", GT));
+ out.println("</span>");
+ try {
+ PropertyDescriptor propertyDescriptors[] =
PropertyUtils.getPropertyDescriptors(value);
+ if (propertyDescriptors.length>0) {
+ out.print("<div class='properties'><ul
class=\'properties\'>");
+ for (int i = 0; i < propertyDescriptors.length; i++) {
+ String beanPropertyName = propertyDescriptors[i].getName();
+ if (PropertyUtils.isReadable(value,beanPropertyName
+ )) {
+ out.print("<li class=\'properties\'>");
+ out.print(beanPropertyName+" =
"+BeanUtils.getProperty(value,beanPropertyName));
+ out.print("</li>");
+
+ }
+ }
+ out.print("</ul></div>");
+ }
+ } catch (Exception e) {
+ // TODO: log exception
+ }
+
+ out.println("</td></tr>");
+ written = true;
+ }
+ }
+ }
+ if (!written) {
+ out.println("<tr><td
colspan=\"2\"><em>None</em></td></tr>");
+ }
+ out.println("</tbody></table>");
+ }
+ /**
+ * @param out
+ */
+ private void writeScript(PrintWriter out) {
+ out
+ .println("<script type='text/javascript'
language='javascript'>\n"
+ + "function toggle(id) {\n"
+ + "var style = document.getElementById(id).style;\n"
+ + "if ('block' == style.display) {\n"
+ + "style.display = 'none';\n"
+ + "document.getElementById(id+'_collapsed').style.display =
'inline';\n"
+ + "document.getElementById(id+'_expanded').style.display =
'none';\n"
+ + "} else {\n"
+ + "style.display = 'block';\n"
+ + "document.getElementById(id+'_collapsed').style.display =
'none';\n"
+ + "document.getElementById(id+'_expanded').style.display =
'inline';\n"
+ + "}\n" + "}\n\n" +
+
+ "</script>");
+ }
+
+ /**
+ * @param out
+ */
+ private void writeStyleSheet(PrintWriter out) {
+ out
+ .println("<style type=\'text/css\' >\n" +
+ "div.a4j_debug, .a4j_debug span, .a4j_debug td, .a4j_debug th, .a4j_debug
caption { font-family: Verdana, Arial, Sans-Serif; }\n" +
+ ".a4j_debug li{\n" +
+ " list-style-position : inside;\n" +
+ "}\n" +
+ "\n" +
+ ".a4j_debug li, .a4j_debug pre { padding: 0; margin: 0; font-size :
12px;}\n" +
+ ".a4j_debug ul { padding: 0 0 10 0; margin: 0; font-size : 12px;}\n" +
+ ".a4j_debug h1 { color: #fff; background-color : #a00; font-size : 17px;
padding : 7px 10px 10px 10px}\n" +
+ "h2.a4j_debug , h2.a4j_debug span { color: #a00; font-size : 17px; padding :
0px 0px 0px 10px;}\n" +
+ "h2.a4j_debug a { text-decoration: none; color: #a00; }\n" +
+ ".exception { color: #000; font-size : 14px; padding : 0px 0px 0px
10px;}\n" +
+ ".grayBox { padding: 8px; margin: 10px 0; border: 1px solid #CCC;
background-color: #f9f9f9; font-size : 12px; }\n" +
+ "#error { color: #900; font-weight: bold; font-size: medium; }\n" +
+ "#trace, #tree, #vars { display: none; }\n" +
+ ".a4j_debug code { font-size: medium; font-size : 14px;}\n" +
+ "#tree dl { color: #666; }\n" +
+ "#tree dd { font-size : 12px;}\n" +
+ "#tree dt { border: 1px solid #DDD; padding: 2px 4px 4px 4px; border-left: 2px
solid #a00; font-family: \"Courier New\", Courier, mono; font-size: small;
font-size : 12px; margin-top: 2px; margin-bottom: 2px;}\n" +
+ ".uicText { color: #999; }\n" +
+ ".a4j_debug table { border: 1px solid #CCC; border-collapse: collapse;
border-spacing: 0px; width: 100%; text-align: left; }\n" +
+ ".a4j_debug td { border: 1px solid #CCC; font-size : 12px; vertical-align :
top}\n" +
+ ".a4j_debug thead tr th { padding: 2px; color: #030; background-color:
#F9F9F9; font-size : 12px;}\n" +
+ ".a4j_debug tbody tr td { padding: 10px 6px; }\n" +
+ ".a4j_debug table caption { text-align: left; padding: 20 0 5 0; font-size :
12px; font-weight : bold;}\n" +
+ ".value {font-size : 12px; font-weight : bold;}\n" +
+ "div.log { width: 100%; height: 400px;}\n" +
+ "iframe.log { width: 99%; height: 99%; border: 1px solid #CCC;}\n" +
+ "</style>");
+ }
+
+}
Copied:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/FacesErrorStateHolder.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/FacesErrorStateHolder.java)
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/FacesErrorStateHolder.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/FacesErrorStateHolder.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,44 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.application;
+
+import javax.faces.component.UIViewRoot;
+
+/**
+ * Hold detailed faces state for Error output.
+ * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:11 $
+ *
+ */
+public interface FacesErrorStateHolder {
+
+ /**
+ * @return detailed message about faces state on error in Html format
+ */
+ public String getFacesErrorStateMessage();
+
+ /**
+ * @return faces view tree at error point.
+ */
+ public UIViewRoot getFacesView();
+
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxRegionBrige.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,361 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.component;
+
+import javax.faces.application.Application;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+import javax.faces.el.ValueBinding;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.component.AjaxContainerBase;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.event.AjaxEvent;
+import org.ajax4jsf.event.AjaxListener;
+import org.ajax4jsf.event.AjaxRenderEvent;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * @author shura
+ *
+ * Brige design pattern for any UIComponent append support ajax partial rendering. For
AJAX request, apply
+ * ActionListeniers, construct list of components for render - by direct setting
+ * from Listenier or Components bean methods.
+ * For use in concrete component, in constructor must be instantiated to class field as
:
+ * private AjaxRegionBrige brige;
+ * ....
+ * Constructor(){
+ * brige = new AjaxRegionBrige(this);
+ * }.
+ * And delegate all brige public methods.
+ * @See <code>AJAXConatiner</code> interface , or from configuration - by
+ * <ajax:forupdate>jsp tag's of this or nested components, or from all
+ * <code>UIForm</code> components instances with
<code>isSubmitted</code>
+ * set to <code>true</code>
+ *
+ */
+public class AjaxRegionBrige implements AjaxContainerBase, StateHolder{
+
+
+ // Private Fields
+ private static final Log log = LogFactory.getLog(AjaxRegionBrige.class);
+
+ /**
+ * Listener for call on Ajax Requests
+ */
+ private MethodBinding ajaxListener = null;
+
+ /**
+ * Flag for immediate call listeners
+ */
+ private boolean immediate = false;
+ private boolean immediateSet = false;
+
+ private boolean selfRendered = false;
+ private boolean selfRenderedSet = false;
+
+
+
+ private boolean transientFlag = false;
+
+ private UIComponent component ;
+
+ private boolean submitted = false;
+
+
+ // Interface implementation
+
+ /**
+ * @param component
+ */
+ public AjaxRegionBrige(UIComponent component) {
+ this.component = component;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.components.custom.ajax.AjaxContainer#getAjaxListener()
+ */
+ public MethodBinding getAjaxListener() {
+ return this.ajaxListener;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
ogr.apache.myfaces.custom.ajax.AjaxContainer#setAjaxListener(javax.faces.el.MethodBinding)
+ */
+ public void setAjaxListener(MethodBinding ajaxListener) {
+ //
+ if (log.isDebugEnabled())
+ {
+ log.debug(Messages.getMessage(Messages.SET_AJAX_LISTENER,
ajaxListener.getExpressionString()));
+ }
+ this.ajaxListener = ajaxListener;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see ogr.apache.myfaces.custom.ajax.AjaxContainer#isImmediate()
+ */
+ public boolean isImmediate() {
+ if (this.immediateSet) {
+ return (this.immediate);
+ }
+ ValueBinding vb = component.getValueBinding("immediate");
+ if (vb != null) {
+ return
(Boolean.TRUE.equals(vb.getValue(FacesContext.getCurrentInstance())));
+ } else {
+ return (this.immediate);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see ogr.apache.myfaces.custom.ajax.AjaxContainer#setImmediate(boolean)
+ */
+ public void setImmediate(boolean immediate) {
+ if (immediate != this.immediate) {
+ this.immediate = immediate;
+ }
+ this.immediateSet = true;
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.framework.ajax.AjaxContainer#isSelfRendered()
+ */
+ public boolean isSelfRendered() {
+ if (this.selfRenderedSet) {
+ return (this.selfRendered);
+ }
+ ValueBinding vb = component.getValueBinding("selfRendered");
+ if (vb != null) {
+ return
(Boolean.TRUE.equals(vb.getValue(FacesContext.getCurrentInstance())));
+ } else {
+ return (this.selfRendered);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.framework.ajax.AjaxContainer#setSelfRendered(boolean)
+ */
+ public void setSelfRendered(boolean selfRendered) {
+ this.selfRendered = selfRendered;
+ this.selfRenderedSet = true;
+ }
+
+ /**
+ * @return Returns the submitted.
+ */
+ public boolean isSubmitted()
+ {
+ // TODO - more correct check for submitted state
+ return this.submitted;
+ }
+
+ /**
+ * @param submitted The submitted to set.
+ */
+ public void setSubmitted(boolean submitted)
+ {
+ // Important - decoder must set submitted AFTER setAjaxRequest !!!
+ if (log.isDebugEnabled() && submitted && (!isSubmitted())) {
+ log.debug(Messages.getMessage(Messages.SUBMITTED_AJAX_REQUEST));
+ }
+ this.submitted = submitted;
+ }
+
+ /**
+ * <p>
+ * In addition to to the default {@link UIComponent#broadcast}processing,
+ * pass the {@link AjaxEvent}being broadcast to the method referenced by
+ * <code>AjaxListener</code> (if any), and to the default
+ * {@link AjaxListener}registered on the {@link Application}.
+ * </p>
+ *
+ * @param event
+ * {@link FacesEvent}to be broadcast
+ *
+ * @exception AbortProcessingException
+ * Signal the JavaServer Faces implementation that no further
+ * processing on the current event should be performed
+ * @exception IllegalArgumentException
+ * if the implementation class of this {@link FacesEvent}is
+ * not supported by this component
+ * @exception NullPointerException
+ * if <code>event</code> is
<code>null</code>
+ */
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+
+ // Perform standard superclass processing
+// component.broadcast(event);
+
+ if (event instanceof AjaxEvent) {
+ if (log.isDebugEnabled())
+ {
+ log.debug(Messages.getMessage(Messages.SEND_EVENT_TO_AJAX_LISTENER,
component.getId()));
+ }
+
+ // Notify the specified action listener method (if any)
+ MethodBinding mb = getAjaxListener();
+ if (mb != null) {
+ FacesContext context = FacesContext.getCurrentInstance();
+ mb.invoke(context, new Object[] { event });
+ }
+ // TODO - perform special rendering, withowt RENDER_VIEW phase.
+ if(isSelfRendered()) {
+ // queue new event to end of queue to perform child elements
+ // events.
+ if (log.isDebugEnabled())
+ {
+ log.debug("Queue AjaxRenderEvent for self-render of AjaxContainer
with Id "
+ + component.getId());
+ }
+ FacesEvent renderEvent = new AjaxRenderEvent(component);
+ renderEvent.setPhaseId(event.getPhaseId());
+ component.queueEvent(renderEvent);
+ }
+ }
+ if (event instanceof AjaxRenderEvent) {
+ FacesContext context = FacesContext.getCurrentInstance();
+ AjaxContext.getCurrentInstance(context).renderAjaxRegion(context,
component, false);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext,
+ * java.lang.Object)
+ */
+ public void restoreState(FacesContext context, Object state) {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.RESTORE_AJAX_COMPONENT_STATE,
component.getId()));
+ }
+ Object values[] = (Object[]) state;
+// super.restoreState(context, values[0]);
+ this.immediate = ((Boolean) values[0]).booleanValue();
+ this.immediateSet = ((Boolean) values[1]).booleanValue();
+ this.ajaxListener = (MethodBinding) UIComponentBase.restoreAttachedState(context,
values[2]);
+ this.selfRendered = ((Boolean) values[3]).booleanValue();
+ this.selfRenderedSet = ((Boolean) values[4]).booleanValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
+ */
+ public Object saveState(FacesContext context) {
+ //
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.SAVE_AJAX_COMPONENT_STATE,
component.getId()));
+ }
+ Object[] values = new Object[5];
+// values[0] = super.saveState(context);
+ values[0] = Boolean.valueOf(immediate);
+ values[1] = Boolean.valueOf(immediateSet);
+ values[2] = UIComponentBase.saveAttachedState(context, ajaxListener);
+ values[3] = Boolean.valueOf(selfRendered);
+ values[4] = Boolean.valueOf(selfRenderedSet);
+ return values;
+ }
+
+/* public void processDecodes(javax.faces.context.FacesContext context)
+ {
+ if (context == null) throw new NullPointerException("context");
+ // due SUN ri design, clear current sattus.
+ if(! component.isRendered()) return;
+ if(log.isDebugEnabled()){
+ log.debug("Process decodes of AjaxContainer with Id
"+component.getId());
+ }
+ component.decode(context);
+ // If it is AJAX request for different area - skip decoding childs.
+ if (isAjaxRequest()&& !isSubmitted()){
+ if(log.isDebugEnabled()){
+ log.debug("Skip Decoders for childrens of AjaxContainer with Id
"+component.getId());
+ }
+ return;
+ }
+ for (Iterator it = component.getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+ childOrFacet.processDecodes(context);
+ }
+ }
+
+ public void processValidators(javax.faces.context.FacesContext context)
+ {
+ if (context == null) throw new NullPointerException("context");
+ if(! component.isRendered()) return;
+ if (isAjaxRequest()&& !isSubmitted()){
+ if(log.isDebugEnabled()){
+ log.debug("Skip Validators for childrens of AjaxContainer with Id
"+component.getId());
+ }
+ return;
+ }
+
+ for (Iterator it = component.getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+ childOrFacet.processValidators(context);
+ }
+ }
+
+ public void processUpdates(javax.faces.context.FacesContext context)
+ {
+ if (context == null) throw new NullPointerException("context");
+ if(! component.isRendered()) return;
+ if (isAjaxRequest()&& !isSubmitted()){
+ if(log.isDebugEnabled()){
+ log.debug("Skip updates for childrens of AjaxContainer with Id
"+component.getId());
+ }
+ return;
+ }
+ for (Iterator it = component.getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent childOrFacet = (UIComponent)it.next();
+ childOrFacet.processUpdates(context);
+ }
+ }
+*/
+ public boolean isTransient() {
+ return transientFlag;
+ }
+
+ public void setTransient(boolean transientFlag) {
+ this.transientFlag = transientFlag;
+ }
+
+ }
+
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java (from
rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxViewRoot.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,568 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.component;
+
+import java.io.IOException;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.application.AjaxSingleException;
+import org.ajax4jsf.component.AjaxContainer;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.context.AjaxContextImpl;
+import org.ajax4jsf.context.InvokerCallback;
+import org.ajax4jsf.context.ViewIdHolder;
+import org.ajax4jsf.event.AjaxListener;
+import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
+import org.apache.commons.collections.Buffer;
+import org.apache.commons.collections.BufferUnderflowException;
+import org.apache.commons.collections.UnboundedFifoBuffer;
+
+/**
+ * Custom ViewRoot for support render parts of tree for Ajax requests. Main
+ * difference from default ViewRoot - store events queue and unique id counter
+ * in request-scope variables. In common realisation, store request-scope
+ * variables in component produce errors in case of concurrent requests to same
+ * view.
+ *
+ * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.4 $ $Date: 2007/02/28 17:01:01 $
+ *
+ */
+public class AjaxViewRoot extends UIViewRoot implements AjaxContainer {
+
+ public static final String ROOT_ID = "_viewRoot";
+
+ private AjaxRegionBrige _brige;
+
+ /**
+ *
+ */
+ public AjaxViewRoot() {
+ super();
+ super.setId(ROOT_ID);
+ _brige = new AjaxRegionBrige(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIComponentBase#getId()
+ */
+ // public String getId() {
+ // return ROOT_ID;
+ // }
+ public String getRendererType() {
+ return (COMPONENT_FAMILY);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#broadcast(javax.faces.event.FacesEvent)
+ */
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ super.broadcast(event);
+ getBrige().broadcast(event);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#getAjaxListener()
+ */
+ public MethodBinding getAjaxListener() {
+ return getBrige().getAjaxListener();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#isImmediate()
+ */
+ public boolean isImmediate() {
+ return getBrige().isImmediate();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#isSubmitted()
+ */
+ public boolean isSubmitted() {
+ return getBrige().isSubmitted();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.UIComponent#queueEvent(javax.faces.event.FacesEvent)
+ */
+ public void queueEvent(FacesEvent event) {
+ if (event == null)
+ throw new NullPointerException(Messages
+ .getMessage(Messages.NULL_EVENT_SUBMITTED_ERROR));
+ if (event.getPhaseId().compareTo(PhaseId.RENDER_RESPONSE) == 0) {
+ // HACK - Special case - Ajax Events to RenderResponse phase
+ // queue.
+ // in future, with JSF 1.2 it must be done by invokeOnComponent
+ // method.
+ // In 1.1 , events to RENDER_RESPONSE phase not used.
+ getAjaxEventsQueue(getFacesContext()).add(event);
+ } else {
+ getEventsQueue(getFacesContext(), event.getPhaseId()).add(event);
+ }
+ }
+
+ /**
+ * Broadcast events for specified Phase
+ *
+ * @param context
+ * @param phaseId -
+ * phase, for wich events must be processed.
+ */
+ void broadcastEvents(FacesContext context, PhaseId phaseId) {
+ Buffer[] events = getEvents(context);
+ Buffer anyPhaseEvents = events[PhaseId.ANY_PHASE.getOrdinal()];
+ Buffer phaseEvents = events[phaseId.getOrdinal()];
+ if (phaseEvents.isEmpty() && anyPhaseEvents.isEmpty())
+ return;
+ // FacesEvent event = null;
+ boolean haveAnyPhaseEvents = !anyPhaseEvents.isEmpty();
+ boolean havePhaseEvents = !phaseEvents.isEmpty();
+ do {
+ // ANY_PHASE first
+ processEvents(anyPhaseEvents, haveAnyPhaseEvents);
+
+ processEvents(phaseEvents, havePhaseEvents);
+ // Events can queued in other events processing
+ haveAnyPhaseEvents = !anyPhaseEvents.isEmpty();
+ havePhaseEvents = !phaseEvents.isEmpty();
+ } while (haveAnyPhaseEvents || havePhaseEvents);
+ if (context.getRenderResponse() || context.getResponseComplete()) {
+ clearEvents(context);
+ }
+
+ }
+
+ /**
+ * @param phaseEventsQueue
+ * @param havePhaseEvents
+ */
+ public void processEvents(Buffer phaseEventsQueue, boolean havePhaseEvents) {
+ FacesEvent event;
+ while (havePhaseEvents) {
+ try {
+ event = (FacesEvent) phaseEventsQueue.remove();
+ UIComponent source = event.getComponent();
+ try {
+ source.broadcast(event);
+ } catch (AbortProcessingException e) {
+ // abort event processing
+ // Page 3-30 of JSF 1.1 spec: "Throw an
+ // AbortProcessingException, to tell the JSF
+ // implementation
+ // that no further broadcast of this event, or any
+ // further
+ // events, should take place."
+ // clearEvents();
+ // return;
+ }
+ } catch (BufferUnderflowException e) {
+ havePhaseEvents = false;
+ }
+ }
+ }
+
+ public void broadcastAjaxEvents(FacesContext context) {
+ Buffer queue = getAjaxEventsQueue(context);
+ processEvents(queue, !queue.isEmpty());
+ }
+
+ private Buffer[] events;
+
+ private Buffer ajaxEvents = new UnboundedFifoBuffer();
+
+ /**
+ * Use FIFO buffers for hold Faces Events. Hold this buffers in Request
+ * scope parameters for support any concurrent requests for same
+ * component tree ( since RI hold component tree in session ).
+ *
+ * @param context
+ * @param phase
+ * @return
+ */
+ protected Buffer getEventsQueue(FacesContext context, PhaseId phase) {
+ return getEvents(context)[phase.getOrdinal()];
+ }
+
+ /**
+ * @return
+ */
+ protected Buffer[] getEvents(FacesContext context) {
+ if (events == null) {
+ clearEvents(context);
+ }
+ return events;
+ }
+
+ /**
+ * Special Fifo Buffer for ajax events to Render Responce phase.
+ *
+ * @param context
+ * @return
+ */
+ protected Buffer getAjaxEventsQueue(FacesContext context) {
+
+ return ajaxEvents;
+ }
+
+ public void clearEvents(FacesContext context) {
+ int len;
+ events = new Buffer[len = PhaseId.VALUES.size()];
+ for (int i = 0; i < len; i++) {
+ events[i] = new UnboundedFifoBuffer();
+ }
+ }
+
+ private InvokerCallback _decodeInvoker = new InvokerCallback() {
+
+ public void invoke(FacesContext context, UIComponent component) {
+ component.processDecodes(context);
+ }
+
+ public void invokeRoot(FacesContext context) {
+ AjaxViewRoot.super.processDecodes(context);
+ }
+
+ };
+
+ private UIComponent singleComponent = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#processDecodes(javax.faces.context.FacesContext)
+ */
+ public void processDecodes(FacesContext context) {
+ if (context == null)
+ throw new NullPointerException("context");
+ singleComponent = null;
+ AjaxContextImpl.invokeOnRegionOrRoot(this, context, _decodeInvoker);
+ try {
+ broadcastEvents(context, PhaseId.APPLY_REQUEST_VALUES);
+ } catch (AjaxSingleException e) {
+ singleComponent = e.getComponent();
+ }
+ }
+
+ private InvokerCallback _updatesInvoker = new InvokerCallback() {
+
+ public void invoke(FacesContext context, UIComponent component) {
+ component.processUpdates(context);
+ }
+
+ public void invokeRoot(FacesContext context) {
+ AjaxViewRoot.super.processUpdates(context);
+ }
+
+ };
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#processUpdates(javax.faces.context.FacesContext)
+ */
+ public void processUpdates(FacesContext context) {
+ if (context == null)
+ throw new NullPointerException("context");
+ if (null == singleComponent) {
+ AjaxContextImpl.invokeOnRegionOrRoot(this, context, _updatesInvoker);
+ } else {
+ singleComponent.processUpdates(context);
+ }
+ broadcastEvents(context, PhaseId.UPDATE_MODEL_VALUES);
+ }
+
+ private InvokerCallback _validatorsInvoker = new InvokerCallback() {
+
+ public void invoke(FacesContext context, UIComponent component) {
+ component.processValidators(context);
+ }
+
+ public void invokeRoot(FacesContext context) {
+ AjaxViewRoot.super.processValidators(context);
+ }
+
+ };
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#processValidators(javax.faces.context.FacesContext)
+ */
+ public void processValidators(FacesContext context) {
+ if (context == null)
+ throw new NullPointerException("context");
+ if (null == singleComponent) {
+ AjaxContextImpl.invokeOnRegionOrRoot(this, context, _validatorsInvoker);
+ } else {
+ singleComponent.processValidators(context);
+ }
+ broadcastEvents(context, PhaseId.PROCESS_VALIDATIONS);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.UIViewRoot#processApplication(javax.faces.context.FacesContext)
+ */
+ public void processApplication(FacesContext context) {
+ if (context == null)
+ throw new NullPointerException("context");
+ // UIComponent component = getSubmittedRegion(context);
+ // TODO - process JSF 1.2 listeners
+ broadcastEvents(context, PhaseId.INVOKE_APPLICATION);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.UIViewRoot#encodeBegin(javax.faces.context.FacesContext)
+ */
+ // public void encodeBegin(FacesContext context) throws IOException {
+ // UIComponent submittedComponent = getSubmittedRegion(context);
+ // if(null == submittedComponent){
+ // super.encodeBegin(context);
+ // } else {
+ // submittedComponent.encodeBegin(context);
+ // }
+ // }
+ private InvokerCallback _ajaxInvoker = new InvokerCallback() {
+
+ public void invoke(FacesContext context, UIComponent component) {
+ try {
+ if (component instanceof AjaxContainer) {
+ AjaxContainer ajax = (AjaxContainer) component;
+ ajax.encodeAjax(context);
+ } else {
+ // Container not found, use Root for encode.
+ encodeAjax(context);
+ }
+ } catch (IOException e) {
+ throw new FacesException(e);
+ }
+ }
+
+ public void invokeRoot(FacesContext context) {
+ try {
+ encodeAjax(context);
+ } catch (IOException e) {
+ throw new FacesException(e);
+ }
+ }
+
+ };
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.UIComponentBase#encodeChildren(javax.faces.context.FacesContext)
+ */
+ public void encodeChildren(FacesContext context) throws IOException {
+ if (!isHavePage()
+ && AjaxContext.getCurrentInstance(context).isAjaxRequest(
+ context)) {
+ AjaxContextImpl.invokeOnRegionOrRoot(this, context, _ajaxInvoker);
+ } else {
+ super.encodeChildren(context);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.UIComponentBase#encodeEnd(javax.faces.context.FacesContext)
+ */
+ // public void encodeEnd(FacesContext context) throws IOException {
+ // UIComponent submittedComponent = getSubmittedRegion(context);
+ // if (null == submittedComponent) {
+ // super.encodeEnd(context);
+ // } else {
+ // submittedComponent.encodeEnd(context);
+ // }
+ // }
+ public void restoreState(FacesContext context, Object state) {
+ Object[] mystate = (Object[]) state;
+ super.restoreState(context, mystate[0]);
+ getBrige().restoreState(context, mystate[1]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#saveState(javax.faces.context.FacesContext)
+ */
+ public Object saveState(FacesContext context) {
+ Object[] state = new Object[2];
+ state[0] = super.saveState(context);
+ state[1] = getBrige().saveState(context);
+ return state;
+ }
+
+ public String getViewId() {
+ ViewIdHolder viewIdHolder = AjaxContext.getCurrentInstance()
+ .getViewIdHolder();
+ String viewId;
+ if (null != viewIdHolder) {
+ viewId = viewIdHolder.getViewId();
+ } else {
+ viewId = super.getViewId();
+ }
+ return viewId;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#setAjaxListener(javax.faces.el.MethodBinding)
+ */
+ public void setAjaxListener(MethodBinding ajaxListener) {
+ getBrige().setAjaxListener(ajaxListener);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#setImmediate(boolean)
+ */
+ public void setImmediate(boolean immediate) {
+ getBrige().setImmediate(immediate);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#setSubmitted(boolean)
+ */
+ public void setSubmitted(boolean submitted) {
+ getBrige().setSubmitted(submitted);
+ }
+
+ public void addAjaxListener(AjaxListener listener) {
+ addFacesListener(listener);
+ }
+
+ public AjaxListener[] getAjaxListeners() {
+ return (AjaxListener[]) getFacesListeners(AjaxListener.class);
+ }
+
+ public void removeAjaxListener(AjaxListener listener) {
+ removeFacesListener(listener);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#isSelfRendered()
+ */
+ public boolean isSelfRendered() {
+ return false;// _brige.isSelfRendered();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#setSelfRendered(boolean)
+ */
+ public void setSelfRendered(boolean selfRendered) {
+ // _brige.setSelfRendered(selfRendered);
+ }
+
+ /**
+ * Check for AjaxContainer component in childreh. This is workaround for
+ * MyFaces JSP tag implementation, not called any encode... methods in
+ * <f:view> tag. If only one AjaxContainer present as children for
+ * viewRoot, decoding methods delegated to them.
+ *
+ * @return Returns the havePage.
+ */
+ public boolean isHavePage() {
+ return (getChildCount() == 1 && getChildren().get(0) instanceof AjaxContainer);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIComponentBase#getRendersChildren()
+ */
+ public boolean getRendersChildren() {
+ FacesContext context = FacesContext.getCurrentInstance();
+ // For non Ajax request, view root not render children
+ if (!AjaxContext.getCurrentInstance(context).isAjaxRequest(context)) {
+ return false;
+ }
+ // Also, if have page component as clild - delegate rendering of
+ // children to it.
+ if (isHavePage()) {
+ return false;
+ }
+ // Ajax Request. Control all output.
+ return true;
+ }
+
+ public boolean isRenderRegionOnly() {
+ // for viewroot it not applicable.
+ return false;
+ }
+
+ public void setRenderRegionOnly(boolean reRenderPage) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void encodeAjax(FacesContext context) throws IOException {
+ String rendererType = getRendererType();
+ if (rendererType != null) {
+ ((AjaxContainerRenderer) getRenderer(context)).encodeAjax(context,
+ this);
+ }
+
+ }
+
+ /**
+ * @return the brige
+ */
+ protected AjaxRegionBrige getBrige() {
+ return _brige;
+ }
+
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java (from
rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxContextImpl.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,760 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.context;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.StateManager;
+import javax.faces.application.ViewHandler;
+import javax.faces.application.StateManager.SerializedView;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import javax.faces.render.Renderer;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.application.AjaxViewHandler;
+import org.ajax4jsf.component.AjaxContainer;
+import org.ajax4jsf.component.AjaxViewRoot;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.context.ViewIdHolder;
+import org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter;
+import org.ajax4jsf.framework.ajax.xmlfilter.FilterServletResponseWrapper;
+import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
+import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
+import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
+import org.ajax4jsf.renderkit.HeaderResourceProducer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.richfaces.skin.Skin;
+import org.richfaces.skin.SkinFactory;
+import org.richfaces.skin.SkinNotFoundException;
+
+/**
+ * This class incapsulated
+ *
+ * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.7 $ $Date: 2007/02/08 19:07:16 $
+ *
+ */
+public class AjaxContextImpl extends AjaxContext {
+ public static final String RESOURCES_PROCESSED =
"org.ajax4jsf.framework.HEADER_PROCESSED";
+
+ private static final Log log = LogFactory.getLog(AjaxContext.class);
+
+ private static ComponentInvoker invoker;
+
+ private static Map contextClasses = new HashMap();
+
+ Set ajaxAreasToRender = new HashSet();
+
+ Set ajaxRenderedAreas = new HashSet();
+
+ boolean ajaxRequest = false;
+
+ boolean ajaxRequestSet = false;
+
+ boolean selfRender = false;
+
+ Integer viewSequence = new Integer(1);
+
+ String submittedRegionClientId = null;
+
+ boolean submittedRegionSet = false;
+
+ ViewIdHolder viewIdHolder = null;
+
+ Map responseDataMap = new HashMap();
+
+ Map commonAjaxParameters = new HashMap();
+
+ static {
+ try {
+ // Attempt to create JSF1.2 specific invoker.
+ invoker = new JsfOneOneInvoker();
+ } catch (Exception e) {
+ invoker = new JsfOneOneInvoker();
+ }
+ }
+
+ /**
+ * @param root
+ * @param context
+ * @param callback
+ * @param regionId
+ * @return
+ * @see
org.ajax4jsf.context.JsfOneOneInvoker#invokeOnComponent(javax.faces.component.UIComponent,
+ * javax.faces.context.FacesContext,
+ * org.ajax4jsf.context.InvokerCallback, java.lang.String)
+ */
+ public static boolean invokeOnComponent(UIComponent root,
+ FacesContext context, InvokerCallback callback, String regionId) {
+ return invoker.invokeOnComponent(root, context, callback, regionId);
+ }
+
+ /**
+ * @param viewRoot
+ * @param context
+ * @param callback
+ * @see
org.ajax4jsf.context.JsfOneOneInvoker#invokeOnRegionOrRoot(org.ajax4jsf.component.AjaxViewRoot,
+ * javax.faces.context.FacesContext,
+ * org.ajax4jsf.context.InvokerCallback)
+ */
+ public static void invokeOnRegionOrRoot(AjaxViewRoot viewRoot,
+ FacesContext context, InvokerCallback callback) {
+ invoker.invokeOnRegionOrRoot(viewRoot, context, callback);
+ }
+
+ private InvokerCallback _ajaxInvoker = new InvokerCallback() {
+
+ public void invoke(FacesContext context, UIComponent component) {
+ if (component instanceof AjaxContainer) {
+ AjaxContainer ajax = (AjaxContainer) component;
+ renderAjaxRegion(context, component, true);
+ } else {
+ // Container not found, use Root for encode.
+ renderAjaxRegion(context, context.getViewRoot(), true);
+ }
+ }
+
+ public void invokeRoot(FacesContext context) {
+ renderAjaxRegion(context, context.getViewRoot(), true);
+ }
+
+ };
+
+ public void renderSubmittedAjaxRegion(FacesContext context) {
+ renderSubmittedAjaxRegion(context, true);
+ }
+
+ public void renderSubmittedAjaxRegion(FacesContext context,
+ final boolean useFilterWriter) {
+ InvokerCallback ajaxInvoker = new InvokerCallback() {
+
+ public void invoke(FacesContext context, UIComponent component) {
+ if (component instanceof AjaxContainer) {
+ renderAjaxRegion(context, component, useFilterWriter);
+ } else {
+ // Container not found, use Root for encode.
+ renderAjaxRegion(context, context.getViewRoot(),
+ useFilterWriter);
+ }
+ }
+
+ public void invokeRoot(FacesContext context) {
+ renderAjaxRegion(context, context.getViewRoot(),
+ useFilterWriter);
+ }
+
+ };
+ if (!invokeOnComponent(context.getViewRoot(), context, ajaxInvoker,
+ getSubmittedRegionClientId(context))) {
+ renderAjaxRegion(context, context.getViewRoot(), useFilterWriter);
+ }
+
+ }
+
+ /**
+ * @param context
+ * @param useFilterWriter
+ * TODO
+ * @throws AbortProcessingException
+ */
+ public void renderAjaxRegion(FacesContext context, UIComponent component,
+ boolean useFilterWriter) throws FacesException {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.RENDER_AJAX_REQUEST,
+ component.getId()));
+ }
+ try {
+ setSelfRender(true);
+ // create response writer.
+ ExternalContext extContext = context.getExternalContext();
+ RenderKit renderKit = context.getRenderKit();
+ String encoding;
+ // Depends if we talk about servlets, portlets, ...
+ if (extContext.getRequest() instanceof ServletRequest) {
+ ServletRequest request = (ServletRequest) extContext
+ .getRequest();
+ ServletResponse response = (ServletResponse) extContext
+ .getResponse();
+ // HACK - bypass MyFaces ( and other ) extensions filter.
+
+ // Setup encoding and content type
+ String contentType = "text/xml";
+ // get the encoding - must be setup by faces context or filter.
+ encoding = request.getCharacterEncoding();
+ if (encoding == null) {
+ encoding = "UTF-8";
+ }
+ response.setContentType(contentType + ";charset=" + encoding);
+ } else
+ encoding = "UTF-8";
+
+ PrintWriter servletWriter;
+ if (useFilterWriter
+ && extContext.getRequestMap().containsKey(
+ BaseFilter.RESPONSE_WRAPPER_ATTRIBUTE)) {
+ // HACK - Special case for MyFaces, since <f:view don't call
+ // encode methods,
+ // encode response as for self-rendered region directly to
+ // filter response wrpper.
+ // to avoid exceptions, inform wrapper to ignore illegal states
+ // for getWriter/Stream.
+ ServletResponse servletResponse = (ServletResponse) extContext
+ .getRequestMap().get(
+ BaseFilter.RESPONSE_WRAPPER_ATTRIBUTE);
+ servletResponse.resetBuffer();
+ servletWriter = servletResponse.getWriter();
+ ((FilterServletResponseWrapper) servletResponse)
+ .setUseNullStream(true);
+ } else {
+ servletWriter = getWriter(extContext);
+ }
+ ResponseWriter writer = renderKit.createResponseWriter(
+ servletWriter, null, encoding);
+ context.setResponseWriter(writer);
+ // make response
+ writer.startDocument();
+ encodeAjaxBegin(context, component);
+ component.encodeBegin(context);
+ ((AjaxContainer) component).encodeAjax(context);
+ component.encodeEnd(context);
+ saveViewState(context);
+ encodeAjaxEnd(context, component);
+ writer.endDocument();
+ writer.flush();
+ writer.close();
+ servletWriter.close();
+ // Save tree state.
+ } catch (IOException e) {
+ throw new FacesException(Messages.getMessage(
+ Messages.RENDERING_AJAX_REGION_ERROR, component
+ .getClientId(context)), e);
+ } finally {
+ context.responseComplete();
+ // component.setRendererType(defaultRenderer);
+ }
+ }
+
+ /**
+ * Encode declaration for AJAX response. Render
<html><body>
+ *
+ * @param context
+ * @param component
+ * @throws IOException
+ */
+ public void encodeAjaxBegin(FacesContext context, UIComponent component)
+ throws IOException {
+ // AjaxContainer ajax = (AjaxContainer) component;
+ ResponseWriter out = context.getResponseWriter();
+ // DebugUtils.traceView("ViewRoot in AJAX Page encode begin");
+ out.startElement(HTML.HTML_ELEMENT, component);
+ // TODO - html attributes. lang - from current locale ?
+ Locale locale = context.getViewRoot().getLocale();
+ out.writeAttribute(HTML.lang_ATTRIBUTE, locale.toString(), "lang");
+ out.startElement(HTML.BODY_ELEMENT, component);
+ }
+
+ /**
+ * End encoding of AJAX response. Render tag with included areas and
+ * close </body></html>
+ *
+ * @param context
+ * @param component
+ * @throws IOException
+ */
+ public void encodeAjaxEnd(FacesContext context, UIComponent component)
+ throws IOException {
+ // AjaxContainer ajax = (AjaxContainer) component;
+ ResponseWriter out = context.getResponseWriter();
+ // DebugUtils.traceView("ViewRoot in AJAX Page encode begin");
+ out.endElement(HTML.BODY_ELEMENT);
+ out.endElement(HTML.HTML_ELEMENT);
+ }
+
+ /**
+ * @param context
+ * @param root
+ * @throws FacesException
+ */
+ public void processHeadResources(FacesContext context)
+ throws FacesException {
+ ExternalContext externalContext = context.getExternalContext();
+ Map requestMap = externalContext.getRequestMap();
+ if (!Boolean.TRUE.equals(requestMap.get(RESOURCES_PROCESSED))) {
+ if (null != requestMap.get(BaseFilter.RESPONSE_WRAPPER_ATTRIBUTE)) {
+ if (log.isDebugEnabled()) {
+ log
+ .debug("Process component tree for collect used scripts and styles");
+ }
+ UIViewRoot root = context.getViewRoot();
+ Set scripts = new LinkedHashSet();
+ Set styles = new LinkedHashSet();
+ RenderKitFactory rkFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKit renderKit = rkFactory.getRenderKit(context, context
+ .getViewRoot().getRenderKitId());
+ processHeadResources(context, root, scripts, styles, renderKit);
+ if (scripts.size() > 0) {
+ if (log.isDebugEnabled()) {
+ StringBuffer buff = new StringBuffer(
+ "Scripts for insert into head : \n");
+ for (Iterator iter = scripts.iterator(); iter.hasNext();) {
+ String script = (String) iter.next();
+ buff.append(script).append("\n");
+ }
+ log.debug(buff.toString());
+ }
+ requestMap.put(SCRIPTS_PARAMETER, scripts);
+ }
+ // Set default style sheet for current skin.
+ String styleSheetUri = null;
+ try {
+ styleSheetUri = (String) SkinFactory.getInstance().getSkin(
+ context).getParameter(context,
+ Skin.generalStyleSheet);
+ } catch (SkinNotFoundException e) {
+ log.warn("Current Skin is not found", e);
+ }
+ if (null != styleSheetUri) {
+ String resourceURL = context.getApplication()
+ .getViewHandler().getResourceURL(context,
+ styleSheetUri);
+ // TODO - some resources can be non-session aware, we
+ // must
+ // skip encoding for this case ?
+ // But, in common case - static links not need session
+ // info,
+ // and dynamic resources perform encodings if nessesary
+ // resourceURL =
+ // context.getExternalContext().encodeResourceURL(resourceURL);
+ styles.add(resourceURL);
+ }
+ if (styles.size() > 0) {
+ if (log.isDebugEnabled()) {
+ StringBuffer buff = new StringBuffer(
+ "Styles for insert into head : \n");
+ for (Iterator iter = styles.iterator(); iter.hasNext();) {
+ String style = (String) iter.next();
+ buff.append(style).append("\n");
+ }
+ log.debug(buff.toString());
+ }
+ requestMap.put(STYLES_PARAMETER, styles);
+ }
+ // Mark as processed.
+ requestMap.put(RESOURCES_PROCESSED, Boolean.TRUE);
+ }
+
+ }
+ }
+
+ /**
+ * Append nessesary scripts and styles from component ( if renderer
+ * implements {@link HeaderResourceProducer}) and recursive process all
+ * facets and childrens.
+ *
+ * @param context
+ * TODO
+ * @param root
+ * @param scripts
+ * @param styles
+ * @param renderKit
+ * TODO
+ */
+ private void processHeadResources(FacesContext context, UIComponent root,
+ Set scripts, Set styles, RenderKit renderKit) {
+ Renderer renderer = getRenderer(context, root, renderKit);
+ if (null != renderer) {
+ if (renderer instanceof HeaderResourceProducer) {
+ HeaderResourceProducer producer = (HeaderResourceProducer) renderer;
+ Set set = producer.getHeaderScripts(context, root);
+ if (null != set) {
+ scripts.addAll(set);
+ }
+ set = producer.getHeaderStyles(context, root);
+ if (null != set) {
+ styles.addAll(set);
+ }
+ }
+ }
+ for (Iterator iter = root.getFacets().values().iterator(); iter
+ .hasNext();) {
+ UIComponent child = (UIComponent) iter.next();
+ processHeadResources(context, child, scripts, styles, renderKit);
+ }
+ for (Iterator iter = root.getChildren().iterator(); iter.hasNext();) {
+ UIComponent child = (UIComponent) iter.next();
+ processHeadResources(context, child, scripts, styles, renderKit);
+ }
+ }
+
+ /**
+ * Find renderer for given component.
+ *
+ * @param context
+ * @param comp
+ * @param renderKit
+ * @return
+ */
+ private Renderer getRenderer(FacesContext context, UIComponent comp,
+ RenderKit renderKit) {
+
+ String rendererType = comp.getRendererType();
+ if (rendererType != null) {
+ return (renderKit.getRenderer(comp.getFamily(), rendererType));
+ } else {
+ return (null);
+ }
+
+ }
+
+ public void saveViewState(FacesContext context) throws IOException {
+ // TODO - for facelets environment, we need to remove transient
+ // components.
+ try {
+ Application.class.getMethod("getExpressionFactory", null);
+ } catch (NoSuchMethodException e) {
+ // JSF 1.1 !
+ }
+ ResponseWriter writer = context.getResponseWriter();
+ StateManager stateManager = context.getApplication().getStateManager();
+ SerializedView serializedView = stateManager
+ .saveSerializedView(context);
+ if (null != serializedView) {
+ StringWriter bufWriter = new StringWriter();
+ ResponseWriter cloneWithWriter = writer.cloneWithWriter(bufWriter);
+ context.setResponseWriter(cloneWithWriter);
+ stateManager.writeState(context, serializedView);
+ cloneWithWriter.flush();
+ if (bufWriter.getBuffer().length() > 0) {
+ context.getExternalContext().getRequestMap().put(
+ AjaxViewHandler.SERIALIZED_STATE_KEY,
+ bufWriter.toString());
+ }
+ // Restore original writer.
+ context.setResponseWriter(writer);
+ }
+ }
+
+ /**
+ * @return Returns the ajaxRequest.
+ */
+ public boolean isAjaxRequest() {
+ return isAjaxRequest(FacesContext.getCurrentInstance());
+ }
+
+ /**
+ * @return Returns the ajaxRequest.
+ */
+ public boolean isAjaxRequest(FacesContext context) {
+ if (!this.ajaxRequestSet) {
+ ajaxRequest = null != getSubmittedRegionClientId(context);
+ ajaxRequestSet = true;
+ }
+ return ajaxRequest;
+ }
+
+ /**
+ * @param ajaxRequest
+ * The ajaxRequest to set.
+ */
+ public void setAjaxRequest(boolean ajaxRequest) {
+ this.ajaxRequest = ajaxRequest;
+ this.ajaxRequestSet = true;
+ }
+
+ /**
+ * @return Returns the ajaxAreasToRender.
+ */
+ public Set getAjaxAreasToRender() {
+ return this.ajaxAreasToRender;
+ }
+
+ /**
+ * Add affected regions's ID to ajaxView component.
+ *
+ * @param component
+ */
+ public void addRegionsFromComponent(UIComponent component) {
+ // First step - find parent ajax view
+ Set ajaxRegions = AjaxRendererUtils.getAjaxAreas(component);
+ // if (ajaxRegions == null){
+ // FacesContext context = FacesContext.getCurrentInstance();
+ // ajaxRegions = AjaxRendererUtils.getAbsoluteId(context,component);
+ // }
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.INVOKE_AJAX_REGION_LISTENER,
+ component.getId()));
+ }
+ if (ajaxRegions != null) {
+ for (Iterator iter = ajaxRegions.iterator(); iter.hasNext();) {
+ String id = iter.next().toString();
+ ajaxAreasToRender.add(convertId(component, id));
+ }
+ }
+ }
+
+ public void addComponentToAjaxRender(UIComponent component) {
+ this.ajaxAreasToRender.add(AjaxRendererUtils.getAbsoluteId(component));
+ }
+
+ public void addComponentToAjaxRender(UIComponent base, String id) {
+ this.ajaxAreasToRender.add(convertId(base, id));
+ }
+
+ /**
+ * Test for relative id of target components. Attempt convert to
+ * absolute. For use as argument for
+ * {@link UIComponent#findComponent(java.lang.String)}
+ *
+ * @param component
+ * @param id
+ * @return
+ */
+ private String convertId(UIComponent component, String id) {
+ if (id.charAt(0) == NamingContainer.SEPARATOR_CHAR) {
+ return id;
+ }
+ if (null == component) {
+ throw new NullPointerException(
+ "Base component for search re-rendered compnnent is null");
+ }
+ UIComponent target = null;
+ UIComponent parent = component;
+ UIComponent root = component;
+ while (null == target && null != parent) {
+ target = parent.findComponent(id);
+ root = parent;
+ parent = parent.getParent();
+ }
+ if (null == target) {
+ target = findUIComponentBelow(root, id);
+ }
+ if (null != target) {
+ return AjaxRendererUtils.getAbsoluteId(target);
+ }
+ log.warn("Target component for id "+id+" not found");
+ return id;
+ }
+
+ private UIComponent findUIComponentBelow(UIComponent root,
+ String id) {
+
+ UIComponent target = null;
+ for (Iterator iter = root.getFacetsAndChildren(); iter.hasNext();) {
+ UIComponent child = (UIComponent) iter.next();
+ if (child instanceof NamingContainer) {
+ try {
+ target = child.findComponent(id);
+ } catch (IllegalArgumentException iae) {
+ continue;
+ }
+ }
+ if (target == null) {
+ if (child.getChildCount() > 0) {
+ target = findUIComponentBelow(child, id);
+ }
+ }
+
+ if (target != null) {
+ break;
+ }
+
+ }
+ return target;
+ }
+
+ /**
+ * @return Returns the ajaxRenderedAreas.
+ */
+ public Set getAjaxRenderedAreas() {
+ return ajaxRenderedAreas;
+ }
+
+ public void addRenderedArea(String id) {
+ ajaxRenderedAreas.add(id);
+ }
+
+ public boolean removeRenderedArea(String id) {
+ return ajaxRenderedAreas.remove(id);
+ }
+
+ /**
+ * @return Returns the submittedClientId.
+ */
+ public String getSubmittedRegionClientId(FacesContext context) {
+ if (!this.submittedRegionSet) {
+ this.submittedRegionClientId = (String) context
+ .getExternalContext().getRequestParameterMap().get(
+ AjaxContainerRenderer.AJAX_PARAMETER_NAME);
+ this.submittedRegionSet = true;
+ if (!this.ajaxRequestSet) {
+ setAjaxRequest(this.submittedRegionClientId != null);
+ }
+ }
+ return this.submittedRegionClientId;
+ }
+
+ /**
+ * @param submittedClientId
+ * The submittedClientId to set.
+ */
+ public void setSubmittedRegionClientId(String submittedClientId) {
+ this.submittedRegionClientId = submittedClientId;
+ this.submittedRegionSet = true;
+ }
+
+ /**
+ * @return Returns the selfRender.
+ */
+ public boolean isSelfRender() {
+ return selfRender;
+ }
+
+ /**
+ * @param selfRender
+ * The selfRender to set.
+ */
+ public void setSelfRender(boolean selfRender) {
+ this.selfRender = selfRender;
+ }
+
+ /**
+ * @return the vievIdHolder
+ */
+ public ViewIdHolder getViewIdHolder() {
+ return viewIdHolder;
+ }
+
+ /**
+ * @param viewIdHolder
+ * the vievIdHolder to set
+ */
+ public void setViewIdHolder(ViewIdHolder viewIdHolder) {
+ this.viewIdHolder = viewIdHolder;
+ }
+
+ /**
+ * @return the responseData
+ */
+ public Object getResponseData() {
+ return responseDataMap.get(RESPONSE_DATA_KEY);
+ }
+
+ /**
+ * @param responseData
+ * the responseData to set
+ */
+ public void setResponseData(Object responseData) {
+ this.responseDataMap.put(RESPONSE_DATA_KEY, responseData);
+ }
+
+ /**
+ * @return the responseDataMap
+ */
+ public Map getResponseDataMap() {
+ return responseDataMap;
+ }
+
+ /**
+ * Gives back the writer of a Response object.
+ *
+ * @param extContext
+ * The external context.
+ * @return The writer of the response.
+ * @throws FacesException
+ * If the response object has no getWriter() method.
+ */
+ protected PrintWriter getWriter(ExternalContext extContext)
+ throws FacesException {
+ PrintWriter writer = null;
+ Object response = extContext.getResponse();
+ try {
+ Method gW = response.getClass()
+ .getMethod("getWriter", new Class[0]);
+ writer = (PrintWriter) gW.invoke(response, new Object[0]);
+ } catch (Exception e) {
+ throw new FacesException(e);
+ }
+ return writer;
+ }
+
+ public String getAjaxActionURL() {
+ return getAjaxActionURL(FacesContext.getCurrentInstance());
+ }
+
+ public String getAjaxActionURL(FacesContext context) {
+ // Check arguments
+ if (null == context) {
+ throw new NullPointerException(
+ "Faces context for build AJAX Action URL is null");
+ }
+ UIViewRoot viewRoot = context.getViewRoot();
+ if (null == viewRoot) {
+ throw new NullPointerException(
+ "Faces view tree for build AJAX Action URL is null");
+ }
+ String viewId = viewRoot.getViewId();
+ if (null == viewId) {
+ throw new NullPointerException(
+ "View id for build AJAX Action URL is null");
+ }
+ if (!viewId.startsWith("/")) {
+ throw new IllegalArgumentException(
+ "Illegal view Id for build AJAX Action URL: " + viewId);
+ }
+ ViewHandler viewHandler = context.getApplication().getViewHandler();
+ return context.getExternalContext().encodeActionURL(
+ viewHandler.getActionURL(context, viewId));
+ }
+
+ /**
+ * @return the commonAjaxParameters
+ */
+ public Map getCommonAjaxParameters() {
+ return commonAjaxParameters;
+ }
+
+}
\ No newline at end of file
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/context/ComponentInvoker.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/ComponentInvoker.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/context/ComponentInvoker.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/context/ComponentInvoker.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,57 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.context;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.component.AjaxViewRoot;
+
+/**
+ * Interface for call lifecycle methods on component with known clientId
+ * For JSF 1.2 implementation must use invokeOnComponent method, for JSF 1.1 use
+ * simple recursion on view tree ( not compatible with UIData components )
+ * @author shura
+ *
+ */
+public interface ComponentInvoker {
+
+ /**
+ * Invoke method on active AjaxContainer component, or on viewRoot, if none.
+ * @param viewRoot
+ * @param context
+ * @param callback
+ */
+ public abstract void invokeOnRegionOrRoot(AjaxViewRoot viewRoot,
+ FacesContext context, InvokerCallback callback);
+
+ /**
+ * Recursive call for all children for search component with same clientId as target
region
+ * @param viewRoot
+ * @param context
+ * @param callback
+ * @param regionId
+ */
+ public abstract boolean invokeOnComponent(UIComponent root,
+ FacesContext context, InvokerCallback callback, String regionId);
+
+}
\ No newline at end of file
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/context/InvokerCallback.java (from
rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/InvokerCallback.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/context/InvokerCallback.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/context/InvokerCallback.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,48 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.context;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+/**
+ * Callback Interface
+ * for invoke lifecycle methods ( processDecodes, processValidators ... encodeEnd ).
+ * @author shura
+ *
+ */
+public interface InvokerCallback {
+
+ /**
+ * Process method on given component.
+ * @param context
+ * @param component
+ */
+ public void invoke(FacesContext context, UIComponent component);
+
+ /**
+ * Default processing on UIVewRoot
+ * @param context
+ */
+ public void invokeRoot(FacesContext context);
+
+}
Copied: trunk/framework/impl/src/main/java/org/ajax4jsf/context/JsfOneOneInvoker.java
(from rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/JsfOneOneInvoker.java)
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/context/JsfOneOneInvoker.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/context/JsfOneOneInvoker.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,90 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.context;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.component.AjaxViewRoot;
+import org.ajax4jsf.context.AjaxContext;
+
+/**
+ * @author shura
+ *
+ */
+public class JsfOneOneInvoker implements ComponentInvoker {
+
+
+ /**
+ *
+ */
+ public JsfOneOneInvoker() {
+ // TODO Auto-generated constructor stub
+ }
+
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.framework.ajax.AjaxInvoker#invokeOnRegionOrRoot(org.ajax4jsf.framework.ajax.AjaxViewRoot,
javax.faces.context.FacesContext, org.ajax4jsf.framework.ajax.InvokerCallback,
javax.faces.event.PhaseId)
+ */
+ public void invokeOnRegionOrRoot(AjaxViewRoot viewRoot, FacesContext context,
InvokerCallback callback) {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ String submittedRegionClientId = ajaxContext.getSubmittedRegionClientId(context);
+ if(null == submittedRegionClientId ||
viewRoot.getId().equals(submittedRegionClientId)){
+ // This is a not AJAX request, or active region is root.
+ callback.invokeRoot(context);
+ } else {
+ if(!invokeOnComponent(viewRoot, context, callback, submittedRegionClientId)){
+ // Region not found - perform default actions.
+ // TODO - log errors.
+ callback.invokeRoot(context);
+ }
+ }
+
+ }
+
+ public void invokeOnRegion(FacesContext context, InvokerCallback callback, String
regionId) {
+ UIViewRoot viewRoot = context.getViewRoot();
+ invokeOnComponent(viewRoot,context,callback,regionId);
+ }
+
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.framework.ajax.AjaxInvoker#invokeOnComponent(javax.faces.component.UIComponent,
javax.faces.context.FacesContext, org.ajax4jsf.framework.ajax.InvokerCallback,
java.lang.String)
+ */
+ public boolean invokeOnComponent(UIComponent root, FacesContext context, InvokerCallback
callback, String regionId) {
+ if(regionId.equals(root.getClientId(context))){
+ callback.invoke(context, root);
+ return true;
+ }
+ for (Iterator iter = root.getFacetsAndChildren(); iter.hasNext();) {
+ UIComponent child = (UIComponent) iter.next();
+ if(invokeOnComponent(child, context, callback, regionId)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
Deleted: trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugLifecycle.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugLifecycle.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugLifecycle.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,170 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework;
-
-import javax.faces.FacesException;
-import javax.faces.context.FacesContext;
-import javax.faces.event.PhaseEvent;
-import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
-import javax.faces.lifecycle.Lifecycle;
-import javax.faces.lifecycle.LifecycleFactory;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:12 $
- *
- */
-public class DebugLifecycle extends Lifecycle implements PhaseListener{
-
- /**
- *
- */
- private static final long serialVersionUID = -3247965217553145312L;
-
- private Lifecycle _default;
-
- private static Log _log = LogFactory.getLog(DebugLifecycle.class);
-
- public static final String DEBUG_LYFECYCLE_ID = "DEBUG";
-
- public static final String LIFECYCLE_ID_ATTR = "javax.faces.LIFECYCLE_ID";
-
-
- public static final String PHASE_ID_PARAM = "org.ajax4jsf.CURRENT_PHASE";
-
- private static final DebugOutputMaker debugOutput = new DebugOutputMaker();
-
- /**
- * @param default1
- */
- public DebugLifecycle(Lifecycle default1) {
- super();
- // TODO Auto-generated constructor stub
- this._default = default1;
- }
-
- /**
- *
- */
- public DebugLifecycle(LifecycleFactory defaultFactory) {
- super();
- _default = defaultFactory
- .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
- _default.addPhaseListener(this);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.lifecycle.Lifecycle#addPhaseListener(javax.faces.event.PhaseListener)
- */
- public void addPhaseListener(PhaseListener arg0) {
- _default.addPhaseListener(arg0);
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.lifecycle.Lifecycle#execute(javax.faces.context.FacesContext)
- */
- public void execute(FacesContext context) throws FacesException {
- try {
- _default.execute(context);
- } catch (Throwable e) {
-// DebugOutputMaker debugOutput = new DebugOutputMaker();
- debugOutput.writeErrorMessage(context, e, "execute");
- context.responseComplete();
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.lifecycle.Lifecycle#getPhaseListeners()
- */
- public PhaseListener[] getPhaseListeners() {
- // TODO Auto-generated method stub
- return _default.getPhaseListeners();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.lifecycle.Lifecycle#removePhaseListener(javax.faces.event.PhaseListener)
- */
- public void removePhaseListener(PhaseListener arg0) {
- _default.removePhaseListener(arg0);
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.lifecycle.Lifecycle#render(javax.faces.context.FacesContext)
- */
- public void render(FacesContext context) throws FacesException {
- try {
- _default.render(context);
- } catch (Throwable e) {
-// DebugOutputMaker debugOutput = new DebugOutputMaker();
- debugOutput.writeErrorMessage(context, e, "render");
- context.responseComplete();
- }
- }
-
-
-
-
- /* (non-Javadoc)
- * @see javax.faces.event.PhaseListener#afterPhase(javax.faces.event.PhaseEvent)
- */
- public void afterPhase(PhaseEvent event) {
- if (_log.isDebugEnabled()) {
- _log.debug("End phase "+event.getPhaseId().toString());
- }
-
- }
-
- /* (non-Javadoc)
- * @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
- */
- public void beforePhase(PhaseEvent event) {
- if (_log.isDebugEnabled()) {
- _log.debug("Start phase "+event.getPhaseId().toString());
- }
- event.getFacesContext().getExternalContext().getRequestMap().put(PHASE_ID_PARAM,event.getPhaseId());
-
- }
-
- /* (non-Javadoc)
- * @see javax.faces.event.PhaseListener#getPhaseId()
- */
- public PhaseId getPhaseId() {
- // TODO Auto-generated method stub
- return PhaseId.ANY_PHASE;
- }
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugLifecycleFactory.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugLifecycleFactory.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugLifecycleFactory.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,99 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework;
-
-import java.util.Iterator;
-
-import javax.faces.lifecycle.Lifecycle;
-import javax.faces.lifecycle.LifecycleFactory;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:12 $
- *
- */
-public class DebugLifecycleFactory extends LifecycleFactory {
-
- private static final Log _log = LogFactory
- .getLog(DebugLifecycleFactory.class);
-
- private LifecycleFactory _defaultFactory;
-
- private DebugLifecycle _debugLifecycle ;
-
-// private Map _lifecycles = new HashMap();
-
- /**
- * @return the debugLifecycle
- */
- private DebugLifecycle getDebugLifecycle() {
- if (_debugLifecycle == null) {
- _debugLifecycle = new DebugLifecycle(_defaultFactory);
- }
- return _debugLifecycle;
- }
-
- /**
- * @param defaultFactory
- */
- public DebugLifecycleFactory(LifecycleFactory defaultFactory) {
- super();
- this._defaultFactory = defaultFactory;
- if (_log.isDebugEnabled()) {
- _log.debug("Created Lifecycle instance");
- }
- }
-
- /* (non-Javadoc)
- * @see javax.faces.lifecycle.LifecycleFactory#addLifecycle(java.lang.String,
javax.faces.lifecycle.Lifecycle)
- */
- public void addLifecycle(String lifecycleId, Lifecycle lifecycle) {
- this._defaultFactory.addLifecycle(lifecycleId, lifecycle);
- if (_log.isDebugEnabled()) {
- _log.debug("Added lifecycle with ID "+lifecycleId);
- }
- }
-
- /* (non-Javadoc)
- * @see javax.faces.lifecycle.LifecycleFactory#getLifecycle(java.lang.String)
- */
- public Lifecycle getLifecycle(String lifecycleId) {
- Lifecycle life;
- if(DebugLifecycle.DEBUG_LYFECYCLE_ID.equals(lifecycleId)) {
- life = getDebugLifecycle();
- } else {
- life = this._defaultFactory.getLifecycle(lifecycleId);
- }
- return life;
- }
-
- /* (non-Javadoc)
- * @see javax.faces.lifecycle.LifecycleFactory#getLifecycleIds()
- */
- public Iterator getLifecycleIds() {
- return this._defaultFactory.getLifecycleIds();
- }
-
-}
Deleted: trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugOutputMaker.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugOutputMaker.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/DebugOutputMaker.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,465 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework;
-
-import java.beans.PropertyDescriptor;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import javax.faces.FacesException;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
-import javax.faces.el.ValueBinding;
-import javax.faces.event.PhaseId;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.resource.InternetResource;
-import org.ajax4jsf.resource.InternetResourceBuilder;
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.beanutils.PropertyUtils;
-
-
-/**
- * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:11 $
- *
- */
-public class DebugOutputMaker {
- private final static String LT = "<";
- private final static String GT = ">";
- // Attributes that should not be printed
- static public final HashSet IGNORE_ATTRIBUTES;
-
- static {
- IGNORE_ATTRIBUTES = new HashSet();
- IGNORE_ATTRIBUTES.add("attributes");
- IGNORE_ATTRIBUTES.add("children");
- IGNORE_ATTRIBUTES.add("childCount");
- IGNORE_ATTRIBUTES.add("class");
- IGNORE_ATTRIBUTES.add("facets");
- IGNORE_ATTRIBUTES.add("facetsAndChildren");
- IGNORE_ATTRIBUTES.add("parent");
- IGNORE_ATTRIBUTES.add("actionListeners");
- IGNORE_ATTRIBUTES.add("valueChangeListeners");
- IGNORE_ATTRIBUTES.add("validators");
- IGNORE_ATTRIBUTES.add("rowData");
- IGNORE_ATTRIBUTES.add("javax.faces.webapp.COMPONENT_IDS");
- IGNORE_ATTRIBUTES.add("javax.faces.webapp.FACET_NAMES");
- IGNORE_ATTRIBUTES.add("javax.faces.webapp.CURRENT_VIEW_ROOT");
- }
-
- private static final String LOGFILE_PARAM = "org.ajax4jsf.LOGFILE";
-
- /**
- * Output error state for lifecycle.
- *
- * @param context
- * @param phase
- * TODO
- * @param error
- * @throws IOException
- */
- public void writeErrorMessage(FacesContext context, Throwable e, String phase)
- throws FacesException {
- if (null == context) {
- throw new FacesException(Messages.getMessage(Messages.FACES_CONTEXT_NOT_CREATED), e);
- }
- ExternalContext externalContext = context
- .getExternalContext();
- if (null == externalContext) {
- throw new FacesException(Messages.getMessage(Messages.FACES_CONTEXT_HAS_NOT_EXTERNAL),
e);
- }
- // debug for http servlet environment, portlets needs other debugger
- HttpServletResponse response;
- HttpServletRequest request;
- try {
- response = (HttpServletResponse) externalContext
- .getResponse();
- request = (HttpServletRequest) externalContext.getRequest();
- response.setContentType("text/html;charset=UTF-8");
- // set internal server error status
- response.setStatus(500);
- } catch (Exception er) {
- throw new FacesException(Messages.getMessage(Messages.FACES_CONTEXT_HAS_NOT_RESPONSE),
e);
- }
- PrintWriter out;
- try {
- out = response.getWriter();
- } catch (IOException e1) {
- throw new FacesException(e1.getMessage(), e);
- }
- UIViewRoot viewRoot = context.getViewRoot();
- String viewId;
- if (null != viewRoot) {
- viewId = viewRoot.getViewId();
- } else {
- viewId = request.getRequestURL().toString();
- }
- // output html prolog
- out.println("<html><head><title>" +
- Messages.getMessage(Messages.ERROR_ON_PAGE, viewId) +
- "</title></head><body>");
- // write script
- writeScriptAndStyle(out);
- // Header
- PhaseId facesPhase = (PhaseId)
context.getExternalContext().getRequestMap().get(DebugLifecycle.PHASE_ID_PARAM);
-
- String errorMessage =
- (facesPhase == null)
- ? Messages.getMessage(Messages.LIFECYCLE_ERROR, viewId, phase)
- : Messages.getMessage(Messages.LIFECYCLE_ERROR_AT_PHASE, new Object[]{viewId, phase,
facesPhase.toString()});
- out.println("<h1 >");
- out.println(errorMessage);
- out.println("</h1>");
- response.setHeader("Ajax-Error-Message", errorMessage+",\n caused by
"+e.getClass().getName()+", with message: "+e.getMessage());
- // Output exceptions
- writeExceptionStack(e, out);
- // Output view tree :
- if (null != viewRoot) {
- writeComponentsTree(context, out);
- } else {
- out.print("<h2 class=' a4j_debug'> " +
- Messages.getMessage(Messages.COMPONENT_TREE_NOT_CREATED) +
- " </h2>");
- }
- // Out scope variables
- writeContextVariables(context, out);
- // Write log output iframe :
- writeLog(context, out);
- // out html tail
- out.println("</body></html>");
- out.flush();
- out.close();
- }
- /**
- * @param e
- * @param out
- */
- public void writeExceptionStack(Throwable e, PrintWriter out) {
- out.println("<h2 class=\"a4j_debug\">Exceptions:
</h2>");
- Throwable error = e;
- int errorId = 0;
- String caused = "exception ";
- while (null != error) {
- out.print("<h3 onclick=\"toggle('exception" + errorId +
"')\" class='exception a4j_debug'>");
- writeToggleMark(out,"exception" + errorId);
- out.print( caused + error.getClass().getName() + " : "
- + error.getMessage() + "</h3>");
- out.println("<div id='exception" + errorId
- + "' style='display: none;'
class='exception'><p>Exception stack :</p><pre>");
- StackTraceElement[] stackTrace = error.getStackTrace();
- for (int i = 0; i < stackTrace.length; i++) {
- out.print(" at " + stackTrace[i].getClassName());
- out.print("." + stackTrace[i].getMethodName());
- out.println(" in " + stackTrace[i].getFileName() + " line "
- + stackTrace[i].getLineNumber());
- }
- // error.printStackTrace(out);
- out.println("</pre></div>");
- error = error.getCause();
- caused = "caused by ";
- errorId++;
- }
- }
-
- /**
- * @param context
- * @param out
- */
- public void writeContextVariables(FacesContext context, PrintWriter out) {
- out.print("<h2 class=\"a4j_debug\"
onclick=\"toggle('variables')\">");
- writeToggleMark(out,"variables");
- out.println("Faces variables: </h2><div id='variables'
style='display: none;' class='variables a4j_debug'>");
- writeVariables(out,context);
- out.println("</div>");
- }
-
- /**
- * @param context
- * @param out
- */
- public void writeComponentsTree(FacesContext context, PrintWriter out) {
- out
- .print("<h2 class=\"a4j_debug\"
onclick=\"toggle('tree')\">");
- writeToggleMark(out,"tree");
- out.println("Component tree: </h2><div id='tree'
style='display: none;' class='tree a4j_debug'><dl>");
- writeComponent(context, out, context.getViewRoot(), null);
- out.println("</dl></div>");
- }
-
- public void writeScriptAndStyle(PrintWriter out) {
- writeScript(out);
- writeStyleSheet(out);
- }
-
- /**
- * @param context
- * @param out
- * @throws FacesException
- */
- public void writeLog(FacesContext context, PrintWriter out) throws FacesException {
- String logname = context.getExternalContext().getInitParameter(LOGFILE_PARAM);
- if (null != logname) {
- InternetResource logResource =
InternetResourceBuilder.getInstance().createResource(this,logname);
- out.print("<h2 onclick=\"toggle('log')\"
class=\"a4j_debug\">");
- writeToggleMark(out, "log");
- out
- .println("Faces log: </h2><div id='log' style='display:
none;' class='log a4j_debug'>");
- out.print("<iframe name='log' class='log'
src='"+logResource.getUri(context,null)+"'><a
href='src='"+logResource.getUri(context,null)+"'>Faces log file
</a> </iframe>");
- out.println("</div>");
- }
- }
-
- public void writeToggleMark(PrintWriter out,String id) {
- out.print("<span style=\"display:none;\"
id=\""+id+"_expanded\" >- </span>");
- out.print("<span style=\"display:inline;\"
id=\""+id+"_collapsed\" >+</span> ");
- }
-
-
- /**
- * Out component with properties and it's facets and childrens
- * @param context TODO
- * @param out
- * @param viewRoot
- */
- private void writeComponent(FacesContext context, PrintWriter out,
- UIComponent component, String facetName) {
- String clientId = "_tree:"+component.getClientId(context);
- out.println("<dt onclick=\"toggle('"+clientId+"')\"
class='tree'>");
- writeToggleMark(out,clientId);
- // out component name
- if (null != facetName) {
- out.print("Facet:'" + facetName + "' ");
- }
- out.println("<code>" + component.getClass().getName() +
"</code> Id:["+component.getId()+"]");
- out.println("</dt>");
- out.println("<dd id='"+clientId+"'
style='display:none;' class='tree' ><ul
class='tree'>");
- // out bean properties
- try {
- PropertyDescriptor propertyDescriptors[] =
PropertyUtils.getPropertyDescriptors(component);
- for (int i = 0; i < propertyDescriptors.length; i++) {
- if (PropertyUtils.isReadable(component,propertyDescriptors[i].getName())) {
- String name = propertyDescriptors[i].getName();
- ValueBinding vb = component.getValueBinding(name);
- if (vb != null) {
- writeAttribute(out, name, vb.getExpressionString());
- } else {
- if (!IGNORE_ATTRIBUTES.contains(name)) {
- try {
- String value = BeanUtils.getProperty(component,name);
- writeAttribute(out, name, value);
- } catch (Exception e) {
- writeAttribute(out, name, null);
- }
- }
- }
- }
- }
- } catch (Exception e) {
- // Do nothing - we in error page.
- }
-
- // out bindings
- // out attributes map
- for (Iterator it = component.getAttributes().entrySet().iterator(); it
- .hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- writeAttribute(out, (String) entry.getKey(), entry.getValue());
- }
- // out listeners
- out.println("</ul></dd>");
- if (component.getFacetsAndChildren().hasNext()) {
- out.println("<dd class='tree_childs'><dl
class='tree_childs'>");
- // out childs of this component
- // facets
- for (Iterator facetEntry = component.getFacets().entrySet()
- .iterator(); facetEntry.hasNext();) {
- Map.Entry entry = (Map.Entry) facetEntry.next();
- writeComponent(context, out,
- (UIComponent) entry.getValue(), (String) entry.getKey());
- }
- // childs components
- for (Iterator childIter = component.getChildren().iterator(); childIter
- .hasNext();) {
- UIComponent child = (UIComponent) childIter.next();
- writeComponent(context, out, child, null);
- }
- out.println("</dl></dd>");
- }
-
- }
-
- private void writeAttribute(PrintWriter out, String name, Object value) {
- if (IGNORE_ATTRIBUTES.contains(name))
- return;
- if (name.startsWith("javax.faces.webapp.UIComponentTag.")) {
- name = name
- .substring("javax.faces.webapp.UIComponentTag.".length());
- }
- out.print("<li>");
- out.print(name);
- out.print("=\"");
- if (value != null) {
- if (value instanceof UIComponent) {
- out.print("[id:");
- out.print(((UIComponent) value).getId());
- out.print(']');
- } else if (value instanceof MethodBinding) {
- out.print(((MethodBinding) value).getExpressionString());
- } else if (value instanceof ValueBinding) {
- out.print(((ValueBinding) value).getExpressionString());
- } else {
- out.print(value.toString());
- }
- } else {
- out.print("NULL");
- }
- out.println("\"</li>");
- }
-
- private void writeVariables(PrintWriter out, FacesContext faces) {
- ExternalContext ctx = faces.getExternalContext();
- writeVariables(out, ctx.getRequestParameterMap(), "Request
Parameters");
- writeVariables(out, ctx.getRequestMap(), "Request Attributes");
- if (ctx.getSession(false) != null) {
- writeVariables(out, ctx.getSessionMap(), "Session Attributes");
- }
- writeVariables(out, ctx.getApplicationMap(), "Application
Attributes");
- }
-
- private void writeVariables(PrintWriter out, Map vars, String caption) {
- out.print("<table><caption>");
- out.print(caption);
- out.println("</caption><thead><tr><th
style=\"width: 10%; \">Name</th><th style=\"width: 90%;
\">Value</th></tr></thead><tbody>");
- boolean written = false;
- if (!vars.isEmpty()) {
- SortedMap map = new TreeMap(vars);
- Map.Entry entry = null;
- String key = null;
- for (Iterator itr = map.entrySet().iterator(); itr.hasNext(); ) {
- entry = (Map.Entry) itr.next();
- key = entry.getKey().toString();
- if (key.indexOf('.') == -1) {
- out.println("<tr><td>");
- out.println(key.replaceAll("<",
LT).replaceAll(">", GT));
- out.println("</td><td><span
class='value'>");
- Object value = entry.getValue();
- out.println(value.toString().replaceAll("<",
LT).replaceAll(">", GT));
- out.println("</span>");
- try {
- PropertyDescriptor propertyDescriptors[] =
PropertyUtils.getPropertyDescriptors(value);
- if (propertyDescriptors.length>0) {
- out.print("<div class='properties'><ul
class=\'properties\'>");
- for (int i = 0; i < propertyDescriptors.length; i++) {
- String beanPropertyName = propertyDescriptors[i].getName();
- if (PropertyUtils.isReadable(value,beanPropertyName
- )) {
- out.print("<li class=\'properties\'>");
- out.print(beanPropertyName+" =
"+BeanUtils.getProperty(value,beanPropertyName));
- out.print("</li>");
-
- }
- }
- out.print("</ul></div>");
- }
- } catch (Exception e) {
- // TODO: log exception
- }
-
- out.println("</td></tr>");
- written = true;
- }
- }
- }
- if (!written) {
- out.println("<tr><td
colspan=\"2\"><em>None</em></td></tr>");
- }
- out.println("</tbody></table>");
- }
- /**
- * @param out
- */
- private void writeScript(PrintWriter out) {
- out
- .println("<script type='text/javascript'
language='javascript'>\n"
- + "function toggle(id) {\n"
- + "var style = document.getElementById(id).style;\n"
- + "if ('block' == style.display) {\n"
- + "style.display = 'none';\n"
- + "document.getElementById(id+'_collapsed').style.display =
'inline';\n"
- + "document.getElementById(id+'_expanded').style.display =
'none';\n"
- + "} else {\n"
- + "style.display = 'block';\n"
- + "document.getElementById(id+'_collapsed').style.display =
'none';\n"
- + "document.getElementById(id+'_expanded').style.display =
'inline';\n"
- + "}\n" + "}\n\n" +
-
- "</script>");
- }
-
- /**
- * @param out
- */
- private void writeStyleSheet(PrintWriter out) {
- out
- .println("<style type=\'text/css\' >\n" +
- "div.a4j_debug, .a4j_debug span, .a4j_debug td, .a4j_debug th, .a4j_debug
caption { font-family: Verdana, Arial, Sans-Serif; }\n" +
- ".a4j_debug li{\n" +
- " list-style-position : inside;\n" +
- "}\n" +
- "\n" +
- ".a4j_debug li, .a4j_debug pre { padding: 0; margin: 0; font-size :
12px;}\n" +
- ".a4j_debug ul { padding: 0 0 10 0; margin: 0; font-size : 12px;}\n" +
- ".a4j_debug h1 { color: #fff; background-color : #a00; font-size : 17px;
padding : 7px 10px 10px 10px}\n" +
- "h2.a4j_debug , h2.a4j_debug span { color: #a00; font-size : 17px; padding :
0px 0px 0px 10px;}\n" +
- "h2.a4j_debug a { text-decoration: none; color: #a00; }\n" +
- ".exception { color: #000; font-size : 14px; padding : 0px 0px 0px
10px;}\n" +
- ".grayBox { padding: 8px; margin: 10px 0; border: 1px solid #CCC;
background-color: #f9f9f9; font-size : 12px; }\n" +
- "#error { color: #900; font-weight: bold; font-size: medium; }\n" +
- "#trace, #tree, #vars { display: none; }\n" +
- ".a4j_debug code { font-size: medium; font-size : 14px;}\n" +
- "#tree dl { color: #666; }\n" +
- "#tree dd { font-size : 12px;}\n" +
- "#tree dt { border: 1px solid #DDD; padding: 2px 4px 4px 4px; border-left: 2px
solid #a00; font-family: \"Courier New\", Courier, mono; font-size: small;
font-size : 12px; margin-top: 2px; margin-bottom: 2px;}\n" +
- ".uicText { color: #999; }\n" +
- ".a4j_debug table { border: 1px solid #CCC; border-collapse: collapse;
border-spacing: 0px; width: 100%; text-align: left; }\n" +
- ".a4j_debug td { border: 1px solid #CCC; font-size : 12px; vertical-align :
top}\n" +
- ".a4j_debug thead tr th { padding: 2px; color: #030; background-color:
#F9F9F9; font-size : 12px;}\n" +
- ".a4j_debug tbody tr td { padding: 10px 6px; }\n" +
- ".a4j_debug table caption { text-align: left; padding: 20 0 5 0; font-size :
12px; font-weight : bold;}\n" +
- ".value {font-size : 12px; font-weight : bold;}\n" +
- "div.log { width: 100%; height: 400px;}\n" +
- "iframe.log { width: 99%; height: 99%; border: 1px solid #CCC;}\n" +
- "</style>");
- }
-
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/FacesErrorStateHolder.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/FacesErrorStateHolder.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/FacesErrorStateHolder.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,44 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework;
-
-import javax.faces.component.UIViewRoot;
-
-/**
- * Hold detailed faces state for Error output.
- * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:11 $
- *
- */
-public interface FacesErrorStateHolder {
-
- /**
- * @return detailed message about faces state on error in Html format
- */
- public String getFacesErrorStateMessage();
-
- /**
- * @return faces view tree at error point.
- */
- public UIViewRoot getFacesView();
-
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxContextImpl.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxContextImpl.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxContextImpl.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,758 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework.ajax;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import javax.faces.FacesException;
-import javax.faces.FactoryFinder;
-import javax.faces.application.Application;
-import javax.faces.application.StateManager;
-import javax.faces.application.ViewHandler;
-import javax.faces.application.StateManager.SerializedView;
-import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.render.RenderKit;
-import javax.faces.render.RenderKitFactory;
-import javax.faces.render.Renderer;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.component.AjaxContainer;
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.context.ViewIdHolder;
-import org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter;
-import org.ajax4jsf.framework.ajax.xmlfilter.FilterServletResponseWrapper;
-import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
-import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
-import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
-import org.ajax4jsf.renderkit.HeaderResourceProducer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.richfaces.skin.Skin;
-import org.richfaces.skin.SkinFactory;
-import org.richfaces.skin.SkinNotFoundException;
-
-/**
- * This class incapsulated
- *
- * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.7 $ $Date: 2007/02/08 19:07:16 $
- *
- */
-public class AjaxContextImpl extends AjaxContext {
- public static final String RESOURCES_PROCESSED =
"org.ajax4jsf.framework.HEADER_PROCESSED";
-
- private static final Log log = LogFactory.getLog(AjaxContext.class);
-
- private static ComponentInvoker invoker;
-
- private static Map contextClasses = new HashMap();
-
- Set ajaxAreasToRender = new HashSet();
-
- Set ajaxRenderedAreas = new HashSet();
-
- boolean ajaxRequest = false;
-
- boolean ajaxRequestSet = false;
-
- boolean selfRender = false;
-
- Integer viewSequence = new Integer(1);
-
- String submittedRegionClientId = null;
-
- boolean submittedRegionSet = false;
-
- ViewIdHolder viewIdHolder = null;
-
- Map responseDataMap = new HashMap();
-
- Map commonAjaxParameters = new HashMap();
-
- static {
- try {
- // Attempt to create JSF1.2 specific invoker.
- invoker = new JsfOneOneInvoker();
- } catch (Exception e) {
- invoker = new JsfOneOneInvoker();
- }
- }
-
- /**
- * @param root
- * @param context
- * @param callback
- * @param regionId
- * @return
- * @see
org.ajax4jsf.framework.ajax.JsfOneOneInvoker#invokeOnComponent(javax.faces.component.UIComponent,
- * javax.faces.context.FacesContext,
- * org.ajax4jsf.framework.ajax.InvokerCallback, java.lang.String)
- */
- public static boolean invokeOnComponent(UIComponent root,
- FacesContext context, InvokerCallback callback, String regionId) {
- return invoker.invokeOnComponent(root, context, callback, regionId);
- }
-
- /**
- * @param viewRoot
- * @param context
- * @param callback
- * @see
org.ajax4jsf.framework.ajax.JsfOneOneInvoker#invokeOnRegionOrRoot(org.ajax4jsf.framework.ajax.AjaxViewRoot,
- * javax.faces.context.FacesContext,
- * org.ajax4jsf.framework.ajax.InvokerCallback)
- */
- public static void invokeOnRegionOrRoot(AjaxViewRoot viewRoot,
- FacesContext context, InvokerCallback callback) {
- invoker.invokeOnRegionOrRoot(viewRoot, context, callback);
- }
-
- private InvokerCallback _ajaxInvoker = new InvokerCallback() {
-
- public void invoke(FacesContext context, UIComponent component) {
- if (component instanceof AjaxContainer) {
- AjaxContainer ajax = (AjaxContainer) component;
- renderAjaxRegion(context, component, true);
- } else {
- // Container not found, use Root for encode.
- renderAjaxRegion(context, context.getViewRoot(), true);
- }
- }
-
- public void invokeRoot(FacesContext context) {
- renderAjaxRegion(context, context.getViewRoot(), true);
- }
-
- };
-
- public void renderSubmittedAjaxRegion(FacesContext context) {
- renderSubmittedAjaxRegion(context, true);
- }
-
- public void renderSubmittedAjaxRegion(FacesContext context,
- final boolean useFilterWriter) {
- InvokerCallback ajaxInvoker = new InvokerCallback() {
-
- public void invoke(FacesContext context, UIComponent component) {
- if (component instanceof AjaxContainer) {
- renderAjaxRegion(context, component, useFilterWriter);
- } else {
- // Container not found, use Root for encode.
- renderAjaxRegion(context, context.getViewRoot(),
- useFilterWriter);
- }
- }
-
- public void invokeRoot(FacesContext context) {
- renderAjaxRegion(context, context.getViewRoot(),
- useFilterWriter);
- }
-
- };
- if (!invokeOnComponent(context.getViewRoot(), context, ajaxInvoker,
- getSubmittedRegionClientId(context))) {
- renderAjaxRegion(context, context.getViewRoot(), useFilterWriter);
- }
-
- }
-
- /**
- * @param context
- * @param useFilterWriter
- * TODO
- * @throws AbortProcessingException
- */
- public void renderAjaxRegion(FacesContext context, UIComponent component,
- boolean useFilterWriter) throws FacesException {
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.RENDER_AJAX_REQUEST,
- component.getId()));
- }
- try {
- setSelfRender(true);
- // create response writer.
- ExternalContext extContext = context.getExternalContext();
- RenderKit renderKit = context.getRenderKit();
- String encoding;
- // Depends if we talk about servlets, portlets, ...
- if (extContext.getRequest() instanceof ServletRequest) {
- ServletRequest request = (ServletRequest) extContext
- .getRequest();
- ServletResponse response = (ServletResponse) extContext
- .getResponse();
- // HACK - bypass MyFaces ( and other ) extensions filter.
-
- // Setup encoding and content type
- String contentType = "text/xml";
- // get the encoding - must be setup by faces context or filter.
- encoding = request.getCharacterEncoding();
- if (encoding == null) {
- encoding = "UTF-8";
- }
- response.setContentType(contentType + ";charset=" + encoding);
- } else
- encoding = "UTF-8";
-
- PrintWriter servletWriter;
- if (useFilterWriter
- && extContext.getRequestMap().containsKey(
- BaseFilter.RESPONSE_WRAPPER_ATTRIBUTE)) {
- // HACK - Special case for MyFaces, since <f:view don't call
- // encode methods,
- // encode response as for self-rendered region directly to
- // filter response wrpper.
- // to avoid exceptions, inform wrapper to ignore illegal states
- // for getWriter/Stream.
- ServletResponse servletResponse = (ServletResponse) extContext
- .getRequestMap().get(
- BaseFilter.RESPONSE_WRAPPER_ATTRIBUTE);
- servletResponse.resetBuffer();
- servletWriter = servletResponse.getWriter();
- ((FilterServletResponseWrapper) servletResponse)
- .setUseNullStream(true);
- } else {
- servletWriter = getWriter(extContext);
- }
- ResponseWriter writer = renderKit.createResponseWriter(
- servletWriter, null, encoding);
- context.setResponseWriter(writer);
- // make response
- writer.startDocument();
- encodeAjaxBegin(context, component);
- component.encodeBegin(context);
- ((AjaxContainer) component).encodeAjax(context);
- component.encodeEnd(context);
- saveViewState(context);
- encodeAjaxEnd(context, component);
- writer.endDocument();
- writer.flush();
- writer.close();
- servletWriter.close();
- // Save tree state.
- } catch (IOException e) {
- throw new FacesException(Messages.getMessage(
- Messages.RENDERING_AJAX_REGION_ERROR, component
- .getClientId(context)), e);
- } finally {
- context.responseComplete();
- // component.setRendererType(defaultRenderer);
- }
- }
-
- /**
- * Encode declaration for AJAX response. Render
<html><body>
- *
- * @param context
- * @param component
- * @throws IOException
- */
- public void encodeAjaxBegin(FacesContext context, UIComponent component)
- throws IOException {
- // AjaxContainer ajax = (AjaxContainer) component;
- ResponseWriter out = context.getResponseWriter();
- // DebugUtils.traceView("ViewRoot in AJAX Page encode begin");
- out.startElement(HTML.HTML_ELEMENT, component);
- // TODO - html attributes. lang - from current locale ?
- Locale locale = context.getViewRoot().getLocale();
- out.writeAttribute(HTML.lang_ATTRIBUTE, locale.toString(), "lang");
- out.startElement(HTML.BODY_ELEMENT, component);
- }
-
- /**
- * End encoding of AJAX response. Render tag with included areas and
- * close </body></html>
- *
- * @param context
- * @param component
- * @throws IOException
- */
- public void encodeAjaxEnd(FacesContext context, UIComponent component)
- throws IOException {
- // AjaxContainer ajax = (AjaxContainer) component;
- ResponseWriter out = context.getResponseWriter();
- // DebugUtils.traceView("ViewRoot in AJAX Page encode begin");
- out.endElement(HTML.BODY_ELEMENT);
- out.endElement(HTML.HTML_ELEMENT);
- }
-
- /**
- * @param context
- * @param root
- * @throws FacesException
- */
- public void processHeadResources(FacesContext context)
- throws FacesException {
- ExternalContext externalContext = context.getExternalContext();
- Map requestMap = externalContext.getRequestMap();
- if (!Boolean.TRUE.equals(requestMap.get(RESOURCES_PROCESSED))) {
- if (null != requestMap.get(BaseFilter.RESPONSE_WRAPPER_ATTRIBUTE)) {
- if (log.isDebugEnabled()) {
- log
- .debug("Process component tree for collect used scripts and styles");
- }
- UIViewRoot root = context.getViewRoot();
- Set scripts = new LinkedHashSet();
- Set styles = new LinkedHashSet();
- RenderKitFactory rkFactory = (RenderKitFactory) FactoryFinder
- .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- RenderKit renderKit = rkFactory.getRenderKit(context, context
- .getViewRoot().getRenderKitId());
- processHeadResources(context, root, scripts, styles, renderKit);
- if (scripts.size() > 0) {
- if (log.isDebugEnabled()) {
- StringBuffer buff = new StringBuffer(
- "Scripts for insert into head : \n");
- for (Iterator iter = scripts.iterator(); iter.hasNext();) {
- String script = (String) iter.next();
- buff.append(script).append("\n");
- }
- log.debug(buff.toString());
- }
- requestMap.put(SCRIPTS_PARAMETER, scripts);
- }
- // Set default style sheet for current skin.
- String styleSheetUri = null;
- try {
- styleSheetUri = (String) SkinFactory.getInstance().getSkin(
- context).getParameter(context,
- Skin.generalStyleSheet);
- } catch (SkinNotFoundException e) {
- log.warn("Current Skin is not found", e);
- }
- if (null != styleSheetUri) {
- String resourceURL = context.getApplication()
- .getViewHandler().getResourceURL(context,
- styleSheetUri);
- // TODO - some resources can be non-session aware, we
- // must
- // skip encoding for this case ?
- // But, in common case - static links not need session
- // info,
- // and dynamic resources perform encodings if nessesary
- // resourceURL =
- // context.getExternalContext().encodeResourceURL(resourceURL);
- styles.add(resourceURL);
- }
- if (styles.size() > 0) {
- if (log.isDebugEnabled()) {
- StringBuffer buff = new StringBuffer(
- "Styles for insert into head : \n");
- for (Iterator iter = styles.iterator(); iter.hasNext();) {
- String style = (String) iter.next();
- buff.append(style).append("\n");
- }
- log.debug(buff.toString());
- }
- requestMap.put(STYLES_PARAMETER, styles);
- }
- // Mark as processed.
- requestMap.put(RESOURCES_PROCESSED, Boolean.TRUE);
- }
-
- }
- }
-
- /**
- * Append nessesary scripts and styles from component ( if renderer
- * implements {@link HeaderResourceProducer}) and recursive process all
- * facets and childrens.
- *
- * @param context
- * TODO
- * @param root
- * @param scripts
- * @param styles
- * @param renderKit
- * TODO
- */
- private void processHeadResources(FacesContext context, UIComponent root,
- Set scripts, Set styles, RenderKit renderKit) {
- Renderer renderer = getRenderer(context, root, renderKit);
- if (null != renderer) {
- if (renderer instanceof HeaderResourceProducer) {
- HeaderResourceProducer producer = (HeaderResourceProducer) renderer;
- Set set = producer.getHeaderScripts(context, root);
- if (null != set) {
- scripts.addAll(set);
- }
- set = producer.getHeaderStyles(context, root);
- if (null != set) {
- styles.addAll(set);
- }
- }
- }
- for (Iterator iter = root.getFacets().values().iterator(); iter
- .hasNext();) {
- UIComponent child = (UIComponent) iter.next();
- processHeadResources(context, child, scripts, styles, renderKit);
- }
- for (Iterator iter = root.getChildren().iterator(); iter.hasNext();) {
- UIComponent child = (UIComponent) iter.next();
- processHeadResources(context, child, scripts, styles, renderKit);
- }
- }
-
- /**
- * Find renderer for given component.
- *
- * @param context
- * @param comp
- * @param renderKit
- * @return
- */
- private Renderer getRenderer(FacesContext context, UIComponent comp,
- RenderKit renderKit) {
-
- String rendererType = comp.getRendererType();
- if (rendererType != null) {
- return (renderKit.getRenderer(comp.getFamily(), rendererType));
- } else {
- return (null);
- }
-
- }
-
- public void saveViewState(FacesContext context) throws IOException {
- // TODO - for facelets environment, we need to remove transient
- // components.
- try {
- Application.class.getMethod("getExpressionFactory", null);
- } catch (NoSuchMethodException e) {
- // JSF 1.1 !
- }
- ResponseWriter writer = context.getResponseWriter();
- StateManager stateManager = context.getApplication().getStateManager();
- SerializedView serializedView = stateManager
- .saveSerializedView(context);
- if (null != serializedView) {
- StringWriter bufWriter = new StringWriter();
- ResponseWriter cloneWithWriter = writer.cloneWithWriter(bufWriter);
- context.setResponseWriter(cloneWithWriter);
- stateManager.writeState(context, serializedView);
- cloneWithWriter.flush();
- if (bufWriter.getBuffer().length() > 0) {
- context.getExternalContext().getRequestMap().put(
- AjaxViewHandler.SERIALIZED_STATE_KEY,
- bufWriter.toString());
- }
- // Restore original writer.
- context.setResponseWriter(writer);
- }
- }
-
- /**
- * @return Returns the ajaxRequest.
- */
- public boolean isAjaxRequest() {
- return isAjaxRequest(FacesContext.getCurrentInstance());
- }
-
- /**
- * @return Returns the ajaxRequest.
- */
- public boolean isAjaxRequest(FacesContext context) {
- if (!this.ajaxRequestSet) {
- ajaxRequest = null != getSubmittedRegionClientId(context);
- ajaxRequestSet = true;
- }
- return ajaxRequest;
- }
-
- /**
- * @param ajaxRequest
- * The ajaxRequest to set.
- */
- public void setAjaxRequest(boolean ajaxRequest) {
- this.ajaxRequest = ajaxRequest;
- this.ajaxRequestSet = true;
- }
-
- /**
- * @return Returns the ajaxAreasToRender.
- */
- public Set getAjaxAreasToRender() {
- return this.ajaxAreasToRender;
- }
-
- /**
- * Add affected regions's ID to ajaxView component.
- *
- * @param component
- */
- public void addRegionsFromComponent(UIComponent component) {
- // First step - find parent ajax view
- Set ajaxRegions = AjaxRendererUtils.getAjaxAreas(component);
- // if (ajaxRegions == null){
- // FacesContext context = FacesContext.getCurrentInstance();
- // ajaxRegions = AjaxRendererUtils.getAbsoluteId(context,component);
- // }
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.INVOKE_AJAX_REGION_LISTENER,
- component.getId()));
- }
- if (ajaxRegions != null) {
- for (Iterator iter = ajaxRegions.iterator(); iter.hasNext();) {
- String id = iter.next().toString();
- ajaxAreasToRender.add(convertId(component, id));
- }
- }
- }
-
- public void addComponentToAjaxRender(UIComponent component) {
- this.ajaxAreasToRender.add(AjaxRendererUtils.getAbsoluteId(component));
- }
-
- public void addComponentToAjaxRender(UIComponent base, String id) {
- this.ajaxAreasToRender.add(convertId(base, id));
- }
-
- /**
- * Test for relative id of target components. Attempt convert to
- * absolute. For use as argument for
- * {@link UIComponent#findComponent(java.lang.String)}
- *
- * @param component
- * @param id
- * @return
- */
- private String convertId(UIComponent component, String id) {
- if (id.charAt(0) == NamingContainer.SEPARATOR_CHAR) {
- return id;
- }
- if (null == component) {
- throw new NullPointerException(
- "Base component for search re-rendered compnnent is null");
- }
- UIComponent target = null;
- UIComponent parent = component;
- UIComponent root = component;
- while (null == target && null != parent) {
- target = parent.findComponent(id);
- root = parent;
- parent = parent.getParent();
- }
- if (null == target) {
- target = findUIComponentBelow(root, id);
- }
- if (null != target) {
- return AjaxRendererUtils.getAbsoluteId(target);
- }
- log.warn("Target component for id "+id+" not found");
- return id;
- }
-
- private UIComponent findUIComponentBelow(UIComponent root,
- String id) {
-
- UIComponent target = null;
- for (Iterator iter = root.getFacetsAndChildren(); iter.hasNext();) {
- UIComponent child = (UIComponent) iter.next();
- if (child instanceof NamingContainer) {
- try {
- target = child.findComponent(id);
- } catch (IllegalArgumentException iae) {
- continue;
- }
- }
- if (target == null) {
- if (child.getChildCount() > 0) {
- target = findUIComponentBelow(child, id);
- }
- }
-
- if (target != null) {
- break;
- }
-
- }
- return target;
- }
-
- /**
- * @return Returns the ajaxRenderedAreas.
- */
- public Set getAjaxRenderedAreas() {
- return ajaxRenderedAreas;
- }
-
- public void addRenderedArea(String id) {
- ajaxRenderedAreas.add(id);
- }
-
- public boolean removeRenderedArea(String id) {
- return ajaxRenderedAreas.remove(id);
- }
-
- /**
- * @return Returns the submittedClientId.
- */
- public String getSubmittedRegionClientId(FacesContext context) {
- if (!this.submittedRegionSet) {
- this.submittedRegionClientId = (String) context
- .getExternalContext().getRequestParameterMap().get(
- AjaxContainerRenderer.AJAX_PARAMETER_NAME);
- this.submittedRegionSet = true;
- if (!this.ajaxRequestSet) {
- setAjaxRequest(this.submittedRegionClientId != null);
- }
- }
- return this.submittedRegionClientId;
- }
-
- /**
- * @param submittedClientId
- * The submittedClientId to set.
- */
- public void setSubmittedRegionClientId(String submittedClientId) {
- this.submittedRegionClientId = submittedClientId;
- this.submittedRegionSet = true;
- }
-
- /**
- * @return Returns the selfRender.
- */
- public boolean isSelfRender() {
- return selfRender;
- }
-
- /**
- * @param selfRender
- * The selfRender to set.
- */
- public void setSelfRender(boolean selfRender) {
- this.selfRender = selfRender;
- }
-
- /**
- * @return the vievIdHolder
- */
- public ViewIdHolder getViewIdHolder() {
- return viewIdHolder;
- }
-
- /**
- * @param viewIdHolder
- * the vievIdHolder to set
- */
- public void setViewIdHolder(ViewIdHolder viewIdHolder) {
- this.viewIdHolder = viewIdHolder;
- }
-
- /**
- * @return the responseData
- */
- public Object getResponseData() {
- return responseDataMap.get(RESPONSE_DATA_KEY);
- }
-
- /**
- * @param responseData
- * the responseData to set
- */
- public void setResponseData(Object responseData) {
- this.responseDataMap.put(RESPONSE_DATA_KEY, responseData);
- }
-
- /**
- * @return the responseDataMap
- */
- public Map getResponseDataMap() {
- return responseDataMap;
- }
-
- /**
- * Gives back the writer of a Response object.
- *
- * @param extContext
- * The external context.
- * @return The writer of the response.
- * @throws FacesException
- * If the response object has no getWriter() method.
- */
- protected PrintWriter getWriter(ExternalContext extContext)
- throws FacesException {
- PrintWriter writer = null;
- Object response = extContext.getResponse();
- try {
- Method gW = response.getClass()
- .getMethod("getWriter", new Class[0]);
- writer = (PrintWriter) gW.invoke(response, new Object[0]);
- } catch (Exception e) {
- throw new FacesException(e);
- }
- return writer;
- }
-
- public String getAjaxActionURL() {
- return getAjaxActionURL(FacesContext.getCurrentInstance());
- }
-
- public String getAjaxActionURL(FacesContext context) {
- // Check arguments
- if (null == context) {
- throw new NullPointerException(
- "Faces context for build AJAX Action URL is null");
- }
- UIViewRoot viewRoot = context.getViewRoot();
- if (null == viewRoot) {
- throw new NullPointerException(
- "Faces view tree for build AJAX Action URL is null");
- }
- String viewId = viewRoot.getViewId();
- if (null == viewId) {
- throw new NullPointerException(
- "View id for build AJAX Action URL is null");
- }
- if (!viewId.startsWith("/")) {
- throw new IllegalArgumentException(
- "Illegal view Id for build AJAX Action URL: " + viewId);
- }
- ViewHandler viewHandler = context.getApplication().getViewHandler();
- return context.getExternalContext().encodeActionURL(
- viewHandler.getActionURL(context, viewId));
- }
-
- /**
- * @return the commonAjaxParameters
- */
- public Map getCommonAjaxParameters() {
- return commonAjaxParameters;
- }
-
-}
\ No newline at end of file
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxRegionBrige.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxRegionBrige.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxRegionBrige.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,361 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework.ajax;
-
-import javax.faces.application.Application;
-import javax.faces.component.StateHolder;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
-import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
-import javax.faces.el.ValueBinding;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.FacesEvent;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.component.AjaxContainerBase;
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.event.AjaxEvent;
-import org.ajax4jsf.event.AjaxListener;
-import org.ajax4jsf.event.AjaxRenderEvent;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
-/**
- * @author shura
- *
- * Brige design pattern for any UIComponent append support ajax partial rendering. For
AJAX request, apply
- * ActionListeniers, construct list of components for render - by direct setting
- * from Listenier or Components bean methods.
- * For use in concrete component, in constructor must be instantiated to class field as
:
- * private AjaxRegionBrige brige;
- * ....
- * Constructor(){
- * brige = new AjaxRegionBrige(this);
- * }.
- * And delegate all brige public methods.
- * @See <code>AJAXConatiner</code> interface , or from configuration - by
- * <ajax:forupdate>jsp tag's of this or nested components, or from all
- * <code>UIForm</code> components instances with
<code>isSubmitted</code>
- * set to <code>true</code>
- *
- */
-public class AjaxRegionBrige implements AjaxContainerBase, StateHolder{
-
-
- // Private Fields
- private static final Log log = LogFactory.getLog(AjaxRegionBrige.class);
-
- /**
- * Listener for call on Ajax Requests
- */
- private MethodBinding ajaxListener = null;
-
- /**
- * Flag for immediate call listeners
- */
- private boolean immediate = false;
- private boolean immediateSet = false;
-
- private boolean selfRendered = false;
- private boolean selfRenderedSet = false;
-
-
-
- private boolean transientFlag = false;
-
- private UIComponent component ;
-
- private boolean submitted = false;
-
-
- // Interface implementation
-
- /**
- * @param component
- */
- public AjaxRegionBrige(UIComponent component) {
- this.component = component;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.components.custom.ajax.AjaxContainer#getAjaxListener()
- */
- public MethodBinding getAjaxListener() {
- return this.ajaxListener;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
ogr.apache.myfaces.custom.ajax.AjaxContainer#setAjaxListener(javax.faces.el.MethodBinding)
- */
- public void setAjaxListener(MethodBinding ajaxListener) {
- //
- if (log.isDebugEnabled())
- {
- log.debug(Messages.getMessage(Messages.SET_AJAX_LISTENER,
ajaxListener.getExpressionString()));
- }
- this.ajaxListener = ajaxListener;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see ogr.apache.myfaces.custom.ajax.AjaxContainer#isImmediate()
- */
- public boolean isImmediate() {
- if (this.immediateSet) {
- return (this.immediate);
- }
- ValueBinding vb = component.getValueBinding("immediate");
- if (vb != null) {
- return
(Boolean.TRUE.equals(vb.getValue(FacesContext.getCurrentInstance())));
- } else {
- return (this.immediate);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see ogr.apache.myfaces.custom.ajax.AjaxContainer#setImmediate(boolean)
- */
- public void setImmediate(boolean immediate) {
- if (immediate != this.immediate) {
- this.immediate = immediate;
- }
- this.immediateSet = true;
-
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.AjaxContainer#isSelfRendered()
- */
- public boolean isSelfRendered() {
- if (this.selfRenderedSet) {
- return (this.selfRendered);
- }
- ValueBinding vb = component.getValueBinding("selfRendered");
- if (vb != null) {
- return
(Boolean.TRUE.equals(vb.getValue(FacesContext.getCurrentInstance())));
- } else {
- return (this.selfRendered);
- }
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.AjaxContainer#setSelfRendered(boolean)
- */
- public void setSelfRendered(boolean selfRendered) {
- this.selfRendered = selfRendered;
- this.selfRenderedSet = true;
- }
-
- /**
- * @return Returns the submitted.
- */
- public boolean isSubmitted()
- {
- // TODO - more correct check for submitted state
- return this.submitted;
- }
-
- /**
- * @param submitted The submitted to set.
- */
- public void setSubmitted(boolean submitted)
- {
- // Important - decoder must set submitted AFTER setAjaxRequest !!!
- if (log.isDebugEnabled() && submitted && (!isSubmitted())) {
- log.debug(Messages.getMessage(Messages.SUBMITTED_AJAX_REQUEST));
- }
- this.submitted = submitted;
- }
-
- /**
- * <p>
- * In addition to to the default {@link UIComponent#broadcast}processing,
- * pass the {@link AjaxEvent}being broadcast to the method referenced by
- * <code>AjaxListener</code> (if any), and to the default
- * {@link AjaxListener}registered on the {@link Application}.
- * </p>
- *
- * @param event
- * {@link FacesEvent}to be broadcast
- *
- * @exception AbortProcessingException
- * Signal the JavaServer Faces implementation that no further
- * processing on the current event should be performed
- * @exception IllegalArgumentException
- * if the implementation class of this {@link FacesEvent}is
- * not supported by this component
- * @exception NullPointerException
- * if <code>event</code> is
<code>null</code>
- */
- public void broadcast(FacesEvent event) throws AbortProcessingException {
-
- // Perform standard superclass processing
-// component.broadcast(event);
-
- if (event instanceof AjaxEvent) {
- if (log.isDebugEnabled())
- {
- log.debug(Messages.getMessage(Messages.SEND_EVENT_TO_AJAX_LISTENER,
component.getId()));
- }
-
- // Notify the specified action listener method (if any)
- MethodBinding mb = getAjaxListener();
- if (mb != null) {
- FacesContext context = FacesContext.getCurrentInstance();
- mb.invoke(context, new Object[] { event });
- }
- // TODO - perform special rendering, withowt RENDER_VIEW phase.
- if(isSelfRendered()) {
- // queue new event to end of queue to perform child elements
- // events.
- if (log.isDebugEnabled())
- {
- log.debug("Queue AjaxRenderEvent for self-render of AjaxContainer
with Id "
- + component.getId());
- }
- FacesEvent renderEvent = new AjaxRenderEvent(component);
- renderEvent.setPhaseId(event.getPhaseId());
- component.queueEvent(renderEvent);
- }
- }
- if (event instanceof AjaxRenderEvent) {
- FacesContext context = FacesContext.getCurrentInstance();
- AjaxContext.getCurrentInstance(context).renderAjaxRegion(context,
component, false);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext,
- * java.lang.Object)
- */
- public void restoreState(FacesContext context, Object state) {
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.RESTORE_AJAX_COMPONENT_STATE,
component.getId()));
- }
- Object values[] = (Object[]) state;
-// super.restoreState(context, values[0]);
- this.immediate = ((Boolean) values[0]).booleanValue();
- this.immediateSet = ((Boolean) values[1]).booleanValue();
- this.ajaxListener = (MethodBinding) UIComponentBase.restoreAttachedState(context,
values[2]);
- this.selfRendered = ((Boolean) values[3]).booleanValue();
- this.selfRenderedSet = ((Boolean) values[4]).booleanValue();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
- */
- public Object saveState(FacesContext context) {
- //
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.SAVE_AJAX_COMPONENT_STATE,
component.getId()));
- }
- Object[] values = new Object[5];
-// values[0] = super.saveState(context);
- values[0] = Boolean.valueOf(immediate);
- values[1] = Boolean.valueOf(immediateSet);
- values[2] = UIComponentBase.saveAttachedState(context, ajaxListener);
- values[3] = Boolean.valueOf(selfRendered);
- values[4] = Boolean.valueOf(selfRenderedSet);
- return values;
- }
-
-/* public void processDecodes(javax.faces.context.FacesContext context)
- {
- if (context == null) throw new NullPointerException("context");
- // due SUN ri design, clear current sattus.
- if(! component.isRendered()) return;
- if(log.isDebugEnabled()){
- log.debug("Process decodes of AjaxContainer with Id
"+component.getId());
- }
- component.decode(context);
- // If it is AJAX request for different area - skip decoding childs.
- if (isAjaxRequest()&& !isSubmitted()){
- if(log.isDebugEnabled()){
- log.debug("Skip Decoders for childrens of AjaxContainer with Id
"+component.getId());
- }
- return;
- }
- for (Iterator it = component.getFacetsAndChildren(); it.hasNext(); )
- {
- UIComponent childOrFacet = (UIComponent)it.next();
- childOrFacet.processDecodes(context);
- }
- }
-
- public void processValidators(javax.faces.context.FacesContext context)
- {
- if (context == null) throw new NullPointerException("context");
- if(! component.isRendered()) return;
- if (isAjaxRequest()&& !isSubmitted()){
- if(log.isDebugEnabled()){
- log.debug("Skip Validators for childrens of AjaxContainer with Id
"+component.getId());
- }
- return;
- }
-
- for (Iterator it = component.getFacetsAndChildren(); it.hasNext(); )
- {
- UIComponent childOrFacet = (UIComponent)it.next();
- childOrFacet.processValidators(context);
- }
- }
-
- public void processUpdates(javax.faces.context.FacesContext context)
- {
- if (context == null) throw new NullPointerException("context");
- if(! component.isRendered()) return;
- if (isAjaxRequest()&& !isSubmitted()){
- if(log.isDebugEnabled()){
- log.debug("Skip updates for childrens of AjaxContainer with Id
"+component.getId());
- }
- return;
- }
- for (Iterator it = component.getFacetsAndChildren(); it.hasNext(); )
- {
- UIComponent childOrFacet = (UIComponent)it.next();
- childOrFacet.processUpdates(context);
- }
- }
-*/
- public boolean isTransient() {
- return transientFlag;
- }
-
- public void setTransient(boolean transientFlag) {
- this.transientFlag = transientFlag;
- }
-
- }
-
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxStateManager.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxStateManager.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxStateManager.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,102 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework.ajax;
-
-import java.io.IOException;
-
-import javax.faces.application.StateManager;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.framework.renderer.AjaxPhaseListener;
-
-/**
- * @author shura
- *
- */
-public class AjaxStateManager extends StateManager {
-
- private StateManager parent;
-
- /**
- * @param parent
- */
- public AjaxStateManager(StateManager parent) {
- super();
- this.parent = parent;
- }
-
- /* (non-Javadoc)
- * @see
javax.faces.application.StateManager#getComponentStateToSave(javax.faces.context.FacesContext)
- */
- protected Object getComponentStateToSave(FacesContext context) {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see
javax.faces.application.StateManager#getTreeStructureToSave(javax.faces.context.FacesContext)
- */
- protected Object getTreeStructureToSave(FacesContext context) {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see
javax.faces.application.StateManager#restoreComponentState(javax.faces.context.FacesContext,
javax.faces.component.UIViewRoot, java.lang.String)
- */
- protected void restoreComponentState(FacesContext context,
- UIViewRoot viewRoot, String renderKitId) {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see
javax.faces.application.StateManager#restoreTreeStructure(javax.faces.context.FacesContext,
java.lang.String, java.lang.String)
- */
- protected UIViewRoot restoreTreeStructure(FacesContext context,
- String viewId, String renderKitId) {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see
javax.faces.application.StateManager#restoreView(javax.faces.context.FacesContext,
java.lang.String, java.lang.String)
- */
- public UIViewRoot restoreView(FacesContext context, String viewId,
- String renderKitId) {
- return parent.restoreView(context, viewId, renderKitId);
- }
-
- /* (non-Javadoc)
- * @see
javax.faces.application.StateManager#saveSerializedView(javax.faces.context.FacesContext)
- */
- public SerializedView saveSerializedView(FacesContext context) {
- return parent.saveSerializedView(context);
- }
-
- /* (non-Javadoc)
- * @see
javax.faces.application.StateManager#writeState(javax.faces.context.FacesContext,
javax.faces.application.StateManager.SerializedView)
- */
- public void writeState(FacesContext context, SerializedView state)
- throws IOException {
- parent.writeState(context, state);
- context.getExternalContext().getRequestMap().put(AjaxPhaseListener.VIEW_STATE_SAVED_PARAM,
Boolean.TRUE);
- }
-
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxViewHandler.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxViewHandler.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxViewHandler.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,278 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework.ajax;
-
-import java.io.IOException;
-import java.util.Map;
-
-import javax.faces.FacesException;
-import javax.faces.application.ViewHandler;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.servlet.http.HttpServletResponse;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.application.ViewHandlerWrapper;
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.context.ViewIdHolder;
-import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
-import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
-import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
-import org.ajax4jsf.resource.InternetResource;
-import org.ajax4jsf.resource.InternetResourceBuilder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.5 $ $Date: 2007/02/08 15:02:04 $
- *
- */
-public class AjaxViewHandler extends ViewHandlerWrapper {
-
- public static final String STATE_MARKER_KEY = "org.ajax4jsf.view.state";
-
- public static final String SERIALIZED_STATE_KEY =
"org.ajax4jsf.view.serializedstate";
-
- private static final Log _log = LogFactory.getLog(AjaxViewHandler.class);
-
- private static final String REDIRECTED = "org.ajax4jsf.view.REDIRECTED";
-
- /**
- * @param parent
- */
- public AjaxViewHandler(ViewHandler parent) {
- super(parent);
- if (_log.isDebugEnabled()) {
- _log.debug("Create instance of Ajax ViewHandler");
- }
- }
-
- /*
- * (non-Javadoc) For creating ViewRoot by Application Instead of new . Not
- * nessesary for MyFaces ( simple copy from it ) or RI 1.2
- *
- * @see
javax.faces.application.ViewHandler#createView(javax.faces.context.FacesContext,
- * java.lang.String)
- */
- public UIViewRoot createView(FacesContext facesContext, String viewId) {
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
- // Check for simple keep new ViewId in navigation cases.
- ViewIdHolder viewIdHolder = ajaxContext.getViewIdHolder();
- UIViewRoot riRoot;
- if (null != viewIdHolder && viewIdHolder.skipNavigation(viewId)) {
- viewIdHolder.setViewId(viewId);
- riRoot = facesContext.getViewRoot();
- } else {
- UIViewRoot root = super.createView(facesContext, viewId);
- // TODO -setup render-kit where instead of Listener ?
- if (null == root || root instanceof AjaxViewRoot) {
- riRoot = root;
- } else {
- // HACK - since only RI 1.1 use new for create ViewRoot instead
- // of Application.createComponent,
- // we can use it as flag for custom creation.
- riRoot = (UIViewRoot)
facesContext.getApplication().createComponent(UIViewRoot.COMPONENT_TYPE);
- // fill properties from default.
- riRoot.setViewId(root.getViewId());
- riRoot.setLocale(root.getLocale());
- String renderKitId = root.getRenderKitId();
- // Fix facelets bug - for debug requests renderKitId is null !
- if (null == renderKitId) {
- renderKitId = calculateRenderKitId(facesContext);
- }
- riRoot.setRenderKitId(renderKitId);
- }
- if (ajaxContext.isAjaxRequest(facesContext)) {
- // Remove ajax status - for navigation states, full page will be
- // send.
- ajaxContext.setAjaxRequest(false);
- }
- }
- return riRoot;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ViewHandlerWrapper#writeState(javax.faces.context.FacesContext)
- */
- public void writeState(FacesContext context) throws IOException {
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
- if (ajaxContext.isAjaxRequest(context)) {
- // TODO - detect case of JSF 1.1 + JSP. for all other we need own
- // state marker for
- // self-rendered regions only.
- // write marker html element - input field. Will be parsed in filter
- // and
- // replaced with real state.
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement(HTML.SPAN_ELEM, null);
- writer.writeAttribute(HTML.id_ATTRIBUTE, STATE_MARKER_KEY, null);
- writer.writeAttribute(HTML.NAME_ATTRIBUTE, STATE_MARKER_KEY, null);
-// writer.writeAttribute("style", "display:none;", null);
- if (!ajaxContext.isSelfRender()) {
- super.writeState(context);
- }
- writer.endElement(HTML.SPAN_ELEM);
- } else {
- super.writeState(context);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ViewHandlerWrapper#restoreView(javax.faces.context.FacesContext,
- * java.lang.String)
- */
- public UIViewRoot restoreView(FacesContext context, String viewId) {
- UIViewRoot viewRoot = super.restoreView(context, viewId);
- ExternalContext externalContext = context.getExternalContext();
- Map requestParameterMap = externalContext.getRequestParameterMap();
- Map requestMap = externalContext.getRequestMap();
- if (null == viewRoot) {
- if (requestParameterMap
- .containsKey(AjaxContainerRenderer.AJAX_PARAMETER_NAME)
- && !requestMap.containsKey(REDIRECTED)) {
- // New view created for AJAX request - indicate session
- // expiration.
- // We need send special response to client and suggest reload
- // page.
- String actionURL = getActionURL(context, viewId);
- // To avoid double call to redirect, if we have more then one
- // handler in chain.
- requestMap.put(REDIRECTED, Boolean.TRUE);
- if (_log.isDebugEnabled()) {
- _log
- .debug("Detect session expiration in AJAX request - view don't restored,
action URL is "
- + actionURL);
- }
- try {
- Object response = externalContext.getResponse();
- if (response instanceof HttpServletResponse) {
- HttpServletResponse httpResponse = (HttpServletResponse) response;
- // TODO - get locale from request ?
- httpResponse.setHeader("Ajax-Expired", Messages
- .getMessage(Messages.AJAX_VIEW_EXPIRED));
- }
- actionURL = externalContext.encodeActionURL(actionURL);
- externalContext.redirect(actionURL);
- context.responseComplete();
- } catch (IOException e) {
- throw new FacesException(
- "Error on redirect for reload expired page", e);
- }
- }
- }
- return viewRoot;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ViewHandlerWrapper#getResourceURL(javax.faces.context.FacesContext,
- * java.lang.String)
- */
- public String getResourceURL(FacesContext context, String url) {
- String resourceURL;
- if (url.startsWith(InternetResource.RESOURCE_URI_PREFIX)) {
- InternetResource resource = InternetResourceBuilder
- .getInstance()
- .createResource(
- null,
- url
- .substring(InternetResource.RESOURCE_URI_PREFIX_LENGTH));
- resourceURL = resource.getUri(context, null);
- } else {
- resourceURL = super.getResourceURL(context, url);
- }
- return resourceURL;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ViewHandlerWrapper#renderView(javax.faces.context.FacesContext,
- * javax.faces.component.UIViewRoot)
- */
- public void renderView(FacesContext context, UIViewRoot root)
- throws IOException, FacesException {
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
- // Broadcast Ajax events before rendering, to setup areas to update.
- if (root instanceof AjaxViewRoot) {
- AjaxViewRoot ajaxRoot = (AjaxViewRoot) root;
- Map requestMap = context.getExternalContext().getRequestMap();
- // broadcast ajax events before render response.
- if (ajaxContext.isAjaxRequest(context)
- && null == requestMap
- .get(AjaxRendererUtils.AJAX_AREAS_RENDERED)) {
- processAjaxEvents(context, ajaxRoot);
- }
- if (!context.getResponseComplete()) {
- super.renderView(context, root);
- if (ajaxContext.isAjaxRequest(context)
- && null == requestMap
- .get(AjaxRendererUtils.AJAX_AREAS_RENDERED)) {
- // HACK for MyFaces ( <f:view> tag not call renderers )
- if (_log.isDebugEnabled()) {
- _log
- .debug(Messages
- .getMessage(Messages.AJAX_RESPONSE_NOT_RENDERED_INFO));
- }
- ajaxContext.setSelfRender(true);
- //ServletResponse response = (ServletResponse) context
- // .getExternalContext().getResponse();
- Object response = (Object) context
- .getExternalContext().getResponse();
- try {
- response.getClass().getDeclaredMethod("reset",
- new Class[0]).invoke(response, new Object[0]);
- //response.reset();
- } catch (Exception e) {
- // Do nothing - we will use directly and reset
- // wrapper
- }
- ajaxContext.renderSubmittedAjaxRegion(context,true);
- }
- }
- } else {
- super.renderView(context, root);
- }
- ajaxContext.processHeadResources(context);
- }
-
- /**
- * @param context
- * @param ajaxRoot
- */
- private void processAjaxEvents(FacesContext context, AjaxViewRoot ajaxRoot) {
- // First - process reRender from active components.
- if (_log.isDebugEnabled()) {
- _log.debug(Messages.getMessage(Messages.PROCESS_AJAX_EVENTS_INFO));
- }
- ajaxRoot.broadcastAjaxEvents(context);
- }
-
-}
Deleted: trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxViewRoot.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxViewRoot.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/AjaxViewRoot.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,566 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework.ajax;
-
-import java.io.IOException;
-
-import javax.faces.FacesException;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.PhaseId;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.application.AjaxSingleException;
-import org.ajax4jsf.component.AjaxContainer;
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.context.ViewIdHolder;
-import org.ajax4jsf.event.AjaxListener;
-import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
-import org.apache.commons.collections.Buffer;
-import org.apache.commons.collections.BufferUnderflowException;
-import org.apache.commons.collections.UnboundedFifoBuffer;
-
-/**
- * Custom ViewRoot for support render parts of tree for Ajax requests. Main
- * difference from default ViewRoot - store events queue and unique id counter
- * in request-scope variables. In common realisation, store request-scope
- * variables in component produce errors in case of concurrent requests to same
- * view.
- *
- * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.4 $ $Date: 2007/02/28 17:01:01 $
- *
- */
-public class AjaxViewRoot extends UIViewRoot implements AjaxContainer {
-
- public static final String ROOT_ID = "_viewRoot";
-
- private AjaxRegionBrige _brige;
-
- /**
- *
- */
- public AjaxViewRoot() {
- super();
- super.setId(ROOT_ID);
- _brige = new AjaxRegionBrige(this);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.UIComponentBase#getId()
- */
- // public String getId() {
- // return ROOT_ID;
- // }
- public String getRendererType() {
- return (COMPONENT_FAMILY);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#broadcast(javax.faces.event.FacesEvent)
- */
- public void broadcast(FacesEvent event) throws AbortProcessingException {
- super.broadcast(event);
- getBrige().broadcast(event);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#getAjaxListener()
- */
- public MethodBinding getAjaxListener() {
- return getBrige().getAjaxListener();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#isImmediate()
- */
- public boolean isImmediate() {
- return getBrige().isImmediate();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#isSubmitted()
- */
- public boolean isSubmitted() {
- return getBrige().isSubmitted();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.component.UIComponent#queueEvent(javax.faces.event.FacesEvent)
- */
- public void queueEvent(FacesEvent event) {
- if (event == null)
- throw new NullPointerException(Messages
- .getMessage(Messages.NULL_EVENT_SUBMITTED_ERROR));
- if (event.getPhaseId().compareTo(PhaseId.RENDER_RESPONSE) == 0) {
- // HACK - Special case - Ajax Events to RenderResponse phase
- // queue.
- // in future, with JSF 1.2 it must be done by invokeOnComponent
- // method.
- // In 1.1 , events to RENDER_RESPONSE phase not used.
- getAjaxEventsQueue(getFacesContext()).add(event);
- } else {
- getEventsQueue(getFacesContext(), event.getPhaseId()).add(event);
- }
- }
-
- /**
- * Broadcast events for specified Phase
- *
- * @param context
- * @param phaseId -
- * phase, for wich events must be processed.
- */
- void broadcastEvents(FacesContext context, PhaseId phaseId) {
- Buffer[] events = getEvents(context);
- Buffer anyPhaseEvents = events[PhaseId.ANY_PHASE.getOrdinal()];
- Buffer phaseEvents = events[phaseId.getOrdinal()];
- if (phaseEvents.isEmpty() && anyPhaseEvents.isEmpty())
- return;
- // FacesEvent event = null;
- boolean haveAnyPhaseEvents = !anyPhaseEvents.isEmpty();
- boolean havePhaseEvents = !phaseEvents.isEmpty();
- do {
- // ANY_PHASE first
- processEvents(anyPhaseEvents, haveAnyPhaseEvents);
-
- processEvents(phaseEvents, havePhaseEvents);
- // Events can queued in other events processing
- haveAnyPhaseEvents = !anyPhaseEvents.isEmpty();
- havePhaseEvents = !phaseEvents.isEmpty();
- } while (haveAnyPhaseEvents || havePhaseEvents);
- if (context.getRenderResponse() || context.getResponseComplete()) {
- clearEvents(context);
- }
-
- }
-
- /**
- * @param phaseEventsQueue
- * @param havePhaseEvents
- */
- public void processEvents(Buffer phaseEventsQueue, boolean havePhaseEvents) {
- FacesEvent event;
- while (havePhaseEvents) {
- try {
- event = (FacesEvent) phaseEventsQueue.remove();
- UIComponent source = event.getComponent();
- try {
- source.broadcast(event);
- } catch (AbortProcessingException e) {
- // abort event processing
- // Page 3-30 of JSF 1.1 spec: "Throw an
- // AbortProcessingException, to tell the JSF
- // implementation
- // that no further broadcast of this event, or any
- // further
- // events, should take place."
- // clearEvents();
- // return;
- }
- } catch (BufferUnderflowException e) {
- havePhaseEvents = false;
- }
- }
- }
-
- public void broadcastAjaxEvents(FacesContext context) {
- Buffer queue = getAjaxEventsQueue(context);
- processEvents(queue, !queue.isEmpty());
- }
-
- private Buffer[] events;
-
- private Buffer ajaxEvents = new UnboundedFifoBuffer();
-
- /**
- * Use FIFO buffers for hold Faces Events. Hold this buffers in Request
- * scope parameters for support any concurrent requests for same
- * component tree ( since RI hold component tree in session ).
- *
- * @param context
- * @param phase
- * @return
- */
- protected Buffer getEventsQueue(FacesContext context, PhaseId phase) {
- return getEvents(context)[phase.getOrdinal()];
- }
-
- /**
- * @return
- */
- protected Buffer[] getEvents(FacesContext context) {
- if (events == null) {
- clearEvents(context);
- }
- return events;
- }
-
- /**
- * Special Fifo Buffer for ajax events to Render Responce phase.
- *
- * @param context
- * @return
- */
- protected Buffer getAjaxEventsQueue(FacesContext context) {
-
- return ajaxEvents;
- }
-
- public void clearEvents(FacesContext context) {
- int len;
- events = new Buffer[len = PhaseId.VALUES.size()];
- for (int i = 0; i < len; i++) {
- events[i] = new UnboundedFifoBuffer();
- }
- }
-
- private InvokerCallback _decodeInvoker = new InvokerCallback() {
-
- public void invoke(FacesContext context, UIComponent component) {
- component.processDecodes(context);
- }
-
- public void invokeRoot(FacesContext context) {
- AjaxViewRoot.super.processDecodes(context);
- }
-
- };
-
- private UIComponent singleComponent = null;
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#processDecodes(javax.faces.context.FacesContext)
- */
- public void processDecodes(FacesContext context) {
- if (context == null)
- throw new NullPointerException("context");
- singleComponent = null;
- AjaxContextImpl.invokeOnRegionOrRoot(this, context, _decodeInvoker);
- try {
- broadcastEvents(context, PhaseId.APPLY_REQUEST_VALUES);
- } catch (AjaxSingleException e) {
- singleComponent = e.getComponent();
- }
- }
-
- private InvokerCallback _updatesInvoker = new InvokerCallback() {
-
- public void invoke(FacesContext context, UIComponent component) {
- component.processUpdates(context);
- }
-
- public void invokeRoot(FacesContext context) {
- AjaxViewRoot.super.processUpdates(context);
- }
-
- };
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#processUpdates(javax.faces.context.FacesContext)
- */
- public void processUpdates(FacesContext context) {
- if (context == null)
- throw new NullPointerException("context");
- if (null == singleComponent) {
- AjaxContextImpl.invokeOnRegionOrRoot(this, context, _updatesInvoker);
- } else {
- singleComponent.processUpdates(context);
- }
- broadcastEvents(context, PhaseId.UPDATE_MODEL_VALUES);
- }
-
- private InvokerCallback _validatorsInvoker = new InvokerCallback() {
-
- public void invoke(FacesContext context, UIComponent component) {
- component.processValidators(context);
- }
-
- public void invokeRoot(FacesContext context) {
- AjaxViewRoot.super.processValidators(context);
- }
-
- };
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#processValidators(javax.faces.context.FacesContext)
- */
- public void processValidators(FacesContext context) {
- if (context == null)
- throw new NullPointerException("context");
- if (null == singleComponent) {
- AjaxContextImpl.invokeOnRegionOrRoot(this, context, _validatorsInvoker);
- } else {
- singleComponent.processValidators(context);
- }
- broadcastEvents(context, PhaseId.PROCESS_VALIDATIONS);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.component.UIViewRoot#processApplication(javax.faces.context.FacesContext)
- */
- public void processApplication(FacesContext context) {
- if (context == null)
- throw new NullPointerException("context");
- // UIComponent component = getSubmittedRegion(context);
- // TODO - process JSF 1.2 listeners
- broadcastEvents(context, PhaseId.INVOKE_APPLICATION);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.component.UIViewRoot#encodeBegin(javax.faces.context.FacesContext)
- */
- // public void encodeBegin(FacesContext context) throws IOException {
- // UIComponent submittedComponent = getSubmittedRegion(context);
- // if(null == submittedComponent){
- // super.encodeBegin(context);
- // } else {
- // submittedComponent.encodeBegin(context);
- // }
- // }
- private InvokerCallback _ajaxInvoker = new InvokerCallback() {
-
- public void invoke(FacesContext context, UIComponent component) {
- try {
- if (component instanceof AjaxContainer) {
- AjaxContainer ajax = (AjaxContainer) component;
- ajax.encodeAjax(context);
- } else {
- // Container not found, use Root for encode.
- encodeAjax(context);
- }
- } catch (IOException e) {
- throw new FacesException(e);
- }
- }
-
- public void invokeRoot(FacesContext context) {
- try {
- encodeAjax(context);
- } catch (IOException e) {
- throw new FacesException(e);
- }
- }
-
- };
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.component.UIComponentBase#encodeChildren(javax.faces.context.FacesContext)
- */
- public void encodeChildren(FacesContext context) throws IOException {
- if (!isHavePage()
- && AjaxContext.getCurrentInstance(context).isAjaxRequest(
- context)) {
- AjaxContextImpl.invokeOnRegionOrRoot(this, context, _ajaxInvoker);
- } else {
- super.encodeChildren(context);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.component.UIComponentBase#encodeEnd(javax.faces.context.FacesContext)
- */
- // public void encodeEnd(FacesContext context) throws IOException {
- // UIComponent submittedComponent = getSubmittedRegion(context);
- // if (null == submittedComponent) {
- // super.encodeEnd(context);
- // } else {
- // submittedComponent.encodeEnd(context);
- // }
- // }
- public void restoreState(FacesContext context, Object state) {
- Object[] mystate = (Object[]) state;
- super.restoreState(context, mystate[0]);
- getBrige().restoreState(context, mystate[1]);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#saveState(javax.faces.context.FacesContext)
- */
- public Object saveState(FacesContext context) {
- Object[] state = new Object[2];
- state[0] = super.saveState(context);
- state[1] = getBrige().saveState(context);
- return state;
- }
-
- public String getViewId() {
- ViewIdHolder viewIdHolder = AjaxContext.getCurrentInstance()
- .getViewIdHolder();
- String viewId;
- if (null != viewIdHolder) {
- viewId = viewIdHolder.getViewId();
- } else {
- viewId = super.getViewId();
- }
- return viewId;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.framework.ajax.AjaxViewBrige#setAjaxListener(javax.faces.el.MethodBinding)
- */
- public void setAjaxListener(MethodBinding ajaxListener) {
- getBrige().setAjaxListener(ajaxListener);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#setImmediate(boolean)
- */
- public void setImmediate(boolean immediate) {
- getBrige().setImmediate(immediate);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#setSubmitted(boolean)
- */
- public void setSubmitted(boolean submitted) {
- getBrige().setSubmitted(submitted);
- }
-
- public void addAjaxListener(AjaxListener listener) {
- addFacesListener(listener);
- }
-
- public AjaxListener[] getAjaxListeners() {
- return (AjaxListener[]) getFacesListeners(AjaxListener.class);
- }
-
- public void removeAjaxListener(AjaxListener listener) {
- removeFacesListener(listener);
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#isSelfRendered()
- */
- public boolean isSelfRendered() {
- return false;// _brige.isSelfRendered();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.AjaxViewBrige#setSelfRendered(boolean)
- */
- public void setSelfRendered(boolean selfRendered) {
- // _brige.setSelfRendered(selfRendered);
- }
-
- /**
- * Check for AjaxContainer component in childreh. This is workaround for
- * MyFaces JSP tag implementation, not called any encode... methods in
- * <f:view> tag. If only one AjaxContainer present as children for
- * viewRoot, decoding methods delegated to them.
- *
- * @return Returns the havePage.
- */
- public boolean isHavePage() {
- return (getChildCount() == 1 && getChildren().get(0) instanceof AjaxContainer);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.UIComponentBase#getRendersChildren()
- */
- public boolean getRendersChildren() {
- FacesContext context = FacesContext.getCurrentInstance();
- // For non Ajax request, view root not render children
- if (!AjaxContext.getCurrentInstance(context).isAjaxRequest(context)) {
- return false;
- }
- // Also, if have page component as clild - delegate rendering of
- // children to it.
- if (isHavePage()) {
- return false;
- }
- // Ajax Request. Control all output.
- return true;
- }
-
- public boolean isRenderRegionOnly() {
- // for viewroot it not applicable.
- return false;
- }
-
- public void setRenderRegionOnly(boolean reRenderPage) {
- // TODO Auto-generated method stub
-
- }
-
- public void encodeAjax(FacesContext context) throws IOException {
- String rendererType = getRendererType();
- if (rendererType != null) {
- ((AjaxContainerRenderer) getRenderer(context)).encodeAjax(context,
- this);
- }
-
- }
-
- /**
- * @return the brige
- */
- protected AjaxRegionBrige getBrige() {
- return _brige;
- }
-
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/ComponentInvoker.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/ComponentInvoker.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/ComponentInvoker.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,55 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework.ajax;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-/**
- * Interface for call lifecycle methods on component with known clientId
- * For JSF 1.2 implementation must use invokeOnComponent method, for JSF 1.1 use
- * simple recursion on view tree ( not compatible with UIData components )
- * @author shura
- *
- */
-public interface ComponentInvoker {
-
- /**
- * Invoke method on active AjaxContainer component, or on viewRoot, if none.
- * @param viewRoot
- * @param context
- * @param callback
- */
- public abstract void invokeOnRegionOrRoot(AjaxViewRoot viewRoot,
- FacesContext context, InvokerCallback callback);
-
- /**
- * Recursive call for all children for search component with same clientId as target
region
- * @param viewRoot
- * @param context
- * @param callback
- * @param regionId
- */
- public abstract boolean invokeOnComponent(UIComponent root,
- FacesContext context, InvokerCallback callback, String regionId);
-
-}
\ No newline at end of file
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/EventValueBinding.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/EventValueBinding.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/EventValueBinding.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,208 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework.ajax;
-
-import javax.faces.component.StateHolder;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.el.EvaluationException;
-import javax.faces.el.PropertyNotFoundException;
-import javax.faces.el.ValueBinding;
-
-import org.ajax4jsf.Messages;
-import org.ajax4jsf.component.AjaxComponent;
-import org.ajax4jsf.component.AjaxSupport;
-import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
-
-/**
- * Inner class for build event string for parent component.
- *
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:38 $ Disadvantages -
- * not rebuild event string setted as EL expression. TODO - save
- * expressions for build event string at render phase.
- */
-public class EventValueBinding extends ValueBinding implements StateHolder {
-
- /**
- *
- */
- private static final long serialVersionUID = -6583167387542332290L;
-
- private String _componentId;
-
- /**
- * current update component. transient since saved state as component.
- */
- transient private AjaxSupport _component = null;
-
- /**
- * Default constructor for restoreState.
- */
- public EventValueBinding() {
-
- }
-
- /**
- * Constructor for build from AjaxComponent.
- *
- * @param update
- */
- public EventValueBinding(AjaxSupport update) {
- _component = update;
- // _componentId = string;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.el.ValueBinding#getType(javax.faces.context.FacesContext)
- */
- public Class getType(FacesContext facesContext) throws EvaluationException,
- PropertyNotFoundException {
-
- return String.class;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.el.ValueBinding#getValue(javax.faces.context.FacesContext)
- */
- public Object getValue(FacesContext facesContext)
- throws EvaluationException, PropertyNotFoundException {
- if (((UIComponent) getComponent(facesContext)).isRendered()) {
- return getComponent(facesContext).getEventString();
-
- } else {
- return null;
- }
- }
-
- private AjaxSupport getComponent(FacesContext facesContext)
- throws EvaluationException {
-
- if (_component == null) {
- UIComponent uiComponent = facesContext.getViewRoot().findComponent(
- _componentId);
- if (null != uiComponent && uiComponent instanceof AjaxComponent) {
- _component = (AjaxSupport) uiComponent;
- } else {
- throw new EvaluationException(Messages.getMessage(
- Messages.COMPONENT_NOT_FOUND, _componentId));
- }
-
- }
-
- return _component;
- }
-
- /**
- * @param component
- * the component to set
- */
- public void setComponent(AjaxSupport component) {
- _component = component;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.el.ValueBinding#isReadOnly(javax.faces.context.FacesContext)
- */
- public boolean isReadOnly(FacesContext facesContext)
- throws EvaluationException, PropertyNotFoundException {
- // TODO Auto-generated method stub
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.el.ValueBinding#setValue(javax.faces.context.FacesContext,
- * java.lang.Object)
- */
- public void setValue(FacesContext facesContext, Object value)
- throws EvaluationException, PropertyNotFoundException {
- throw new EvaluationException(Messages
- .getMessage(Messages.EVENT_IS_READ_ONLY));
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
- */
- public Object saveState(FacesContext context) {
- if (null == _component) {
- return _componentId;
- } else {
- return AjaxRendererUtils
- .getAbsoluteId((UIComponent) getComponent(context));
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext,
- * java.lang.Object)
- */
- public void restoreState(FacesContext context, Object state) {
- // TODO Auto-generated method stub
- _componentId = (String) state;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.StateHolder#isTransient()
- */
- public boolean isTransient() {
- // TODO Auto-generated method stub
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.StateHolder#setTransient(boolean)
- */
- public void setTransient(boolean newTransientValue) {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.el.ValueBinding#getExpressionString()
- */
- public String getExpressionString() {
- // FacesContext context = FacesContext.getCurrentInstance();
- // UIComponent component = (UIComponent) getComponent(context);
- // return "#{ajaxSupport["+component.getClientId(context)+"]}";
- return null;
- }
-
-}
\ No newline at end of file
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/InitPhaseListener.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/InitPhaseListener.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/InitPhaseListener.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -34,6 +34,8 @@
import javax.faces.lifecycle.Lifecycle;
import javax.faces.lifecycle.LifecycleFactory;
+import org.ajax4jsf.application.AjaxStateManager;
+import org.ajax4jsf.application.AjaxViewHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/InvokerCallback.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/InvokerCallback.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/InvokerCallback.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,48 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework.ajax;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-/**
- * Callback Interface
- * for invoke lifecycle methods ( processDecodes, processValidators ... encodeEnd ).
- * @author shura
- *
- */
-public interface InvokerCallback {
-
- /**
- * Process method on given component.
- * @param context
- * @param component
- */
- public void invoke(FacesContext context, UIComponent component);
-
- /**
- * Default processing on UIVewRoot
- * @param context
- */
- public void invokeRoot(FacesContext context);
-
-}
Deleted:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/JsfOneOneInvoker.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/JsfOneOneInvoker.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/JsfOneOneInvoker.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -1,89 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - 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.ajax4jsf.framework.ajax;
-
-import java.util.Iterator;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.context.AjaxContext;
-
-/**
- * @author shura
- *
- */
-public class JsfOneOneInvoker implements ComponentInvoker {
-
-
- /**
- *
- */
- public JsfOneOneInvoker() {
- // TODO Auto-generated constructor stub
- }
-
-
- /* (non-Javadoc)
- * @see
org.ajax4jsf.framework.ajax.AjaxInvoker#invokeOnRegionOrRoot(org.ajax4jsf.framework.ajax.AjaxViewRoot,
javax.faces.context.FacesContext, org.ajax4jsf.framework.ajax.InvokerCallback,
javax.faces.event.PhaseId)
- */
- public void invokeOnRegionOrRoot(AjaxViewRoot viewRoot, FacesContext context,
InvokerCallback callback) {
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
- String submittedRegionClientId = ajaxContext.getSubmittedRegionClientId(context);
- if(null == submittedRegionClientId ||
viewRoot.getId().equals(submittedRegionClientId)){
- // This is a not AJAX request, or active region is root.
- callback.invokeRoot(context);
- } else {
- if(!invokeOnComponent(viewRoot, context, callback, submittedRegionClientId)){
- // Region not found - perform default actions.
- // TODO - log errors.
- callback.invokeRoot(context);
- }
- }
-
- }
-
- public void invokeOnRegion(FacesContext context, InvokerCallback callback, String
regionId) {
- UIViewRoot viewRoot = context.getViewRoot();
- invokeOnComponent(viewRoot,context,callback,regionId);
- }
-
-
- /* (non-Javadoc)
- * @see
org.ajax4jsf.framework.ajax.AjaxInvoker#invokeOnComponent(javax.faces.component.UIComponent,
javax.faces.context.FacesContext, org.ajax4jsf.framework.ajax.InvokerCallback,
java.lang.String)
- */
- public boolean invokeOnComponent(UIComponent root, FacesContext context, InvokerCallback
callback, String regionId) {
- if(regionId.equals(root.getClientId(context))){
- callback.invoke(context, root);
- return true;
- }
- for (Iterator iter = root.getFacetsAndChildren(); iter.hasNext();) {
- UIComponent child = (UIComponent) iter.next();
- if(invokeOnComponent(child, context, callback, regionId)){
- return true;
- }
- }
- return false;
- }
-
-}
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseXMLFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseXMLFilter.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/BaseXMLFilter.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -39,8 +39,8 @@
import javax.servlet.http.HttpServletResponse;
import org.ajax4jsf.Messages;
+import org.ajax4jsf.application.AjaxViewHandler;
import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.framework.ajax.AjaxViewHandler;
import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoParser.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoParser.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoParser.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -35,7 +35,7 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import org.ajax4jsf.framework.ajax.AjaxViewHandler;
+import org.ajax4jsf.application.AjaxViewHandler;
import org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser;
import org.ajax4jsf.xml.serializer.Method;
import org.ajax4jsf.xml.serializer.OutputPropertiesFactory;
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/tidy/TidyParser.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/tidy/TidyParser.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/tidy/TidyParser.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -31,7 +31,7 @@
import java.util.Set;
import org.ajax4jsf.Messages;
-import org.ajax4jsf.framework.ajax.AjaxViewHandler;
+import org.ajax4jsf.application.AjaxViewHandler;
import org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser;
import org.ajax4jsf.org.w3c.tidy.Lexer;
import org.ajax4jsf.org.w3c.tidy.Node;
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxRendererUtils.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxRendererUtils.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxRendererUtils.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -48,8 +48,8 @@
import org.ajax4jsf.component.AjaxContainer;
import org.ajax4jsf.component.AjaxLoadBundleComponent;
import org.ajax4jsf.component.AjaxSupport;
+import org.ajax4jsf.component.AjaxViewRoot;
import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.framework.ajax.AjaxViewRoot;
import org.ajax4jsf.framework.ajax.JavaScriptParameter;
import org.ajax4jsf.framework.renderer.RendererUtils.HTML;
import org.ajax4jsf.framework.util.ServicesUtils;
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxViewRootRenderer.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxViewRootRenderer.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxViewRootRenderer.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -21,7 +21,7 @@
package org.ajax4jsf.framework.renderer;
-import org.ajax4jsf.framework.ajax.AjaxViewRoot;
+import org.ajax4jsf.component.AjaxViewRoot;
import org.ajax4jsf.resource.InternetResource;
/**
Modified: trunk/framework/impl/src/main/resources/META-INF/faces-config.xml
===================================================================
--- trunk/framework/impl/src/main/resources/META-INF/faces-config.xml 2007-07-09 19:28:02
UTC (rev 1554)
+++ trunk/framework/impl/src/main/resources/META-INF/faces-config.xml 2007-07-10 00:08:19
UTC (rev 1555)
@@ -7,15 +7,15 @@
<faces-config>
<factory>
<render-kit-factory>org.ajax4jsf.framework.renderer.ChameleonRenderKitFactory</render-kit-factory>
- <lifecycle-factory>org.ajax4jsf.framework.DebugLifecycleFactory</lifecycle-factory>
+ <lifecycle-factory>org.ajax4jsf.application.DebugLifecycleFactory</lifecycle-factory>
</factory>
<application>
<!--
<variable-resolver>org.richfaces.skin.SkinVariableResolver</variable-resolver>
<property-resolver>org.richfaces.skin.SkinPropertyResolver</property-resolver>
-->
- <view-handler>org.ajax4jsf.framework.ajax.AjaxViewHandler</view-handler>
- <state-manager>org.ajax4jsf.framework.ajax.AjaxStateManager</state-manager>
+ <view-handler>org.ajax4jsf.application.AjaxViewHandler</view-handler>
+ <state-manager>org.ajax4jsf.application.AjaxStateManager</state-manager>
</application>
<lifecycle>
<phase-listener>org.ajax4jsf.framework.renderer.AjaxPhaseListener</phase-listener>
@@ -33,13 +33,13 @@
</managed-bean>
<managed-bean>
<managed-bean-name>ajaxContext</managed-bean-name>
-
<managed-bean-class>org.ajax4jsf.framework.ajax.AjaxContextImpl</managed-bean-class>
+
<managed-bean-class>org.ajax4jsf.context.AjaxContextImpl</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<component>
<component-type>javax.faces.ViewRoot</component-type>
-
<component-class>org.ajax4jsf.framework.ajax.AjaxViewRoot</component-class>
+
<component-class>org.ajax4jsf.component.AjaxViewRoot</component-class>
<component-extension>
<component-family>javax.faces.ViewRoot</component-family>
Modified:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
---
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -45,7 +45,7 @@
import javax.servlet.http.HttpServletResponse;
import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.framework.ajax.AjaxContextImpl;
+import org.ajax4jsf.context.AjaxContextImpl;
import org.ajax4jsf.framework.renderer.AjaxViewRootRenderer;
import org.ajax4jsf.framework.renderer.ChameleonRenderKitImpl;
import org.ajax4jsf.framework.skin.SkinBean;
Modified:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractThreadedAjax4JsfTestCase.java
===================================================================
---
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractThreadedAjax4JsfTestCase.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/AbstractThreadedAjax4JsfTestCase.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -27,7 +27,7 @@
import junit.framework.TestResult;
import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.framework.ajax.AjaxContextImpl;
+import org.ajax4jsf.context.AjaxContextImpl;
import org.apache.shale.test.mock.MockFacesContext;
import org.apache.shale.test.mock.MockHttpServletRequest;
import org.apache.shale.test.mock.MockHttpServletResponse;
Modified: trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java 2007-07-09
19:28:02 UTC (rev 1554)
+++ trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockViewHandler.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -26,7 +26,7 @@
import javax.faces.application.ViewHandler;
import javax.faces.context.FacesContext;
-import org.ajax4jsf.framework.ajax.AjaxViewHandler;
+import org.ajax4jsf.application.AjaxViewHandler;
public class MockViewHandler extends AjaxViewHandler {
Modified: trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockViewRoot.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockViewRoot.java 2007-07-09
19:28:02 UTC (rev 1554)
+++ trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockViewRoot.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -24,7 +24,7 @@
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
-import org.ajax4jsf.framework.ajax.AjaxViewRoot;
+import org.ajax4jsf.component.AjaxViewRoot;
import org.apache.commons.collections.Buffer;
/**
Modified: trunk/samples/dragDropDemo/src/main/java/org/richfaces/Bean.java
===================================================================
--- trunk/samples/dragDropDemo/src/main/java/org/richfaces/Bean.java 2007-07-09 19:28:02
UTC (rev 1554)
+++ trunk/samples/dragDropDemo/src/main/java/org/richfaces/Bean.java 2007-07-10 00:08:19
UTC (rev 1555)
@@ -24,10 +24,10 @@
import java.util.ArrayList;
import java.util.List;
-import org.ajax4jsf.dnd.Dropzone;
-import org.ajax4jsf.dnd.event.DragEvent;
-import org.ajax4jsf.dnd.event.DropEvent;
-import org.ajax4jsf.dnd.event.DropListener;
+import org.richfaces.component.Dropzone;
+import org.richfaces.event.DragEvent;
+import org.richfaces.event.DropEvent;
+import org.richfaces.event.DropListener;
/**
* @author $Autor$
Modified:
trunk/samples/suggestionbox-sample/src/main/java/org/richfaces/AjaxListener.java
===================================================================
---
trunk/samples/suggestionbox-sample/src/main/java/org/richfaces/AjaxListener.java 2007-07-09
19:28:02 UTC (rev 1554)
+++
trunk/samples/suggestionbox-sample/src/main/java/org/richfaces/AjaxListener.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -3,7 +3,7 @@
*/
package org.richfaces;
-import org.ajax4jsf.framework.ajax.AjaxEvent;
+import org.ajax4jsf.event.AjaxEvent;
import org.richfaces.component.AjaxSuggestionEvent;
/**
@@ -11,7 +11,7 @@
* created 27.03.2007
*
*/
-public class AjaxListener implements org.ajax4jsf.framework.ajax.AjaxListener {
+public class AjaxListener implements org.ajax4jsf.event.AjaxListener {
/* (non-Javadoc)
* @see
org.ajax4jsf.framework.ajax.AjaxListener#processAjax(org.ajax4jsf.framework.ajax.AjaxEvent)
Copied: trunk/ui/core/src/main/java/org/ajax4jsf/component/EventValueBinding.java (from
rev 1551,
trunk/framework/impl/src/main/java/org/ajax4jsf/framework/ajax/EventValueBinding.java)
===================================================================
--- trunk/ui/core/src/main/java/org/ajax4jsf/component/EventValueBinding.java
(rev 0)
+++ trunk/ui/core/src/main/java/org/ajax4jsf/component/EventValueBinding.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -0,0 +1,208 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.component;
+
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.component.AjaxComponent;
+import org.ajax4jsf.component.AjaxSupport;
+import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
+
+/**
+ * Inner class for build event string for parent component.
+ *
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:38 $ Disadvantages -
+ * not rebuild event string setted as EL expression. TODO - save
+ * expressions for build event string at render phase.
+ */
+public class EventValueBinding extends ValueBinding implements StateHolder {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6583167387542332290L;
+
+ private String _componentId;
+
+ /**
+ * current update component. transient since saved state as component.
+ */
+ transient private AjaxSupport _component = null;
+
+ /**
+ * Default constructor for restoreState.
+ */
+ public EventValueBinding() {
+
+ }
+
+ /**
+ * Constructor for build from AjaxComponent.
+ *
+ * @param update
+ */
+ public EventValueBinding(AjaxSupport update) {
+ _component = update;
+ // _componentId = string;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.el.ValueBinding#getType(javax.faces.context.FacesContext)
+ */
+ public Class getType(FacesContext facesContext) throws EvaluationException,
+ PropertyNotFoundException {
+
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.el.ValueBinding#getValue(javax.faces.context.FacesContext)
+ */
+ public Object getValue(FacesContext facesContext)
+ throws EvaluationException, PropertyNotFoundException {
+ if (((UIComponent) getComponent(facesContext)).isRendered()) {
+ return getComponent(facesContext).getEventString();
+
+ } else {
+ return null;
+ }
+ }
+
+ private AjaxSupport getComponent(FacesContext facesContext)
+ throws EvaluationException {
+
+ if (_component == null) {
+ UIComponent uiComponent = facesContext.getViewRoot().findComponent(
+ _componentId);
+ if (null != uiComponent && uiComponent instanceof AjaxComponent) {
+ _component = (AjaxSupport) uiComponent;
+ } else {
+ throw new EvaluationException(Messages.getMessage(
+ Messages.COMPONENT_NOT_FOUND, _componentId));
+ }
+
+ }
+
+ return _component;
+ }
+
+ /**
+ * @param component
+ * the component to set
+ */
+ public void setComponent(AjaxSupport component) {
+ _component = component;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.el.ValueBinding#isReadOnly(javax.faces.context.FacesContext)
+ */
+ public boolean isReadOnly(FacesContext facesContext)
+ throws EvaluationException, PropertyNotFoundException {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.el.ValueBinding#setValue(javax.faces.context.FacesContext,
+ * java.lang.Object)
+ */
+ public void setValue(FacesContext facesContext, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+ throw new EvaluationException(Messages
+ .getMessage(Messages.EVENT_IS_READ_ONLY));
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
+ */
+ public Object saveState(FacesContext context) {
+ if (null == _component) {
+ return _componentId;
+ } else {
+ return AjaxRendererUtils
+ .getAbsoluteId((UIComponent) getComponent(context));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext,
+ * java.lang.Object)
+ */
+ public void restoreState(FacesContext context, Object state) {
+ // TODO Auto-generated method stub
+ _componentId = (String) state;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.StateHolder#isTransient()
+ */
+ public boolean isTransient() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.StateHolder#setTransient(boolean)
+ */
+ public void setTransient(boolean newTransientValue) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.el.ValueBinding#getExpressionString()
+ */
+ public String getExpressionString() {
+ // FacesContext context = FacesContext.getCurrentInstance();
+ // UIComponent component = (UIComponent) getComponent(context);
+ // return "#{ajaxSupport["+component.getClientId(context)+"]}";
+ return null;
+ }
+
+}
\ No newline at end of file
Modified: trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxRegion.java
===================================================================
--- trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxRegion.java 2007-07-09
19:28:02 UTC (rev 1554)
+++ trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxRegion.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -33,11 +33,9 @@
import javax.faces.event.FacesEvent;
import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.context.AjaxContextImpl;
+import org.ajax4jsf.context.InvokerCallback;
import org.ajax4jsf.event.AjaxListener;
-import org.ajax4jsf.framework.ajax.AjaxContextImpl;
-import org.ajax4jsf.framework.ajax.AjaxRegionBrige;
-import org.ajax4jsf.framework.ajax.AjaxViewRoot;
-import org.ajax4jsf.framework.ajax.InvokerCallback;
import org.ajax4jsf.framework.renderer.AjaxContainerRenderer;
/**
Modified: trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxSupport.java
===================================================================
--- trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxSupport.java 2007-07-09
19:28:02 UTC (rev 1554)
+++ trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxSupport.java 2007-07-10
00:08:19 UTC (rev 1555)
@@ -27,7 +27,6 @@
import javax.faces.el.ValueBinding;
import org.ajax4jsf.Messages;
-import org.ajax4jsf.framework.ajax.EventValueBinding;
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;