JBoss Ajax4JSF SVN: r88 - trunk/test/src/main/java/org/ajax4jsf/tests.
by ajax4jsf-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-14 08:42:04 -0400 (Sat, 14 Apr 2007)
New Revision: 88
Added:
trunk/test/src/main/java/org/ajax4jsf/tests/MockValueBinding.java
Log:
MockValueBinding.java added
Added: trunk/test/src/main/java/org/ajax4jsf/tests/MockValueBinding.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/MockValueBinding.java (rev 0)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/MockValueBinding.java 2007-04-14 12:42:04 UTC (rev 88)
@@ -0,0 +1,74 @@
+/**
+ * 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.tests;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 13.04.2007
+ *
+ */
+public class MockValueBinding extends ValueBinding {
+
+ private Class clazz;
+ private Object value;
+
+ public MockValueBinding(Object value, Class clazz) {
+ super();
+ this.clazz = clazz;
+ this.value = value;
+ }
+
+ public Class getType(FacesContext context) throws EvaluationException,
+ PropertyNotFoundException {
+ return clazz;
+ }
+
+ public Object getValue(FacesContext context) throws EvaluationException,
+ PropertyNotFoundException {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ return value;
+ }
+
+ public boolean isReadOnly(FacesContext context) throws EvaluationException,
+ PropertyNotFoundException {
+ return false;
+ }
+
+ public void setValue(FacesContext context, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+
+ if (context == null) {
+ throw new NullPointerException();
+ }
+
+ this.value = value;
+ }
+
+}
17 years, 8 months
JBoss Ajax4JSF SVN: r87 - trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator.
by ajax4jsf-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-14 07:37:54 -0400 (Sat, 14 Apr 2007)
New Revision: 87
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/TestDataGenerator.java
Log:
TestDataGenerator.java added
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/TestDataGenerator.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/TestDataGenerator.java (rev 0)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/TestDataGenerator.java 2007-04-14 11:37:54 UTC (rev 87)
@@ -0,0 +1,138 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.generator;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ajax4jsf.builder.config.PropertyBean;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 13.04.2007
+ *
+ */
+public class TestDataGenerator {
+
+ private ClassLoader loader;
+ private Logger logger;
+
+ private static Map<String, String> testData = new HashMap<String, String>();
+ static {
+ testData.put(Boolean.TYPE.getName(), "true");
+ testData.put(Character.TYPE.getName(), "'#'");
+ testData.put(Byte.TYPE.getName(), "17");
+ testData.put(Short.TYPE.getName(), "18");
+ testData.put(Integer.TYPE.getName(), "20");
+ testData.put(Long.TYPE.getName(), "26");
+ testData.put(Float.TYPE.getName(), "2.05f");
+ testData.put(Double.TYPE.getName(), "1.34d");
+
+ testData.put(Boolean.class.getName(), "new Boolean(true)");
+ testData.put(Character.class.getName(), "new Character('#')");
+ testData.put(Byte.class.getName(), "new Byte(17)");
+ testData.put(Short.class.getName(), "new Short(18)");
+ testData.put(Integer.class.getName(), "new Integer(20)");
+ testData.put(Long.class.getName(), "new Long(26)");
+ testData.put(Float.class.getName(), "new Float(2.05f)");
+ testData.put(Double.class.getName(), "new Double(1.34d)");
+
+ }
+
+ private static Map<String, String> testData1 = new HashMap<String, String>();
+ static {
+ testData1.put(Boolean.TYPE.getName(), "false");
+ testData1.put(Character.TYPE.getName(), "'*'");
+ testData1.put(Byte.TYPE.getName(), "8");
+ testData1.put(Short.TYPE.getName(), "26");
+ testData1.put(Integer.TYPE.getName(), "15");
+ testData1.put(Long.TYPE.getName(), "13");
+ testData1.put(Float.TYPE.getName(), "1.05f");
+ testData1.put(Double.TYPE.getName(), "1.44d");
+
+ testData1.put(Boolean.class.getName(), "new Boolean(false)");
+ testData1.put(Character.class.getName(), "new Character('*')");
+ testData1.put(Byte.class.getName(), "new Byte(8)");
+ testData1.put(Short.class.getName(), "new Short(26)");
+ testData1.put(Integer.class.getName(), "new Integer(15)");
+ testData1.put(Long.class.getName(), "new Long(13)");
+ testData1.put(Float.class.getName(), "new Float(1.05f)");
+ testData1.put(Double.class.getName(), "new Double(1.44d)");
+
+ }
+
+ private static Map<String, Class> primitiveToWrapper = new HashMap<String, Class>();
+ static {
+ primitiveToWrapper.put(Boolean.TYPE.getName(), Boolean.class);
+ primitiveToWrapper.put(Character.TYPE.getName(), Character.class);
+ primitiveToWrapper.put(Byte.TYPE.getName(), Byte.class);
+ primitiveToWrapper.put(Short.TYPE.getName(), Short.class);
+ primitiveToWrapper.put(Integer.TYPE.getName(), Integer.class);
+ primitiveToWrapper.put(Long.TYPE.getName(), Long.class);
+ primitiveToWrapper.put(Float.TYPE.getName(), Float.class);
+ primitiveToWrapper.put(Double.TYPE.getName(), Double.class);
+ }
+
+ public TestDataGenerator(ClassLoader loader, Logger logger) {
+ super();
+ this.loader = loader;
+ this.logger = logger;
+ }
+
+
+ public String getTestVeClass(PropertyBean propertyBean) {
+ String type = propertyBean.getClassname();
+ Class clazz = primitiveToWrapper.get(propertyBean.getClassname());
+ if (clazz == null) {
+ try {
+ clazz = loader.loadClass(propertyBean.getClassname());
+ } catch (ClassNotFoundException e) {
+ logger.error(e);
+
+ return null;
+ }
+ }
+
+ return clazz.getName();
+ }
+
+ public String getTestVeData(PropertyBean propertyBean) {
+ String veClass = getTestVeClass(propertyBean);
+ if (veClass != null) {
+ return getTestData(propertyBean.getName(), veClass, 0);
+ }
+
+ return "";
+ }
+
+ public String getTestVeData1(PropertyBean propertyBean) {
+ String veClass = getTestVeClass(propertyBean);
+ if (veClass != null) {
+ return getTestData(propertyBean.getName(), veClass, 1);
+ }
+
+ return "";
+ }
+
+ private String getTestData(String propertyName, String className, int number) {
+ String string = number == 0 ? testData.get(className) : testData1.get(className);
+ if (string != null) {
+ return string;
+ }
+
+ if (number == 0) {
+ return "\"" + propertyName + "\"";
+ }
+
+ return "\"" + propertyName + "_" + propertyName + "\"";
+ }
+
+ public String getTestData(PropertyBean propertyBean) {
+ return getTestData(propertyBean.getName(), propertyBean.getClassname(), 0);
+ }
+
+ public String getTestData1(PropertyBean propertyBean) {
+ return getTestData(propertyBean.getName(), propertyBean.getClassname(), 1);
+ }
+}
17 years, 8 months
JBoss Ajax4JSF SVN: r86 - in trunk/a4j-portlet/src: test/java/org/ajax4jsf/portlet and 1 other directories.
by ajax4jsf-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2007-04-13 21:46:02 -0400 (Fri, 13 Apr 2007)
New Revision: 86
Added:
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextAttributesMapTest.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
Modified:
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java
Log:
Continue contexts testing.
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java 2007-04-14 00:39:00 UTC (rev 85)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java 2007-04-14 01:46:02 UTC (rev 86)
@@ -126,11 +126,11 @@
if ((context instanceof PortletContext)
&& (request instanceof PortletRequest)
&& (response instanceof PortletResponse)) {
- externalContext = new PortletContextImpl(context, request, response);
+ externalContext = new PortletContextImpl((PortletContext)context, (PortletRequest)request, (PortletResponse)response);
} else if ((context instanceof ServletContext)
&& (request instanceof HttpServletRequest)
&& (response instanceof HttpServletResponse)) {
- externalContext = new ServletContextImpl(context, request, response);
+ externalContext = new ServletContextImpl((ServletContext)context, (HttpServletRequest)request, (HttpServletResponse)response);
} else {
throw new FacesException(
"Unsupported environment. Only servlet or portlet is allowed");
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-04-14 00:39:00 UTC (rev 85)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-04-14 01:46:02 UTC (rev 86)
@@ -31,7 +31,7 @@
*
*/
public class PortletContextImpl extends AbstractExternalContext {
- public PortletContextImpl(Object context, Object request, Object response) {
+ public PortletContextImpl(PortletContext context, PortletRequest request, PortletResponse response) {
super(context, request, response);
}
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java 2007-04-14 00:39:00 UTC (rev 85)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ServletContextImpl.java 2007-04-14 01:46:02 UTC (rev 86)
@@ -34,7 +34,7 @@
* @param request
* @param response
*/
- public ServletContextImpl(Object context, Object request, Object response) {
+ public ServletContextImpl(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
super(context, request, response);
}
Modified: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java 2007-04-14 00:39:00 UTC (rev 85)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java 2007-04-14 01:46:02 UTC (rev 86)
@@ -4,7 +4,10 @@
package org.ajax4jsf.portlet;
import java.security.Principal;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.portlet.PortalContext;
@@ -19,6 +22,15 @@
*
*/
public class MockPortletRequest implements PortletRequest {
+
+ public static final String PARAMETER_VALUE2 = "value2";
+ public static final String PARAMETER_VALUE1 = "value1";
+ public static final String PARAMETER = "paremeter";
+ public Map parameters = new HashMap();
+
+ public MockPortletRequest() {
+ parameters.put(PARAMETER, new String[]{PARAMETER_VALUE1,PARAMETER_VALUE2});
+ }
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#getAttribute(java.lang.String)
*/
@@ -67,36 +79,38 @@
return null;
}
+
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#getParameter(java.lang.String)
*/
- public String getParameter(String arg0) {
- // TODO Auto-generated method stub
- return null;
+ public String getParameter(String name) {
+ String result = null;
+ String[] vals = (String[]) parameters.get(name);
+ if(null != vals){
+ result = vals[0];
+ }
+ return result;
}
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#getParameterMap()
*/
public Map getParameterMap() {
- // TODO Auto-generated method stub
- return null;
+ return parameters;
}
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#getParameterNames()
*/
public Enumeration getParameterNames() {
- // TODO Auto-generated method stub
- return null;
+ return Collections.enumeration(Collections.singleton(PARAMETER));
}
/* (non-Javadoc)
* @see javax.portlet.PortletRequest#getParameterValues(java.lang.String)
*/
public String[] getParameterValues(String arg0) {
- // TODO Auto-generated method stub
- return null;
+ return (String[]) parameters.get(arg0);
}
/* (non-Javadoc)
Added: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextAttributesMapTest.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextAttributesMapTest.java (rev 0)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextAttributesMapTest.java 2007-04-14 01:46:02 UTC (rev 86)
@@ -0,0 +1,100 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.context;
+
+import java.util.HashMap;
+import java.util.Map;
+import junit.framework.TestCase;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ContextAttributesMapTest extends TestCase {
+
+ private Map backend = new HashMap();
+ /**
+ * @param name
+ */
+ public ContextAttributesMapTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.ContextAttributesMap#remove(java.lang.Object)}.
+ */
+ public final void testRemoveObject() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.ContextAttributesMap#get(java.lang.Object)}.
+ */
+ public final void testGetObject() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.ContextAttributesMap#put(java.lang.Object, java.lang.Object)}.
+ */
+ public final void testPutObjectObject() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.ContextMap#clear()}.
+ */
+ public final void testClear() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.ContextMap#entrySet()}.
+ */
+ public final void testEntrySet() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.ContextMap#keySet()}.
+ */
+ public final void testKeySet() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.ContextMap#values()}.
+ */
+ public final void testValues() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link java.util.AbstractMap#containsValue(java.lang.Object)}.
+ */
+ public final void testContainsValue() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link java.util.AbstractMap#containsKey(java.lang.Object)}.
+ */
+ public final void testContainsKey() {
+ fail("Not yet implemented");
+ }
+}
Modified: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java 2007-04-14 00:39:00 UTC (rev 85)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java 2007-04-14 01:46:02 UTC (rev 86)
@@ -3,7 +3,10 @@
*/
package org.ajax4jsf.portlet.context;
+import java.util.Iterator;
import javax.el.ELContext;
+import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
@@ -12,6 +15,7 @@
*
*/
public class FacesContextImplTest extends AbstractAjax4JsfTestCase {
+ private static final String ID0 = "_id0";
protected FacesContextImpl portalFacesContext;
protected ServletContextImpl servletContextImpl;
@@ -86,41 +90,65 @@
* Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getApplication()}.
*/
public void testGetApplication() {
- fail("Not yet implemented");
+ assertSame(application,portalFacesContext.getApplication());
}
/**
* Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getClientIdsWithMessages()}.
*/
public void testGetClientIdsWithMessages() {
- fail("Not yet implemented");
+ portalFacesContext.addMessage(ID0, new FacesMessage());
+ Iterator clientIdsWithMessages = portalFacesContext.getClientIdsWithMessages();
+ assertTrue(clientIdsWithMessages.hasNext());
+ assertEquals(ID0, clientIdsWithMessages.next());
+ assertFalse(clientIdsWithMessages.hasNext());
}
/**
* Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getMaximumSeverity()}.
*/
public void testGetMaximumSeverity() {
- fail("Not yet implemented");
+ assertNull(portalFacesContext.getMaximumSeverity());
+ portalFacesContext.addMessage(ID0, new FacesMessage());
+ Severity maximumSeverity = portalFacesContext.getMaximumSeverity();
+ assertEquals(0,maximumSeverity.compareTo(FacesMessage.SEVERITY_INFO));
+ portalFacesContext.addMessage("_id1", new FacesMessage(FacesMessage.SEVERITY_ERROR,"error","error detail"));
+ maximumSeverity = portalFacesContext.getMaximumSeverity();
+ assertEquals(0,maximumSeverity.compareTo(FacesMessage.SEVERITY_ERROR));
}
/**
* Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getMessages()}.
*/
public void testGetMessages() {
- fail("Not yet implemented");
+ FacesMessage facesMessage = new FacesMessage();
+ portalFacesContext.addMessage(ID0, facesMessage);
+ Iterator messages = portalFacesContext.getMessages();
+ assertTrue(messages.hasNext());
+ assertSame(facesMessage, messages.next());
+ assertFalse(messages.hasNext());
}
/**
* Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getMessages(java.lang.String)}.
*/
public void testGetMessagesString() {
- fail("Not yet implemented");
+ FacesMessage facesMessage = new FacesMessage();
+ portalFacesContext.addMessage(ID0, facesMessage);
+ portalFacesContext.addMessage("_id1", new FacesMessage());
+ Iterator messages = portalFacesContext.getMessages(ID0);
+ assertTrue(messages.hasNext());
+ assertSame(facesMessage, messages.next());
+ assertFalse(messages.hasNext());
}
/**
* Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getRenderKit()}.
*/
public void testGetRenderKit() {
- fail("Not yet implemented");
+ portalFacesContext.setViewRoot(null);
+ assertNull(portalFacesContext.getRenderKit());
+ portalFacesContext.setViewRoot(facesContext.getViewRoot());
+ assertSame(renderKit, portalFacesContext.getRenderKit());
}
}
Added: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java (rev 0)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/PortletExternalContextTest.java 2007-04-14 01:46:02 UTC (rev 86)
@@ -0,0 +1,159 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.context;
+
+import javax.portlet.PortletResponse;
+import org.ajax4jsf.portlet.MockActionRequest;
+import org.ajax4jsf.portlet.MockActionResponse;
+import org.ajax4jsf.portlet.MockPortletContext;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class PortletExternalContextTest extends AbstractAjax4JsfTestCase {
+ private PortletContextImpl portletContextImpl;
+ private FacesContextImpl portalFacesContext;
+ private MockPortletContext portletContext;
+ private MockActionRequest portletRequest;
+ private MockActionResponse portletResponse;
+
+ /**
+ * @param arg0
+ */
+ public PortletExternalContextTest(String arg0) {
+ super(arg0);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ portletContext=new MockPortletContext();
+ portletRequest = new MockActionRequest();
+ portletResponse = new MockActionResponse();
+ portletContextImpl = new PortletContextImpl(portletContext,portletRequest,portletResponse);
+ portalFacesContext = new FacesContextImpl(portletContextImpl,lifecycle);
+ portalFacesContext.setViewRoot(facesContext.getViewRoot());
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ portletContextImpl = null;
+ portalFacesContext = null;
+ portletContext = null;
+ portletRequest = null;
+ portletResponse = null;
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.PortletContextImpl#getRequestParameterValuesMap()}.
+ */
+ public final void testGetRequestParameterValuesMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.PortletContextImpl#getInitParameter(java.lang.String)}.
+ */
+ public final void testGetInitParameterString() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.PortletContextImpl#getRequestLocales()}.
+ */
+ public final void testGetRequestLocales() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.PortletContextImpl#getSession(boolean)}.
+ */
+ public final void testGetSessionBoolean() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.AbstractExternalContext#getApplicationMap()}.
+ */
+ public final void testGetApplicationMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.AbstractExternalContext#getInitParameterMap()}.
+ */
+ public final void testGetInitParameterMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.AbstractExternalContext#setRequest(java.lang.Object)}.
+ */
+ public final void testSetRequestObject() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestCookieMap()}.
+ */
+ public final void testGetRequestCookieMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestHeaderMap()}.
+ */
+ public final void testGetRequestHeaderMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestHeaderValuesMap()}.
+ */
+ public final void testGetRequestHeaderValuesMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestMap()}.
+ */
+ public final void testGetRequestMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestParameterMap()}.
+ */
+ public final void testGetRequestParameterMap() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.AbstractExternalContext#getRequestParameterNames()}.
+ */
+ public final void testGetRequestParameterNames() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.AbstractExternalContext#setResponse(java.lang.Object)}.
+ */
+ public final void testSetResponseObject() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.AbstractExternalContext#getSessionMap()}.
+ */
+ public final void testGetSessionMap() {
+ fail("Not yet implemented");
+ }
+}
17 years, 8 months
JBoss Ajax4JSF SVN: r85 - in trunk: a4j-portlet/src/main/java/org/ajax4jsf/portlet/context and 8 other directories.
by ajax4jsf-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2007-04-13 20:39:00 -0400 (Fri, 13 Apr 2007)
New Revision: 85
Added:
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockActionRequest.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockActionResponse.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletResponse.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockRenderRequest.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockRenderResponse.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java
trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java
Modified:
trunk/a4j-portlet/pom.xml
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextConcatentedMap.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java
trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_component_attributes.ent
trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java
trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UISelector.java
trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/AjaxActionComponent.java
trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/AjaxComponent.java
trunk/framework/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java
trunk/framework/src/main/java/org/ajax4jsf/framework/renderer/AjaxContainerRenderer.java
trunk/framework/src/main/javascript/ajaxjsf/JSFAJAX.js
Log:
Fix UIData issues related to RF-83
Create Portlet environment context test cases
Modified: trunk/a4j-portlet/pom.xml
===================================================================
--- trunk/a4j-portlet/pom.xml 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/a4j-portlet/pom.xml 2007-04-14 00:39:00 UTC (rev 85)
@@ -1,4 +1,7 @@
-<?xml version="1.0"?><project>
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>master</artifactId>
<groupId>org.ajax4jsf</groupId>
@@ -51,5 +54,11 @@
<artifactId>ajax4jsf</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.ajax4jsf</groupId>
+ <artifactId>test</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/AbstractExternalContext.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -94,7 +94,6 @@
*
*/
public abstract class AbstractExternalContext extends ExternalContext {
- // TODO - more configurable with sitemap parameters.
// TODO - optimization.
private Map applicationMap;
@@ -382,9 +381,6 @@
*
*/
public Map getRequestParameterValuesMap() {
- //
- // TODO make Cocoon-specific realization ( interact with sitemap
- // parameters )
if (this.requestParameterValuesMap == null) {
this.requestParameterValuesMap = new ContextAttributesMap() {
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextConcatentedMap.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextConcatentedMap.java 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/ContextConcatentedMap.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -18,17 +18,6 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/*
-
- * Created on 02.07.2005
-
- *
-
- * TODO To change the template for this generated file go to
-
- * Window - Preferences - Java - Code Style - Code Templates
-
- */
package org.ajax4jsf.portlet.context;
import java.util.Map;
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextFactoryImpl.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -85,9 +85,8 @@
* Hold <code>FacesContextFactory</code> from default implementation.
*
*/
- private FacesContextFactory defaultFacesContextFactory;
+// private FacesContextFactory defaultFacesContextFactory;
- public static final String FACES_CONTEXT_KEY = "COCOON_FACES_CONTEXT";
/**
*
@@ -98,11 +97,11 @@
* Factory from JSF implementation.
*
*/
- public FacesContextFactoryImpl(FacesContextFactory defaultFactory) {
+ public FacesContextFactoryImpl(/*FacesContextFactory defaultFactory*/) {
super();
- if (this.defaultFacesContextFactory == null) {
- this.defaultFacesContextFactory = defaultFactory;
- }
+// if (this.defaultFacesContextFactory == null) {
+// this.defaultFacesContextFactory = defaultFactory;
+// }
}
/*
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/FacesContextImpl.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -76,30 +76,13 @@
/**
*
+ * Implementation for <code>FacesContext</code> in Portlet Environment.
* @author shura
*
*
- *
- * Implementation for <code>FacesContext</code> in Cocoon Environment. Best -
- *
- * Act as decorator for default FacesContext implementation, but Sun
- *
- * implementstion use too many servlet functions ... Configure in cocoon.xconf
- *
- * with next global parameters : name of JSP servlet to NamedDispatcher. In
- *
- * Tomcat - "jsp" <parameter name="servlet-name" value="jsp"/>
- *
- *
- *
- * TODO - Implement as <code>Serviciable</code>,<code>Pullable</code>
- *
- * Avalon component ?
- *
- *
- *
*/
public class FacesContextImpl extends FacesContext {
+
private boolean released = true;
private boolean renderResponse;
@@ -127,6 +110,7 @@
setCurrentInstance(this);
this.externalContext = externalContext;
this.lifecycle = lifecycle;
+ this.released = false;
}
/*
@@ -139,13 +123,15 @@
*
*/
public Lifecycle getLifecycle() {
+ checkReleased();
return this.lifecycle;
}
public ELContext getELContext() {
checkReleased();
if (this.elContext == null) {
- this.elContext = new ELContextImpl(getApplication().getELResolver());
+ Application application = getApplication();
+ this.elContext = new ELContextImpl(application.getELResolver());
this.elContext.putContext(FacesContext.class, this);
UIViewRoot root = getViewRoot();
if (null != root) {
@@ -189,6 +175,7 @@
*
*/
public ResponseStream getResponseStream() {
+ checkReleased();
return this.responseStream;
}
@@ -202,6 +189,7 @@
*
*/
public void setResponseStream(ResponseStream responseStream) {
+ checkReleased();
this.responseStream = responseStream;
}
Modified: trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java
===================================================================
--- trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/a4j-portlet/src/main/java/org/ajax4jsf/portlet/context/PortletContextImpl.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -204,12 +204,10 @@
}
public String getRequestPathInfo() {
- // TODO Auto-generated method stub
return null;
}
public String getRequestServletPath() {
- // TODO Auto-generated method stub
return null;
}
Added: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockActionRequest.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockActionRequest.java (rev 0)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockActionRequest.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -0,0 +1,66 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import javax.portlet.ActionRequest;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MockActionRequest extends MockPortletRequest implements
+ ActionRequest {
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#getCharacterEncoding()
+ */
+ public String getCharacterEncoding() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#getContentLength()
+ */
+ public int getContentLength() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#getContentType()
+ */
+ public String getContentType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#getPortletInputStream()
+ */
+ public InputStream getPortletInputStream() throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#getReader()
+ */
+ public BufferedReader getReader() throws UnsupportedEncodingException,
+ IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionRequest#setCharacterEncoding(java.lang.String)
+ */
+ public void setCharacterEncoding(String arg0)
+ throws UnsupportedEncodingException {
+ // TODO Auto-generated method stub
+ }
+}
Added: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockActionResponse.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockActionResponse.java (rev 0)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockActionResponse.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -0,0 +1,61 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import java.io.IOException;
+import java.util.Map;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletModeException;
+import javax.portlet.WindowState;
+import javax.portlet.WindowStateException;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MockActionResponse extends MockPortletResponse implements
+ ActionResponse {
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#sendRedirect(java.lang.String)
+ */
+ public void sendRedirect(String arg0) throws IOException {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#setPortletMode(javax.portlet.PortletMode)
+ */
+ public void setPortletMode(PortletMode arg0) throws PortletModeException {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#setRenderParameter(java.lang.String, java.lang.String)
+ */
+ public void setRenderParameter(String arg0, String arg1) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#setRenderParameter(java.lang.String, java.lang.String[])
+ */
+ public void setRenderParameter(String arg0, String[] arg1) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#setRenderParameters(java.util.Map)
+ */
+ public void setRenderParameters(Map arg0) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.ActionResponse#setWindowState(javax.portlet.WindowState)
+ */
+ public void setWindowState(WindowState arg0) throws WindowStateException {
+ // TODO Auto-generated method stub
+ }
+}
Added: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java (rev 0)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletContext.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -0,0 +1,166 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletRequestDispatcher;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MockPortletContext implements PortletContext {
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getAttributeNames()
+ */
+ public Enumeration getAttributeNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getInitParameter(java.lang.String)
+ */
+ public String getInitParameter(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getInitParameterNames()
+ */
+ public Enumeration getInitParameterNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getMajorVersion()
+ */
+ public int getMajorVersion() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getMimeType(java.lang.String)
+ */
+ public String getMimeType(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getMinorVersion()
+ */
+ public int getMinorVersion() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getNamedDispatcher(java.lang.String)
+ */
+ public PortletRequestDispatcher getNamedDispatcher(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getPortletContextName()
+ */
+ public String getPortletContextName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getRealPath(java.lang.String)
+ */
+ public String getRealPath(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getRequestDispatcher(java.lang.String)
+ */
+ public PortletRequestDispatcher getRequestDispatcher(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getResource(java.lang.String)
+ */
+ public URL getResource(String arg0) throws MalformedURLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getResourceAsStream(java.lang.String)
+ */
+ public InputStream getResourceAsStream(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getResourcePaths(java.lang.String)
+ */
+ public Set getResourcePaths(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#getServerInfo()
+ */
+ public String getServerInfo() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#log(java.lang.String)
+ */
+ public void log(String arg0) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#log(java.lang.String, java.lang.Throwable)
+ */
+ public void log(String arg0, Throwable arg1) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String arg0) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletContext#setAttribute(java.lang.String, java.lang.Object)
+ */
+ public void setAttribute(String arg0, Object arg1) {
+ // TODO Auto-generated method stub
+ }
+}
Added: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java (rev 0)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletRequest.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -0,0 +1,291 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import java.security.Principal;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Map;
+import javax.portlet.PortalContext;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletSession;
+import javax.portlet.WindowState;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MockPortletRequest implements PortletRequest {
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getAttributeNames()
+ */
+ public Enumeration getAttributeNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getAuthType()
+ */
+ public String getAuthType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getContextPath()
+ */
+ public String getContextPath() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getLocale()
+ */
+ public Locale getLocale() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getLocales()
+ */
+ public Enumeration getLocales() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getParameter(java.lang.String)
+ */
+ public String getParameter(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getParameterMap()
+ */
+ public Map getParameterMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getParameterNames()
+ */
+ public Enumeration getParameterNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getParameterValues(java.lang.String)
+ */
+ public String[] getParameterValues(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getPortalContext()
+ */
+ public PortalContext getPortalContext() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getPortletMode()
+ */
+ public PortletMode getPortletMode() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getPortletSession()
+ */
+ public PortletSession getPortletSession() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getPortletSession(boolean)
+ */
+ public PortletSession getPortletSession(boolean arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getPreferences()
+ */
+ public PortletPreferences getPreferences() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getProperties(java.lang.String)
+ */
+ public Enumeration getProperties(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getProperty(java.lang.String)
+ */
+ public String getProperty(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getPropertyNames()
+ */
+ public Enumeration getPropertyNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getRemoteUser()
+ */
+ public String getRemoteUser() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getRequestedSessionId()
+ */
+ public String getRequestedSessionId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getResponseContentType()
+ */
+ public String getResponseContentType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getResponseContentTypes()
+ */
+ public Enumeration getResponseContentTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getScheme()
+ */
+ public String getScheme() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getServerName()
+ */
+ public String getServerName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getServerPort()
+ */
+ public int getServerPort() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getUserPrincipal()
+ */
+ public Principal getUserPrincipal() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#getWindowState()
+ */
+ public WindowState getWindowState() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#isPortletModeAllowed(javax.portlet.PortletMode)
+ */
+ public boolean isPortletModeAllowed(PortletMode arg0) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#isRequestedSessionIdValid()
+ */
+ public boolean isRequestedSessionIdValid() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#isSecure()
+ */
+ public boolean isSecure() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#isUserInRole(java.lang.String)
+ */
+ public boolean isUserInRole(String arg0) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#isWindowStateAllowed(javax.portlet.WindowState)
+ */
+ public boolean isWindowStateAllowed(WindowState arg0) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String arg0) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletRequest#setAttribute(java.lang.String, java.lang.Object)
+ */
+ public void setAttribute(String arg0, Object arg1) {
+ // TODO Auto-generated method stub
+ }
+}
Added: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletResponse.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletResponse.java (rev 0)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockPortletResponse.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -0,0 +1,34 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import javax.portlet.PortletResponse;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MockPortletResponse implements PortletResponse {
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletResponse#addProperty(java.lang.String, java.lang.String)
+ */
+ public void addProperty(String arg0, String arg1) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletResponse#encodeURL(java.lang.String)
+ */
+ public String encodeURL(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.PortletResponse#setProperty(java.lang.String, java.lang.String)
+ */
+ public void setProperty(String arg0, String arg1) {
+ // TODO Auto-generated method stub
+ }
+}
Added: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockRenderRequest.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockRenderRequest.java (rev 0)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockRenderRequest.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -0,0 +1,14 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import javax.portlet.RenderRequest;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MockRenderRequest extends MockPortletRequest implements
+ RenderRequest {
+}
Added: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockRenderResponse.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockRenderResponse.java (rev 0)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/MockRenderResponse.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -0,0 +1,140 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.Locale;
+import javax.portlet.PortletURL;
+import javax.portlet.RenderResponse;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MockRenderResponse extends MockPortletResponse implements
+ RenderResponse {
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#createActionURL()
+ */
+ public PortletURL createActionURL() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#createRenderURL()
+ */
+ public PortletURL createRenderURL() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#flushBuffer()
+ */
+ public void flushBuffer() throws IOException {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#getBufferSize()
+ */
+ public int getBufferSize() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#getCharacterEncoding()
+ */
+ public String getCharacterEncoding() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#getContentType()
+ */
+ public String getContentType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#getLocale()
+ */
+ public Locale getLocale() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#getNamespace()
+ */
+ public String getNamespace() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#getPortletOutputStream()
+ */
+ public OutputStream getPortletOutputStream() throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#getWriter()
+ */
+ public PrintWriter getWriter() throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#isCommitted()
+ */
+ public boolean isCommitted() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#reset()
+ */
+ public void reset() {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#resetBuffer()
+ */
+ public void resetBuffer() {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#setBufferSize(int)
+ */
+ public void setBufferSize(int arg0) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#setContentType(java.lang.String)
+ */
+ public void setContentType(String arg0) {
+ // TODO Auto-generated method stub
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.RenderResponse#setTitle(java.lang.String)
+ */
+ public void setTitle(String arg0) {
+ // TODO Auto-generated method stub
+ }
+}
Added: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java (rev 0)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/ContextFactoryTest.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -0,0 +1,89 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.context;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
+import org.ajax4jsf.portlet.MockActionRequest;
+import org.ajax4jsf.portlet.MockActionResponse;
+import org.ajax4jsf.portlet.MockPortletContext;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import junit.framework.TestCase;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ContextFactoryTest extends AbstractAjax4JsfTestCase {
+ /**
+ * @param arg0
+ */
+ public ContextFactoryTest(String arg0) {
+ super(arg0);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test method for
+ * {@link org.ajax4jsf.portlet.context.FacesContextFactoryImpl#FacesContextFactoryImpl(javax.faces.context.FacesContextFactory)}.
+ */
+ public void testFacesContextFactoryImpl() {
+ FacesContextFactoryImpl factory = new FacesContextFactoryImpl();
+ FacesContext context = factory.getFacesContext(servletContext, request,
+ response, lifecycle);
+ assertTrue((context instanceof FacesContextImpl));
+ assertTrue((context.getExternalContext() instanceof ServletContextImpl));
+ }
+
+ /**
+ * Test method for
+ * {@link org.ajax4jsf.portlet.context.FacesContextFactoryImpl#getFacesContext(java.lang.Object, java.lang.Object, java.lang.Object, javax.faces.lifecycle.Lifecycle)}.
+ */
+ public void testGetFacesContextPortlet() {
+ FacesContextFactoryImpl factory = new FacesContextFactoryImpl();
+ MockPortletContext portletContext = new MockPortletContext();
+ MockActionRequest portletRequest = new MockActionRequest();
+ MockActionResponse portletResponse = new MockActionResponse();
+ FacesContext context = factory.getFacesContext(portletContext,
+ portletRequest, portletResponse, lifecycle);
+ assertTrue((context instanceof FacesContextImpl));
+ assertTrue((context.getExternalContext() instanceof PortletContextImpl));
+ assertSame(FacesContext.getCurrentInstance(),context);
+ }
+
+ public void testIllegalEnvironment() throws Exception {
+ FacesContextFactoryImpl factory = new FacesContextFactoryImpl();
+ try {
+ FacesContext context = factory.getFacesContext(null, request,
+ response, lifecycle);
+ assertTrue("null pointer passed", false);
+ } catch (NullPointerException e) {
+ }
+ try {
+ FacesContext context = factory.getFacesContext(facesContext,
+ request, response, lifecycle);
+ assertTrue("illegal context passed", false);
+ } catch (FacesException e) {
+ // TODO: handle exception
+ }
+ }
+}
Added: trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java
===================================================================
--- trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java (rev 0)
+++ trunk/a4j-portlet/src/test/java/org/ajax4jsf/portlet/context/FacesContextImplTest.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -0,0 +1,126 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet.context;
+
+import javax.el.ELContext;
+import javax.faces.context.FacesContext;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class FacesContextImplTest extends AbstractAjax4JsfTestCase {
+ protected FacesContextImpl portalFacesContext;
+ protected ServletContextImpl servletContextImpl;
+
+ /**
+ * @param arg0
+ */
+ public FacesContextImplTest(String arg0) {
+ super(arg0);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ servletContextImpl = new ServletContextImpl(servletContext,request,response);
+ portalFacesContext = new FacesContextImpl(servletContextImpl,lifecycle);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+// portalFacesContext.release();
+ servletContextImpl = null;
+ portalFacesContext = null;
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#release()}.
+ */
+ public void testRelease() {
+ portalFacesContext.release();
+ assertNull(FacesContext.getCurrentInstance());
+ try {
+ portalFacesContext.getLifecycle();
+ fail("Context not released");
+ } catch (Exception e) {
+ }
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#renderResponse()}.
+ */
+ public void testRenderResponse() {
+ assertFalse(portalFacesContext.getRenderResponse());
+ portalFacesContext.renderResponse();
+ assertTrue(portalFacesContext.getRenderResponse());
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#responseComplete()}.
+ */
+ public void testResponseComplete() {
+ assertFalse(portalFacesContext.getResponseComplete());
+ portalFacesContext.responseComplete();
+ assertTrue(portalFacesContext.getResponseComplete());
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getELContext()}.
+ */
+ public void testGetELContext() {
+ ELContext elContext = portalFacesContext.getELContext();
+ assertSame(application.getELResolver(),elContext.getELResolver());
+ assertSame(elContext,portalFacesContext.getELContext());
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getApplication()}.
+ */
+ public void testGetApplication() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getClientIdsWithMessages()}.
+ */
+ public void testGetClientIdsWithMessages() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getMaximumSeverity()}.
+ */
+ public void testGetMaximumSeverity() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getMessages()}.
+ */
+ public void testGetMessages() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getMessages(java.lang.String)}.
+ */
+ public void testGetMessagesString() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.portlet.context.FacesContextImpl#getRenderKit()}.
+ */
+ public void testGetRenderKit() {
+ fail("Not yet implemented");
+ }
+}
Modified: trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_component_attributes.ent
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_component_attributes.ent 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_component_attributes.ent 2007-04-14 00:39:00 UTC (rev 85)
@@ -59,6 +59,11 @@
<classname>java.lang.String</classname>
<description>JavaScript code for call after request completed on client side</description>
</property>
+ <property >
+ <name>focus</name>
+ <classname>java.lang.String</classname>
+ <description>id of element to set focus after request completed on client side</description>
+ </property>
<property >
<name>data</name>
<classname>java.lang.Object</classname>
Modified: trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java
===================================================================
--- trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -47,11 +47,8 @@
import javax.faces.model.ListDataModel;
import javax.faces.render.Renderer;
-import org.ajax4jsf.framework.ajax.AjaxEvent;
import org.ajax4jsf.framework.renderer.AjaxChildrenRenderer;
-import com.sun.org.apache.bcel.internal.generic.GETSTATIC;
-
/**
* Base class for iterable components, like dataTable, Tomahawk dataList,
* Facelets repeat, tree etc., with support for partial rendering on AJAX
@@ -62,1218 +59,1254 @@
*/
public abstract class UIDataAdaptor extends UIData implements AjaxDataEncoder {
- /**
- *
- */
- public static final String COMPONENT_STATE_ATTRIBUTE = "componentState";
+ /**
+ *
+ */
+ public static final String COMPONENT_STATE_ATTRIBUTE = "componentState";
- public final static DataModel EMPTY_MODEL = new ListDataModel(
- Collections.EMPTY_LIST);
+ public final static DataModel EMPTY_MODEL = new ListDataModel(
+ Collections.EMPTY_LIST);
- /**
- * Base class for visit data model at phases decode, validation and update
- * model
- *
- * @author shura
- *
- */
- protected abstract class ComponentVisitor implements DataVisitor {
+ /**
+ * Base class for visit data model at phases decode, validation and
+ * update model
+ *
+ * @author shura
+ *
+ */
+ protected abstract class ComponentVisitor implements DataVisitor {
- public void process(FacesContext context, Object rowKey, Object argument)
- throws IOException {
- setRowKey(context, rowKey);
- Iterator childIterator = dataChildren();
- while (childIterator.hasNext()) {
- UIComponent component = (UIComponent) childIterator.next();
- processComponent(context, component, argument);
- }
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+ setRowKey(context, rowKey);
+ if (isRowAvailable()) {
+ Iterator childIterator = dataChildren();
+ while (childIterator.hasNext()) {
+ UIComponent component = (UIComponent) childIterator.next();
+ processComponent(context, component, argument);
}
- public abstract void processComponent(FacesContext context,
- UIComponent c, Object argument);
+ }
+ }
+ public abstract void processComponent(FacesContext context,
+ UIComponent c, Object argument) throws IOException;
+
+ }
+
+ /**
+ * Visitor for process decode on children components.
+ */
+ protected ComponentVisitor decodeVisitor = new ComponentVisitor() {
+
+ public void processComponent(FacesContext context, UIComponent c,
+ Object argument) {
+ c.processDecodes(context);
}
- /**
- * Visitor for process decode on children components.
- */
- protected ComponentVisitor decodeVisitor = new ComponentVisitor() {
+ };
- public void processComponent(FacesContext context, UIComponent c,
- Object argument) {
- c.processDecodes(context);
- }
+ /**
+ * Visitor for process validation phase
+ */
+ protected ComponentVisitor validateVisitor = new ComponentVisitor() {
- };
+ public void processComponent(FacesContext context, UIComponent c,
+ Object argument) {
+ c.processValidators(context);
+ }
- /**
- * Visitor for process validation phase
- */
- protected ComponentVisitor validateVisitor = new ComponentVisitor() {
+ };
- public void processComponent(FacesContext context, UIComponent c,
- Object argument) {
- c.processValidators(context);
- }
+ /**
+ * Visitor for process update model phase.
+ */
+ protected ComponentVisitor updateVisitor = new ComponentVisitor() {
- };
+ public void processComponent(FacesContext context, UIComponent c,
+ Object argument) {
+ c.processUpdates(context);
+ }
- /**
- * Visitor for process update model phase.
- */
- protected ComponentVisitor updateVisitor = new ComponentVisitor() {
+ };
- public void processComponent(FacesContext context, UIComponent c,
- Object argument) {
- c.processUpdates(context);
- }
+ /**
+ * Base client id's of this component, for wich invoked encode...
+ * methods. Component will save state and serialisable models for this
+ * keys only.
+ */
+ private Set _encoded;
- };
+ /**
+ * Storage for data model instances with different client id's of this
+ * component. In case of child for UIData component, this map will keep
+ * data models for different iterations between phases.
+ */
+ private Map _modelsMap = new HashMap();
- /**
- * Base client id's of this component, for wich invoked encode... methods.
- * Component will save state and serialisable models for this keys only.
- */
- private Set _encoded;
+ /**
+ * Reference for curent data model
+ */
+ private ExtendedDataModel _currentModel = null;
- /**
- * Storage for data model instances with different client id's of this
- * component. In case of child for UIData component, this map will keep data
- * models for different iterations between phases.
- */
- private Map _modelsMap = new HashMap();
+ /**
+ * States of this component for diferent iterations, same as for models.
+ */
+ private Map _statesMap = new HashMap();
- /**
- * Reference for curent data model
- */
- private ExtendedDataModel _currentModel = null;
+ /**
+ * Reference for current component state.
+ */
+ private DataComponentState _currentState = null;
- /**
- * States of this component for diferent iterations, same as for models.
- */
- private Map _statesMap = new HashMap();
+ /**
+ * Name of EL variable for current component state.
+ */
+ private String _stateVar;
- /**
- * Reference for current component state.
- */
- private DataComponentState _currentState = null;
+ private String _rowKeyVar;
- /**
- * Name of EL variable for current component state.
- */
- private String _stateVar;
+ /**
+ * Key for current value in model.
+ */
+ private Object _rowKey = null;
- private String _rowKeyVar;
+ /**
+ * Values of row keys, encoded on ajax response rendering.
+ */
+ private Set _ajaxKeys = null;
- /**
- * Key for current value in model.
- */
- private Object _rowKey = null;
+ private Object _ajaxRowKey = null;
- /**
- * Values of row keys, encoded on ajax response rendering.
- */
- private Set _ajaxKeys = null;
+ private Map _ajaxRowKeysMap = new HashMap();
- /**
- * Get name of EL variable for component state.
- *
- * @return the varState
- */
- public String getStateVar() {
- return _stateVar;
- }
+ /**
+ * Get name of EL variable for component state.
+ *
+ * @return the varState
+ */
+ public String getStateVar() {
+ return _stateVar;
+ }
- /**
- * @param varStatus
- * the varStatus to set
- */
- public void setStateVar(String varStatus) {
- this._stateVar = varStatus;
- }
+ /**
+ * @param varStatus
+ * the varStatus to set
+ */
+ public void setStateVar(String varStatus) {
+ this._stateVar = varStatus;
+ }
- /**
- * @return the rowKeyVar
- */
- public String getRowKeyVar() {
- return this._rowKeyVar;
- }
+ /**
+ * @return the rowKeyVar
+ */
+ public String getRowKeyVar() {
+ return this._rowKeyVar;
+ }
- /**
- * @param rowKeyVar
- * the rowKeyVar to set
- */
- public void setRowKeyVar(String rowKeyVar) {
- this._rowKeyVar = rowKeyVar;
- }
+ /**
+ * @param rowKeyVar
+ * the rowKeyVar to set
+ */
+ public void setRowKeyVar(String rowKeyVar) {
+ this._rowKeyVar = rowKeyVar;
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.UIData#getRowCount()
- */
- public int getRowCount() {
- return getExtendedDataModel().getRowCount();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIData#getRowCount()
+ */
+ public int getRowCount() {
+ return getExtendedDataModel().getRowCount();
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.UIData#getRowData()
- */
- public Object getRowData() {
- return getExtendedDataModel().getRowData();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIData#getRowData()
+ */
+ public Object getRowData() {
+ return getExtendedDataModel().getRowData();
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.UIData#isRowAvailable()
- */
- public boolean isRowAvailable() {
- return this.getExtendedDataModel().isRowAvailable();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIData#isRowAvailable()
+ */
+ public boolean isRowAvailable() {
+ return this.getExtendedDataModel().isRowAvailable();
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.UIData#setRowIndex(int)
- */
- public void setRowIndex(int index) {
- FacesContext faces = FacesContext.getCurrentInstance();
- ExtendedDataModel localModel = getExtendedDataModel();
- // if(key == localModel.getRowIndex()){
- // return;
- // }
- // save child state
- this.saveChildState(faces);
- // Set current model row by int, but immediately get value from model.
- // for compability, complex models must provide values map between
- // integer and key value.
- localModel.setRowIndex(index);
- this._rowKey = localModel.getRowKey();
- this._clientId = null;
- boolean rowSelected = this._rowKey != null;
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIData#setRowIndex(int)
+ */
+ public void setRowIndex(int index) {
+ FacesContext faces = FacesContext.getCurrentInstance();
+ ExtendedDataModel localModel = getExtendedDataModel();
+ // if(key == localModel.getRowIndex()){
+ // return;
+ // }
+ // save child state
+ this.saveChildState(faces);
+ // Set current model row by int, but immediately get value from model.
+ // for compability, complex models must provide values map between
+ // integer and key value.
+ localModel.setRowIndex(index);
+ this._rowKey = localModel.getRowKey();
+ this._clientId = null;
+ boolean rowSelected = this._rowKey != null;
- setupVariable(faces, localModel, rowSelected);
- // restore child state
- this.restoreChildState(faces);
- }
+ setupVariable(faces, localModel, rowSelected);
+ // restore child state
+ this.restoreChildState(faces);
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.UIData#getRowIndex()
- */
- public int getRowIndex() {
- return getExtendedDataModel().getRowIndex();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIData#getRowIndex()
+ */
+ public int getRowIndex() {
+ return getExtendedDataModel().getRowIndex();
+ }
- /**
- * Same as for int index, but for complex model key.
- *
- * @return
- */
- public Object getRowKey() {
- return this._rowKey;
- }
+ /**
+ * Same as for int index, but for complex model key.
+ *
+ * @return
+ */
+ public Object getRowKey() {
+ return this._rowKey;
+ }
- public void setRowKey(Object key) {
- setRowKey(FacesContext.getCurrentInstance(), key);
- }
+ public void setRowKey(Object key) {
+ setRowKey(FacesContext.getCurrentInstance(), key);
+ }
- /**
- * Setup current roy by key. Perform same functionality as
- * {@link UIData#setRowIndex(int)}, but for key object - it may be not only
- * row number in sequence data, but, for example - path to current node in
- * tree.
- *
- * @param faces -
- * current FacesContext
- * @param key
- * new key value.
- */
- public void setRowKey(FacesContext faces, Object key) {
- ExtendedDataModel localModel = getExtendedDataModel();
- // save child state
- this.saveChildState(faces);
- this._rowKey = key;
- this._clientId = null;
- localModel.setRowKey(key);
+ /**
+ * Setup current roy by key. Perform same functionality as
+ * {@link UIData#setRowIndex(int)}, but for key object - it may be not
+ * only row number in sequence data, but, for example - path to current
+ * node in tree.
+ *
+ * @param faces -
+ * current FacesContext
+ * @param key
+ * new key value.
+ */
+ public void setRowKey(FacesContext faces, Object key) {
+ ExtendedDataModel localModel = getExtendedDataModel();
+ // save child state
+ this.saveChildState(faces);
+ this._rowKey = key;
+ this._clientId = null;
+ localModel.setRowKey(key);
- boolean rowSelected = key != null;
+ boolean rowSelected = key != null;
- setupVariable(faces, localModel, rowSelected);
- // restore child state
- this.restoreChildState(faces);
+ setupVariable(faces, localModel, rowSelected);
+ // restore child state
+ this.restoreChildState(faces);
- }
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.ajax.repeat.AjaxDataEncoder#getAjaxKeys()
- */
- public Set getAjaxKeys() {
- if (this._ajaxKeys != null) {
- return (this._ajaxKeys);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.ajax.repeat.AjaxDataEncoder#getAjaxKeys()
+ */
+ public Set getAjaxKeys() {
+ Set keys = null;
+ if (this._ajaxKeys != null) {
+ keys = (this._ajaxKeys);
+ } else {
ValueBinding vb = getValueBinding("ajaxKeys");
if (vb != null) {
- return (Set) (vb.getValue(getFacesContext()));
- } else {
- return (null);
+ keys = (Set) (vb.getValue(getFacesContext()));
+ } else if(null != _ajaxRowKey){
+ // If none of above exist , use row with submitted AjaxComponent
+ keys = (Collections.singleton(_ajaxRowKey));
}
}
+ return keys;
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.ajax.repeat.AjaxDataEncoder#setAjaxKeys(java.util.Set)
- */
- public void setAjaxKeys(Set ajaxKeys) {
- this._ajaxKeys = ajaxKeys;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.ajax.repeat.AjaxDataEncoder#setAjaxKeys(java.util.Set)
+ */
+ public void setAjaxKeys(Set ajaxKeys) {
+ this._ajaxKeys = ajaxKeys;
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.framework.ajax.AjaxChildrenEncoder#encodeAjaxChild(javax.faces.context.FacesContext,
- * java.lang.String, java.util.Set, java.util.Set)
- */
- public void encodeAjaxChild(FacesContext context, String path, Set ids,
- Set renderedAreas) throws IOException {
- resetDataModel();
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.AjaxChildrenEncoder#encodeAjaxChild(javax.faces.context.FacesContext,
+ * java.lang.String, java.util.Set, java.util.Set)
+ */
+ public void encodeAjaxChild(FacesContext context, String path,
+ final Set ids, final Set renderedAreas) throws IOException {
+ resetDataModel();
- Renderer renderer = getRenderer(context);
- if (null != renderer && renderer instanceof AjaxChildrenRenderer) {
- // If renderer support partial encoding - call them.
- AjaxChildrenRenderer childrenRenderer = (AjaxChildrenRenderer) renderer;
- childrenRenderer.encodeAjaxChild(context, this, path, ids,
- renderedAreas);
- } else {
- // Use simple ajax children encoding for iterate other keys.
- AjaxChildrenRenderer childrenRenderer = getChildrenRenderer();
- Set ajaxKeys = getAjaxKeys();
- if (null != ajaxKeys) {
- Object savedKey = getRowKey();
- for (Iterator iter = ajaxKeys.iterator(); iter.hasNext();) {
- Object key = (Object) iter.next();
- setRowKey(key);
- if (isRowAvailable()) {
- childrenRenderer.encodeAjaxChild(context, this, path,
- ids, renderedAreas);
- }
- }
- setRowKey(savedKey);
- } else {
- if (isRowAvailable()) {
- childrenRenderer.encodeAjaxChild(context, this, path, ids,
- renderedAreas);
- }
- }
+ Renderer renderer = getRenderer(context);
+ if (null != renderer && renderer instanceof AjaxChildrenRenderer) {
+ // If renderer support partial encoding - call them.
+ AjaxChildrenRenderer childrenRenderer = (AjaxChildrenRenderer) renderer;
+ childrenRenderer.encodeAjaxChildren(context, this, path, ids,
+ renderedAreas);
+ } else {
+ // Use simple ajax children encoding for iterate other keys.
+ final AjaxChildrenRenderer childrenRenderer = getChildrenRenderer();
+ final String childrenPath = path + getId() + NamingContainer.SEPARATOR_CHAR;
+ ComponentVisitor ajaxVisitor = new ComponentVisitor() {
+
+ public void processComponent(FacesContext context,
+ UIComponent c, Object argument) throws IOException {
+ childrenRenderer.encodeAjaxComponent(context, c, childrenPath,
+ ids, renderedAreas);
}
+
+ };
+ Set ajaxKeys = getAjaxKeys();
+ if (null != ajaxKeys) {
+ captureOrigValue();
+ Object savedKey = getRowKey();
+ setRowKey(context, null);
+ Iterator fixedChildren = fixedChildren();
+ while (fixedChildren.hasNext()) {
+ UIComponent component = (UIComponent) fixedChildren.next();
+ ajaxVisitor.processComponent(context, component, null);
+ }
+ for (Iterator iter = ajaxKeys.iterator(); iter.hasNext();) {
+ Object key = (Object) iter.next();
+ ajaxVisitor.process(context, key, null);
+ }
+ setRowKey(savedKey);
+ restoreOrigValue();
+ } else {
+ iterate(context, ajaxVisitor, null);
+ }
}
+ }
- /**
- * Instance of default renderer in ajax responses.
- */
- private AjaxChildrenRenderer _childrenRenderer = null;
+ /**
+ * Instance of default renderer in ajax responses.
+ */
+ private AjaxChildrenRenderer _childrenRenderer = null;
- /**
- * getter for simple {@link AjaxChildrenRenderer} instance in case of ajax
- * responses. If default renderer not support search of children for encode
- * in ajax response, component will use this instance by default.
- *
- * @return
- */
- protected AjaxChildrenRenderer getChildrenRenderer() {
- if (_childrenRenderer == null) {
- _childrenRenderer = new AjaxChildrenRenderer() {
+ /**
+ * getter for simple {@link AjaxChildrenRenderer} instance in case of
+ * ajax responses. If default renderer not support search of children
+ * for encode in ajax response, component will use this instance by
+ * default.
+ *
+ * @return
+ */
+ protected AjaxChildrenRenderer getChildrenRenderer() {
+ if (_childrenRenderer == null) {
+ _childrenRenderer = new AjaxChildrenRenderer() {
- protected Class getComponentClass() {
- return UIDataAdaptor.class;
- }
+ protected Class getComponentClass() {
+ return UIDataAdaptor.class;
+ }
- };
+ };
- }
-
- return _childrenRenderer;
}
- /**
- * @return Set of values for clientId's of this component, for wich was
- * invoked "encode" methods.
- */
- protected Set getEncodedIds() {
- if (_encoded == null) {
- _encoded = new HashSet();
- }
+ return _childrenRenderer;
+ }
- return _encoded;
+ /**
+ * @return Set of values for clientId's of this component, for wich was
+ * invoked "encode" methods.
+ */
+ protected Set getEncodedIds() {
+ if (_encoded == null) {
+ _encoded = new HashSet();
}
- /**
- * Setup EL variable for different iteration. Value of row data and
- * component state will be put into request scope attributes with names
- * given by "var" and "varState" bean properties.
- *
- * @param faces
- * current faces context
- * @param localModel
- * @param rowSelected
- */
- protected void setupVariable(FacesContext faces, DataModel localModel,
- boolean rowSelected) {
- Map attrs = faces.getExternalContext().getRequestMap();
- if (rowSelected && isRowAvailable()) {
- // Current row data.
- setupVariable(getVar(), attrs, localModel.getRowData());
- // Component state variable.
- setupVariable(getStateVar(), attrs, getComponentState());
- // Row key Data variable.
- setupVariable(getRowKeyVar(), attrs, getRowKey());
+ return _encoded;
+ }
- } else {
- removeVariable(getVar(), attrs);
- removeVariable(getStateVar(), attrs);
- removeVariable(getRowKeyVar(), attrs);
- }
- }
+ /**
+ * Setup EL variable for different iteration. Value of row data and
+ * component state will be put into request scope attributes with names
+ * given by "var" and "varState" bean properties.
+ *
+ * @param faces
+ * current faces context
+ * @param localModel
+ * @param rowSelected
+ */
+ protected void setupVariable(FacesContext faces, DataModel localModel,
+ boolean rowSelected) {
+ Map attrs = faces.getExternalContext().getRequestMap();
+ if (rowSelected && isRowAvailable()) {
+ // Current row data.
+ setupVariable(getVar(), attrs, localModel.getRowData());
+ // Component state variable.
+ setupVariable(getStateVar(), attrs, getComponentState());
+ // Row key Data variable.
+ setupVariable(getRowKeyVar(), attrs, getRowKey());
- /**
- * @param var
- * @param attrs
- * @param rowData
- */
- private void setupVariable(String var, Map attrs, Object rowData) {
- if (var != null) {
- attrs.put(var, rowData);
- }
+ } else {
+ removeVariable(getVar(), attrs);
+ removeVariable(getStateVar(), attrs);
+ removeVariable(getRowKeyVar(), attrs);
}
+ }
- /**
- * @param var
- * @param attrs
- * @param rowData
- */
- private void removeVariable(String var, Map attrs) {
- if (var != null) {
- attrs.remove(var);
- }
+ /**
+ * @param var
+ * @param attrs
+ * @param rowData
+ */
+ private void setupVariable(String var, Map attrs, Object rowData) {
+ if (var != null) {
+ attrs.put(var, rowData);
}
- /**
- * Reset data model. this method must be called twice per request - before
- * decode phase and before component encoding.
- */
- protected void resetDataModel() {
- this.setExtendedDataModel(null);
- }
+ }
- /**
- * Set data model. Model value will be stored in Map with key as current
- * clientId for this component, to keep models between phases for same
- * iteration in case if this component child for other UIData
- *
- * @param model
- */
- protected void setExtendedDataModel(ExtendedDataModel model) {
- this._currentModel = model;
- this._modelsMap.put(getBaseClientId(getFacesContext()), model);
+ /**
+ * @param var
+ * @param attrs
+ * @param rowData
+ */
+ private void removeVariable(String var, Map attrs) {
+ if (var != null) {
+ attrs.remove(var);
}
+ }
- /**
- * Get current data model, or create it by {@link #createDataModel()}
- * method. For different iterations in ancestor UIData ( if present ) will
- * be returned different models.
- *
- * @return current data model.
- */
- protected ExtendedDataModel getExtendedDataModel() {
- if (this._currentModel == null) {
- String baseClientId = getBaseClientId(getFacesContext());
- ExtendedDataModel model = (ExtendedDataModel) this._modelsMap
- .get(baseClientId);
- if (null == model) {
- model = createDataModel();
- this._modelsMap.put(baseClientId, model);
- }
- this._currentModel = model;
- }
- return this._currentModel;
- }
+ /**
+ * Reset data model. this method must be called twice per request -
+ * before decode phase and before component encoding.
+ */
+ protected void resetDataModel() {
+ this.setExtendedDataModel(null);
+ }
- /**
- * Hook mathod for create data model in concrete implementations.
- *
- * @return
- */
- protected abstract ExtendedDataModel createDataModel();
+ /**
+ * Set data model. Model value will be stored in Map with key as current
+ * clientId for this component, to keep models between phases for same
+ * iteration in case if this component child for other UIData
+ *
+ * @param model
+ */
+ protected void setExtendedDataModel(ExtendedDataModel model) {
+ this._currentModel = model;
+ this._modelsMap.put(getBaseClientId(getFacesContext()), model);
+ }
- /**
- * Set current state ( at most cases, visual representation ) of this
- * component. Same as for DataModel, component will keep states for
- * different iterations.
- *
- * @param state
- */
- public void setComponentState(DataComponentState state) {
- this._currentState = state;
- this._statesMap.put(getBaseClientId(getFacesContext()),
- this._currentState);
+ /**
+ * Get current data model, or create it by {@link #createDataModel()}
+ * method. For different iterations in ancestor UIData ( if present )
+ * will be returned different models.
+ *
+ * @return current data model.
+ */
+ protected ExtendedDataModel getExtendedDataModel() {
+ if (this._currentModel == null) {
+ String baseClientId = getBaseClientId(getFacesContext());
+ ExtendedDataModel model = (ExtendedDataModel) this._modelsMap
+ .get(baseClientId);
+ if (null == model) {
+ model = createDataModel();
+ this._modelsMap.put(baseClientId, model);
+ }
+ this._currentModel = model;
}
+ return this._currentModel;
+ }
- /**
- * @return current state of this component.
- */
- public DataComponentState getComponentState() {
- DataComponentState state = null;
- if (this._currentState == null) {
- // Check for binding state to user bean.
- ValueBinding valueBinding = getValueBinding(UIDataAdaptor.COMPONENT_STATE_ATTRIBUTE);
- FacesContext facesContext = getFacesContext();
- if (null != valueBinding) {
- state = (DataComponentState) valueBinding
- .getValue(facesContext);
- if (null == state) {
- // Create default state
- state = createComponentState();
- if (!valueBinding.isReadOnly(facesContext)) {
- // Store created state in user bean.
- valueBinding.setValue(facesContext, state);
- }
- }
- } else {
- // Check for stored state in map for parent iterations
- String baseClientId = getBaseClientId(facesContext);
- state = (DataComponentState) this._statesMap.get(baseClientId);
- if (null == state) {
- // Create default component state
- state = createComponentState();
- this._statesMap.put(baseClientId, state);
- }
- this._currentState = state;
- }
- } else {
- state = this._currentState;
+ /**
+ * Hook mathod for create data model in concrete implementations.
+ *
+ * @return
+ */
+ protected abstract ExtendedDataModel createDataModel();
+
+ /**
+ * Set current state ( at most cases, visual representation ) of this
+ * component. Same as for DataModel, component will keep states for
+ * different iterations.
+ *
+ * @param state
+ */
+ public void setComponentState(DataComponentState state) {
+ this._currentState = state;
+ this._statesMap.put(getBaseClientId(getFacesContext()),
+ this._currentState);
+ }
+
+ /**
+ * @return current state of this component.
+ */
+ public DataComponentState getComponentState() {
+ DataComponentState state = null;
+ if (this._currentState == null) {
+ // Check for binding state to user bean.
+ ValueBinding valueBinding = getValueBinding(UIDataAdaptor.COMPONENT_STATE_ATTRIBUTE);
+ FacesContext facesContext = getFacesContext();
+ if (null != valueBinding) {
+ state = (DataComponentState) valueBinding
+ .getValue(facesContext);
+ if (null == state) {
+ // Create default state
+ state = createComponentState();
+ if (!valueBinding.isReadOnly(facesContext)) {
+ // Store created state in user bean.
+ valueBinding.setValue(facesContext, state);
+ }
}
- return state;
+ } else {
+ // Check for stored state in map for parent iterations
+ String baseClientId = getBaseClientId(facesContext);
+ state = (DataComponentState) this._statesMap.get(baseClientId);
+ if (null == state) {
+ // Create default component state
+ state = createComponentState();
+ this._statesMap.put(baseClientId, state);
+ }
+ this._currentState = state;
+ }
+ } else {
+ state = this._currentState;
}
+ return state;
+ }
- /**
- * Hook method for create default state in concrete implementations.
- *
- * @return
- */
- protected abstract DataComponentState createComponentState();
+ /**
+ * Hook method for create default state in concrete implementations.
+ *
+ * @return
+ */
+ protected abstract DataComponentState createComponentState();
- private String _clientId = null;
+ private String _clientId = null;
- public String getClientId(FacesContext faces) {
- if (null == _clientId) {
- StringBuffer id = new StringBuffer(getBaseClientId(faces));
- Object rowKey = getRowKey();
- if (rowKey != null) {
- id.append(NamingContainer.SEPARATOR_CHAR).append(
- rowKey.toString());
- }
- Renderer renderer;
- if (null != (renderer = getRenderer(faces))) {
- _clientId = renderer.convertClientId(faces, id.toString());
- } else {
- _clientId = id.toString();
- }
+ public String getClientId(FacesContext faces) {
+ if (null == _clientId) {
+ StringBuffer id = new StringBuffer(getBaseClientId(faces));
+ Object rowKey = getRowKey();
+ if (rowKey != null) {
+ id.append(NamingContainer.SEPARATOR_CHAR).append(
+ rowKey.toString());
+ }
+ Renderer renderer;
+ if (null != (renderer = getRenderer(faces))) {
+ _clientId = renderer.convertClientId(faces, id.toString());
+ } else {
+ _clientId = id.toString();
+ }
- }
- return _clientId;
}
+ return _clientId;
+ }
- private String _baseClientId = null;
+ private String _baseClientId = null;
- /**
- * Get base clietntId of this component ( withowt iteration part )
- *
- * @param faces
- * @return
- */
- public String getBaseClientId(FacesContext faces) {
- // Return any previously cached client identifier
- if (_baseClientId == null) {
+ /**
+ * Get base clietntId of this component ( withowt iteration part )
+ *
+ * @param faces
+ * @return
+ */
+ public String getBaseClientId(FacesContext faces) {
+ // Return any previously cached client identifier
+ if (_baseClientId == null) {
- // Search for an ancestor that is a naming container
- UIComponent ancestorContainer = this;
- StringBuffer parentIds = new StringBuffer();
- while (null != (ancestorContainer = ancestorContainer.getParent())) {
- if (ancestorContainer instanceof NamingContainer) {
- parentIds.append(ancestorContainer.getClientId(faces))
- .append(NamingContainer.SEPARATOR_CHAR);
- break;
- }
- }
- String id = getId();
- if (null != id) {
- _baseClientId = parentIds.append(id).toString();
- } else {
- _baseClientId = parentIds.append(
- faces.getViewRoot().createUniqueId()).toString();
- }
+ // Search for an ancestor that is a naming container
+ UIComponent ancestorContainer = this;
+ StringBuffer parentIds = new StringBuffer();
+ while (null != (ancestorContainer = ancestorContainer.getParent())) {
+ if (ancestorContainer instanceof NamingContainer) {
+ parentIds.append(ancestorContainer.getClientId(faces))
+ .append(NamingContainer.SEPARATOR_CHAR);
+ break;
}
- return (_baseClientId);
-
+ }
+ String id = getId();
+ if (null != id) {
+ _baseClientId = parentIds.append(id).toString();
+ } else {
+ _baseClientId = parentIds.append(
+ faces.getViewRoot().createUniqueId()).toString();
+ }
}
+ return (_baseClientId);
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.UIComponentBase#setId(java.lang.String)
- */
- public void setId(String id) {
- // If component created by restoring tree or JSP, initial Id is null.
- boolean haveId = null != super.getId();
- super.setId(id);
- _baseClientId = null;
- _clientId = null;
- if (haveId) {
- // parent UIData ( if present ) will be set same Id at iteration -
- // we use it for
- // switch to different model and state.
- String baseClientId = getBaseClientId(getFacesContext());
- this._currentState = (DataComponentState) this._statesMap
- .get(baseClientId);
- this._currentModel = (ExtendedDataModel) this._modelsMap
- .get(baseClientId);
- if (null != this._currentModel) {
- this._rowKey = this._currentModel.getRowKey();
- // restoreChildState();
- }
- }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIComponentBase#setId(java.lang.String)
+ */
+ public void setId(String id) {
+ // If component created by restoring tree or JSP, initial Id is null.
+ boolean haveId = null != super.getId();
+ super.setId(id);
+ _baseClientId = null;
+ _clientId = null;
+ if (haveId) {
+ // parent UIData ( if present ) will be set same Id at iteration
+ // -
+ // we use it for
+ // switch to different model and state.
+ String baseClientId = getBaseClientId(getFacesContext());
+ this._currentState = (DataComponentState) this._statesMap
+ .get(baseClientId);
+ this._currentModel = (ExtendedDataModel) this._modelsMap
+ .get(baseClientId);
+ if (null != this._currentModel) {
+ this._rowKey = this._currentModel.getRowKey();
+ // restoreChildState();
+ }
+ // Restore value for row with submitted AjaxComponent.
+ this._ajaxRowKey = _ajaxRowKeysMap.get(baseClientId);
}
+ }
- private Object origValue;
+ private Object origValue;
- /**
- * Save current state of data variable.
- */
- public void captureOrigValue() {
- captureOrigValue(FacesContext.getCurrentInstance());
- }
+ /**
+ * Save current state of data variable.
+ */
+ public void captureOrigValue() {
+ captureOrigValue(FacesContext.getCurrentInstance());
+ }
- /**
- * Save current state of data variable.
- *
- * @param faces
- * current faces context
- */
- public void captureOrigValue(FacesContext faces) {
- String var = getVar();
- if (var != null) {
- Map attrs = faces.getExternalContext().getRequestMap();
- this.origValue = attrs.get(var);
- }
+ /**
+ * Save current state of data variable.
+ *
+ * @param faces
+ * current faces context
+ */
+ public void captureOrigValue(FacesContext faces) {
+ String var = getVar();
+ if (var != null) {
+ Map attrs = faces.getExternalContext().getRequestMap();
+ this.origValue = attrs.get(var);
}
+ }
- /**
- * Restore value of data variable after processing phase.
- */
- public void restoreOrigValue() {
- restoreOrigValue(FacesContext.getCurrentInstance());
- }
+ /**
+ * Restore value of data variable after processing phase.
+ */
+ public void restoreOrigValue() {
+ restoreOrigValue(FacesContext.getCurrentInstance());
+ }
- /**
- * Restore value of data variable after processing phase.
- *
- * @param faces
- * current faces context
- */
- public void restoreOrigValue(FacesContext faces) {
- String var = getVar();
- if (var != null) {
- Map attrs = faces.getExternalContext().getRequestMap();
- if (this.origValue != null) {
- attrs.put(var, this.origValue);
- } else {
- attrs.remove(var);
- }
- }
+ /**
+ * Restore value of data variable after processing phase.
+ *
+ * @param faces
+ * current faces context
+ */
+ public void restoreOrigValue(FacesContext faces) {
+ String var = getVar();
+ if (var != null) {
+ Map attrs = faces.getExternalContext().getRequestMap();
+ if (this.origValue != null) {
+ attrs.put(var, this.origValue);
+ } else {
+ attrs.remove(var);
+ }
}
+ }
- /**
- * Saved values of {@link EditableValueHolder} fields per iterations.
- */
- private Map childState;
+ /**
+ * Saved values of {@link EditableValueHolder} fields per iterations.
+ */
+ private Map childState;
- /**
- * @param faces
- * @return Saved values of {@link EditableValueHolder} fields per
- * iterations.
- */
- protected Map getChildState(FacesContext faces) {
- if (this.childState == null) {
- this.childState = new HashMap();
- }
- String baseClientId = getBaseClientId(faces);
- Map currentChildState = (Map) childState.get(baseClientId);
- if (null == currentChildState) {
- currentChildState = new HashMap();
- childState.put(baseClientId, currentChildState);
- }
- return currentChildState;
+ /**
+ * @param faces
+ * @return Saved values of {@link EditableValueHolder} fields per
+ * iterations.
+ */
+ protected Map getChildState(FacesContext faces) {
+ if (this.childState == null) {
+ this.childState = new HashMap();
}
+ String baseClientId = getBaseClientId(faces);
+ Map currentChildState = (Map) childState.get(baseClientId);
+ if (null == currentChildState) {
+ currentChildState = new HashMap();
+ childState.put(baseClientId, currentChildState);
+ }
+ return currentChildState;
+ }
- /**
- * Save values of {@link EditableValueHolder} fields before change current
- * row.
- *
- * @param faces
- */
- protected void saveChildState(FacesContext faces) {
+ /**
+ * Save values of {@link EditableValueHolder} fields before change
+ * current row.
+ *
+ * @param faces
+ */
+ protected void saveChildState(FacesContext faces) {
- Iterator itr = dataChildren();
- while (itr.hasNext()) {
- Map childState = this.getChildState(faces);
- this.saveChildState(faces, (UIComponent) itr.next(), childState);
- }
+ Iterator itr = dataChildren();
+ while (itr.hasNext()) {
+ Map childState = this.getChildState(faces);
+ this.saveChildState(faces, (UIComponent) itr.next(), childState);
}
+ }
- /**
- * Recursive method for Iterate on children for save
- * {@link EditableValueHolder} fields states.
- *
- * @param faces
- * @param c
- * @param childState
- */
- private void saveChildState(FacesContext faces, UIComponent c,
- Map childState) {
+ /**
+ * Recursive method for Iterate on children for save
+ * {@link EditableValueHolder} fields states.
+ *
+ * @param faces
+ * @param c
+ * @param childState
+ */
+ private void saveChildState(FacesContext faces, UIComponent c,
+ Map childState) {
- if (c instanceof EditableValueHolder && !c.isTransient()) {
- String clientId = c.getClientId(faces);
- SavedState ss = (SavedState) childState.get(clientId);
- if (ss == null) {
- ss = new SavedState();
- childState.put(clientId, ss);
- }
- ss.populate((EditableValueHolder) c);
- }
+ if (c instanceof EditableValueHolder && !c.isTransient()) {
+ String clientId = c.getClientId(faces);
+ SavedState ss = (SavedState) childState.get(clientId);
+ if (ss == null) {
+ ss = new SavedState();
+ childState.put(clientId, ss);
+ }
+ ss.populate((EditableValueHolder) c);
+ }
- // continue hack
- Iterator itr = c.getChildren().iterator();
- while (itr.hasNext()) {
- saveChildState(faces, (UIComponent) itr.next(), childState);
- }
- itr = c.getFacets().values().iterator();
- while (itr.hasNext()) {
- saveChildState(faces, (UIComponent) itr.next(), childState);
- }
+ // continue hack
+ Iterator itr = c.getChildren().iterator();
+ while (itr.hasNext()) {
+ saveChildState(faces, (UIComponent) itr.next(), childState);
}
+ itr = c.getFacets().values().iterator();
+ while (itr.hasNext()) {
+ saveChildState(faces, (UIComponent) itr.next(), childState);
+ }
+ }
- /**
- * Restore values of {@link EditableValueHolder} fields after change current
- * row.
- *
- * @param faces
- */
- protected void restoreChildState(FacesContext faces) {
+ /**
+ * Restore values of {@link EditableValueHolder} fields after change
+ * current row.
+ *
+ * @param faces
+ */
+ protected void restoreChildState(FacesContext faces) {
- Iterator itr = dataChildren();
- while (itr.hasNext()) {
- Map childState = this.getChildState(faces);
- this.restoreChildState(faces, (UIComponent) itr.next(), childState);
- }
+ Iterator itr = dataChildren();
+ while (itr.hasNext()) {
+ Map childState = this.getChildState(faces);
+ this.restoreChildState(faces, (UIComponent) itr.next(), childState);
}
+ }
- /**
- * Recursive part of
- * {@link #restoreChildState(FacesContext, UIComponent, Map)}
- *
- * @param faces
- * @param c
- * @param childState
- *
- */
- private void restoreChildState(FacesContext faces, UIComponent c,
- Map childState) {
- // reset id
- String id = c.getId();
- c.setId(id);
+ /**
+ * Recursive part of
+ * {@link #restoreChildState(FacesContext, UIComponent, Map)}
+ *
+ * @param faces
+ * @param c
+ * @param childState
+ *
+ */
+ private void restoreChildState(FacesContext faces, UIComponent c,
+ Map childState) {
+ // reset id
+ String id = c.getId();
+ c.setId(id);
- // hack
- if (c instanceof EditableValueHolder) {
- EditableValueHolder evh = (EditableValueHolder) c;
- String clientId = c.getClientId(faces);
- SavedState ss = (SavedState) childState.get(clientId);
- if (ss != null) {
- ss.apply(evh);
- } else {
- NullState.apply(evh);
- }
- }
-
- // continue hack
- Iterator itr = c.getChildren().iterator();
- while (itr.hasNext()) {
- restoreChildState(faces, (UIComponent) itr.next(), childState);
- }
- itr = c.getFacets().values().iterator();
- while (itr.hasNext()) {
- restoreChildState(faces, (UIComponent) itr.next(), childState);
- }
+ // hack
+ if (c instanceof EditableValueHolder) {
+ EditableValueHolder evh = (EditableValueHolder) c;
+ String clientId = c.getClientId(faces);
+ SavedState ss = (SavedState) childState.get(clientId);
+ if (ss != null) {
+ ss.apply(evh);
+ } else {
+ NullState.apply(evh);
+ }
}
- /**
- * Check for validation errors on children components. If true, saved values
- * must be keep on render phase
- *
- * @param context
- * @return
- */
- private boolean keepSaved(FacesContext context) {
-
- Iterator clientIds = this.getChildState(context).keySet().iterator();
- while (clientIds.hasNext()) {
- String clientId = (String) clientIds.next();
- Iterator messages = context.getMessages(clientId);
- while (messages.hasNext()) {
- FacesMessage message = (FacesMessage) messages.next();
- if (message.getSeverity()
- .compareTo(FacesMessage.SEVERITY_ERROR) >= 0) {
- return (true);
- }
- }
- }
- return false;
+ // continue hack
+ Iterator itr = c.getChildren().iterator();
+ while (itr.hasNext()) {
+ restoreChildState(faces, (UIComponent) itr.next(), childState);
}
+ itr = c.getFacets().values().iterator();
+ while (itr.hasNext()) {
+ restoreChildState(faces, (UIComponent) itr.next(), childState);
+ }
+ }
- /**
- * Perform iteration on all children components and all data rows with given
- * visitor.
- *
- * @param faces
- * @param visitor
- */
- protected void iterate(FacesContext faces, ComponentVisitor visitor,
- Object argument) {
+ /**
+ * Check for validation errors on children components. If true, saved
+ * values must be keep on render phase
+ *
+ * @param context
+ * @return
+ */
+ private boolean keepSaved(FacesContext context) {
- // stop if not rendered
- if (!this.isRendered()) {
- return;
+ Iterator clientIds = this.getChildState(context).keySet().iterator();
+ while (clientIds.hasNext()) {
+ String clientId = (String) clientIds.next();
+ Iterator messages = context.getMessages(clientId);
+ while (messages.hasNext()) {
+ FacesMessage message = (FacesMessage) messages.next();
+ if (message.getSeverity()
+ .compareTo(FacesMessage.SEVERITY_ERROR) >= 0) {
+ return (true);
}
- // reset rowIndex
- this.captureOrigValue(faces);
- this.setRowKey(faces, null);
- try {
- Iterator fixedChildren = fixedChildren();
- while (fixedChildren.hasNext()) {
- UIComponent component = (UIComponent) fixedChildren.next();
- visitor.processComponent(faces, component, argument);
- }
-
- walk(faces, visitor, argument);
- } catch (Exception e) {
- throw new FacesException(e);
- } finally {
- this.setRowKey(faces, null);
- this.restoreOrigValue(faces);
- }
+ }
}
+ return false;
+ }
- /**
- * Walk ( visit ) this component on all data-avare children for each row.
- *
- * @param faces
- * @param visitor
- * @throws IOException
- */
- public void walk(FacesContext faces, DataVisitor visitor, Object argument)
- throws IOException {
- getExtendedDataModel().walk(faces, visitor,
- getComponentState().getRange(), argument);
- }
+ /**
+ * Perform iteration on all children components and all data rows with
+ * given visitor.
+ *
+ * @param faces
+ * @param visitor
+ */
+ protected void iterate(FacesContext faces, ComponentVisitor visitor,
+ Object argument) {
- protected void processDecodes(FacesContext faces, Object argument) {
- if (!this.isRendered())
- return;
- this.resetComponent(faces);
- this.iterate(faces, decodeVisitor, argument);
- this.decode(faces);
+ // stop if not rendered
+ if (!this.isRendered()) {
+ return;
}
+ // reset rowIndex
+ this.captureOrigValue(faces);
+ this.setRowKey(faces, null);
+ try {
+ Iterator fixedChildren = fixedChildren();
+ while (fixedChildren.hasNext()) {
+ UIComponent component = (UIComponent) fixedChildren.next();
+ visitor.processComponent(faces, component, argument);
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.UIData#processDecodes(javax.faces.context.FacesContext)
- */
- public void processDecodes(FacesContext faces) {
- processDecodes(faces, null);
+ walk(faces, visitor, argument);
+ } catch (Exception e) {
+ throw new FacesException(e);
+ } finally {
+ this.setRowKey(faces, null);
+ this.restoreOrigValue(faces);
}
+ }
- /**
- * Reset per-request fields in component.
- *
- * @param faces
- *
- */
- protected void resetComponent(FacesContext faces) {
- // resetDataModel();
- if (null != this.childState) {
- childState.remove(getBaseClientId(faces));
- }
- this._encoded = null;
- }
+ /**
+ * Walk ( visit ) this component on all data-avare children for each
+ * row.
+ *
+ * @param faces
+ * @param visitor
+ * @throws IOException
+ */
+ public void walk(FacesContext faces, DataVisitor visitor, Object argument)
+ throws IOException {
+ getExtendedDataModel().walk(faces, visitor,
+ getComponentState().getRange(), argument);
+ }
- protected void processUpdates(FacesContext faces, Object argument) {
- if (!this.isRendered())
- return;
- this.iterate(faces, updateVisitor, argument);
- ExtendedDataModel dataModel = getExtendedDataModel();
- // If no validation errors, update values for serializable model,
- // restored from view.
- if (dataModel instanceof SerializableDataModel && (!keepSaved(faces))) {
- SerializableDataModel serializableModel = (SerializableDataModel) dataModel;
- serializableModel.update();
- }
- }
+ protected void processDecodes(FacesContext faces, Object argument) {
+ if (!this.isRendered())
+ return;
+ this.resetComponent(faces);
+ this.iterate(faces, decodeVisitor, argument);
+ this.decode(faces);
+ }
- public void processUpdates(FacesContext faces) {
- processUpdates(faces, null);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIData#processDecodes(javax.faces.context.FacesContext)
+ */
+ public void processDecodes(FacesContext faces) {
+ processDecodes(faces, null);
+ }
- protected void processValidators(FacesContext faces, Object argument) {
- if (!this.isRendered())
- return;
- this.iterate(faces, validateVisitor, argument);
+ /**
+ * Reset per-request fields in component.
+ *
+ * @param faces
+ *
+ */
+ protected void resetComponent(FacesContext faces) {
+ // resetDataModel();
+ if (null != this.childState) {
+ childState.remove(getBaseClientId(faces));
}
+ this._encoded = null;
+ }
- public void processValidators(FacesContext faces) {
- processValidators(faces, null);
+ protected void processUpdates(FacesContext faces, Object argument) {
+ if (!this.isRendered())
+ return;
+ this.iterate(faces, updateVisitor, argument);
+ ExtendedDataModel dataModel = getExtendedDataModel();
+ // If no validation errors, update values for serializable model,
+ // restored from view.
+ if (dataModel instanceof SerializableDataModel && (!keepSaved(faces))) {
+ SerializableDataModel serializableModel = (SerializableDataModel) dataModel;
+ serializableModel.update();
}
+ }
- public void encodeBegin(FacesContext context) throws IOException {
- resetDataModel();
- // if(!keepSaved(context)){
- // childState.remove(getBaseClientId(context));
- // }
- // Mark component as used, if parent UIData change own range states not
- // accessed at
- // encode phase must be unsaved.
- getEncodedIds().add(getBaseClientId(context));
- // getComponentState().setUsed(true);
- super.encodeBegin(context);
- }
+ public void processUpdates(FacesContext faces) {
+ processUpdates(faces, null);
+ }
- /**
- * This method must create iterator for all non-data avare children of this
- * component ( header/footer facets for components and columns in dataTable,
- * facets for tree etc.
- *
- * @return iterator for all components not sensitive for row data.
- */
- protected abstract Iterator fixedChildren();
+ protected void processValidators(FacesContext faces, Object argument) {
+ if (!this.isRendered())
+ return;
+ this.iterate(faces, validateVisitor, argument);
+ }
- /**
- * This method must create iterator for all children components, processed
- * "per row" It can be children of UIColumn in dataTable, nodes in tree
- *
- * @return iterator for all components processed per row.
- */
- protected abstract Iterator dataChildren();
+ public void processValidators(FacesContext faces) {
+ processValidators(faces, null);
+ }
- private final static SavedState NullState = new SavedState();
+ public void encodeBegin(FacesContext context) throws IOException {
+ resetDataModel();
+ // if(!keepSaved(context)){
+ // childState.remove(getBaseClientId(context));
+ // }
+ // Mark component as used, if parent UIData change own range states not
+ // accessed at
+ // encode phase must be unsaved.
+ getEncodedIds().add(getBaseClientId(context));
+ // getComponentState().setUsed(true);
+ super.encodeBegin(context);
+ }
- // from RI
- /**
- * This class keep values of {@link EditableValueHolder} row-sensitive
- * fields.
- *
- * @author shura
- *
- */
- private final static class SavedState implements Serializable {
+ /**
+ * This method must create iterator for all non-data avare children of
+ * this component ( header/footer facets for components and columns in
+ * dataTable, facets for tree etc.
+ *
+ * @return iterator for all components not sensitive for row data.
+ */
+ protected abstract Iterator fixedChildren();
- private Object submittedValue;
+ /**
+ * This method must create iterator for all children components,
+ * processed "per row" It can be children of UIColumn in dataTable,
+ * nodes in tree
+ *
+ * @return iterator for all components processed per row.
+ */
+ protected abstract Iterator dataChildren();
- private static final long serialVersionUID = 2920252657338389849L;
+ private final static SavedState NullState = new SavedState();
- Object getSubmittedValue() {
- return (this.submittedValue);
- }
+ // from RI
+ /**
+ * This class keep values of {@link EditableValueHolder} row-sensitive
+ * fields.
+ *
+ * @author shura
+ *
+ */
+ private final static class SavedState implements Serializable {
- void setSubmittedValue(Object submittedValue) {
- this.submittedValue = submittedValue;
- }
+ private Object submittedValue;
- private boolean valid = true;
+ private static final long serialVersionUID = 2920252657338389849L;
- boolean isValid() {
- return (this.valid);
- }
+ Object getSubmittedValue() {
+ return (this.submittedValue);
+ }
- void setValid(boolean valid) {
- this.valid = valid;
- }
+ void setSubmittedValue(Object submittedValue) {
+ this.submittedValue = submittedValue;
+ }
- private Object value;
+ private boolean valid = true;
- Object getValue() {
- return (this.value);
- }
+ boolean isValid() {
+ return (this.valid);
+ }
- public void setValue(Object value) {
- this.value = value;
- }
+ void setValid(boolean valid) {
+ this.valid = valid;
+ }
- private boolean localValueSet;
+ private Object value;
- boolean isLocalValueSet() {
- return (this.localValueSet);
- }
+ Object getValue() {
+ return (this.value);
+ }
- public void setLocalValueSet(boolean localValueSet) {
- this.localValueSet = localValueSet;
- }
+ public void setValue(Object value) {
+ this.value = value;
+ }
- public String toString() {
- return ("submittedValue: " + submittedValue + " value: " + value
- + " localValueSet: " + localValueSet);
- }
+ private boolean localValueSet;
- public void populate(EditableValueHolder evh) {
- this.value = evh.getLocalValue();
- this.valid = evh.isValid();
- this.submittedValue = evh.getSubmittedValue();
- this.localValueSet = evh.isLocalValueSet();
- }
+ boolean isLocalValueSet() {
+ return (this.localValueSet);
+ }
- public void apply(EditableValueHolder evh) {
- evh.setValue(this.value);
- evh.setValid(this.valid);
- evh.setSubmittedValue(this.submittedValue);
- evh.setLocalValueSet(this.localValueSet);
- }
+ public void setLocalValueSet(boolean localValueSet) {
+ this.localValueSet = localValueSet;
+ }
+ public String toString() {
+ return ("submittedValue: " + submittedValue + " value: " + value
+ + " localValueSet: " + localValueSet);
}
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.component.UIData#queueEvent(javax.faces.event.FacesEvent)
- */
- public void queueEvent(FacesEvent event) {
- if (event.getComponent() != this) {
- event = new IndexedEvent(this, event, getRowKey());
- }
- // Send event directly to parent, to avoid wrapping in superclass.
- UIComponent parent = getParent();
- if (parent == null) {
- throw new IllegalStateException(
- "No parent component for queue event");
- } else {
- parent.queueEvent(event);
- }
+ public void populate(EditableValueHolder evh) {
+ this.value = evh.getLocalValue();
+ this.valid = evh.isValid();
+ this.submittedValue = evh.getSubmittedValue();
+ this.localValueSet = evh.isLocalValueSet();
}
- public void broadcast(FacesEvent event) throws AbortProcessingException {
+ public void apply(EditableValueHolder evh) {
+ evh.setValue(this.value);
+ evh.setValid(this.valid);
+ evh.setSubmittedValue(this.submittedValue);
+ evh.setLocalValueSet(this.localValueSet);
+ }
- if (!(event instanceof IndexedEvent)) {
- if (!broadcastLocal(event)) {
- super.broadcast(event);
- }
- return;
- }
+ }
- // Set up the correct context and fire our wrapped event
- IndexedEvent revent = (IndexedEvent) event;
- Object oldRowKey = getRowKey();
- FacesContext faces = FacesContext.getCurrentInstance();
- captureOrigValue(faces);
- setRowKey(faces, revent.getKey());
- FacesEvent rowEvent = revent.getTarget();
- rowEvent.getComponent().broadcast(rowEvent);
- // For Ajax events, keep row value.
-// if (!(rowEvent instanceof AjaxEvent)) {
- setRowKey(faces, oldRowKey);
- restoreOrigValue(faces);
-// }
- return;
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIData#queueEvent(javax.faces.event.FacesEvent)
+ */
+ public void queueEvent(FacesEvent event) {
+ if (event.getComponent() != this) {
+ event = new IndexedEvent(this, event, getRowKey());
}
+ // Send event directly to parent, to avoid wrapping in superclass.
+ UIComponent parent = getParent();
+ if (parent == null) {
+ throw new IllegalStateException(
+ "No parent component for queue event");
+ } else {
+ parent.queueEvent(event);
+ }
+ }
- /**
- * Process events targetted for concrete implementation. Hook method called
- * from {@link #broadcast(FacesEvent)}
- *
- * @param event -
- * processed event.
- * @return true if event processed, false if component must continue
- * processing.
- */
- protected boolean broadcastLocal(FacesEvent event) {
- return false;
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+
+ if (!(event instanceof IndexedEvent)) {
+ if (!broadcastLocal(event)) {
+ super.broadcast(event);
+ }
+ return;
}
- /**
- * Wrapper for event from child component, with value of current row key.
- *
- * @author shura
- *
- */
- protected static final class IndexedEvent extends FacesEvent {
+ // Set up the correct context and fire our wrapped event
+ IndexedEvent revent = (IndexedEvent) event;
+ Object oldRowKey = getRowKey();
+ FacesContext faces = FacesContext.getCurrentInstance();
+ captureOrigValue(faces);
+ Object eventRowKey = revent.getKey();
+ setRowKey(faces, eventRowKey);
+ FacesEvent rowEvent = revent.getTarget();
+ rowEvent.getComponent().broadcast(rowEvent);
+ // For Ajax events, keep row value.
+ if (!(rowEvent.getPhaseId() == PhaseId.RENDER_RESPONSE)) {
+ this._ajaxRowKey = eventRowKey;
+ this._ajaxRowKeysMap.put(getBaseClientId(faces), eventRowKey);
+ }
+ setRowKey(faces, oldRowKey);
+ restoreOrigValue(faces);
+ // }
+ return;
+ }
- private static final long serialVersionUID = -8318895390232552385L;
+ /**
+ * Process events targetted for concrete implementation. Hook method
+ * called from {@link #broadcast(FacesEvent)}
+ *
+ * @param event -
+ * processed event.
+ * @return true if event processed, false if component must continue
+ * processing.
+ */
+ protected boolean broadcastLocal(FacesEvent event) {
+ return false;
+ }
- private final FacesEvent target;
+ /**
+ * Wrapper for event from child component, with value of current row
+ * key.
+ *
+ * @author shura
+ *
+ */
+ protected static final class IndexedEvent extends FacesEvent {
- private final Object key;
+ private static final long serialVersionUID = -8318895390232552385L;
- public IndexedEvent(UIDataAdaptor owner, FacesEvent target, Object key) {
- super(owner);
- this.target = target;
- this.key = key;
- }
+ private final FacesEvent target;
- public PhaseId getPhaseId() {
- return (this.target.getPhaseId());
- }
+ private final Object key;
- public void setPhaseId(PhaseId phaseId) {
- this.target.setPhaseId(phaseId);
- }
+ public IndexedEvent(UIDataAdaptor owner, FacesEvent target, Object key) {
+ super(owner);
+ this.target = target;
+ this.key = key;
+ }
- public boolean isAppropriateListener(FacesListener listener) {
- return this.target.isAppropriateListener(listener);
- }
+ public PhaseId getPhaseId() {
+ return (this.target.getPhaseId());
+ }
- public void processListener(FacesListener listener) {
- UIDataAdaptor owner = (UIDataAdaptor) this.getComponent();
- Object prevIndex = owner._rowKey;
- try {
- owner.setRowKey(this.key);
- this.target.processListener(listener);
- } finally {
- owner.setRowKey(prevIndex);
- }
- }
+ public void setPhaseId(PhaseId phaseId) {
+ this.target.setPhaseId(phaseId);
+ }
- public Object getKey() {
- return key;
- }
+ public boolean isAppropriateListener(FacesListener listener) {
+ return this.target.isAppropriateListener(listener);
+ }
- public FacesEvent getTarget() {
- return target;
- }
+ public void processListener(FacesListener listener) {
+ UIDataAdaptor owner = (UIDataAdaptor) this.getComponent();
+ Object prevIndex = owner._rowKey;
+ try {
+ owner.setRowKey(this.key);
+ this.target.processListener(listener);
+ } finally {
+ owner.setRowKey(prevIndex);
+ }
+ }
+ public Object getKey() {
+ return key;
}
+ public FacesEvent getTarget() {
+ return target;
+ }
+
+ }
+
+ /**
+ * "memento" pattern class for state of component.
+ *
+ * @author shura
+ *
+ */
+ private static class DataState implements Serializable {
+
/**
- * "memento" pattern class for state of component.
- *
- * @author shura
- *
- */
- private static class DataState implements Serializable {
+ *
+ */
+ private static final long serialVersionUID = 17070532L;
- /**
- *
- */
- private static final long serialVersionUID = 17070532L;
+ private Object superState;
- private Object superState;
+ private Map componentStates = new HashMap();
- private Map componentStates = new HashMap();
+ private Set ajaxKeys;
- private Set ajaxKeys;
+ }
- }
+ /**
+ * Serialisable model and component state per iteration of parent
+ * UIData.
+ *
+ * @author shura
+ *
+ */
+ private static class PerIdState implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 9037454770537726418L;
/**
- * Serialisable model and component state per iteration of parent UIData.
- *
- * @author shura
- *
- */
- private static class PerIdState implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 9037454770537726418L;
+ * Flag setted to true if componentState implements StateHolder
+ */
+ private boolean stateInHolder = false;
- /**
- * Flag setted to true if componentState implements StateHolder
- */
- private boolean stateInHolder = false;
+ /**
+ * Serializable componentState or
+ */
+ private Object componentState;
- /**
- * Serializable componentState or
- */
- private Object componentState;
+ private SerializableDataModel model;
+ }
- private SerializableDataModel model;
+ public void restoreState(FacesContext faces, Object object) {
+ DataState state = (DataState) object;
+ super.restoreState(faces, state.superState);
+ this._ajaxKeys = state.ajaxKeys;
+ this._statesMap = new HashMap();
+ // Restore serializable models and component states for all rows of
+ // parent UIData ( single if this
+ // component not child of iterable )
+ for (Iterator iter = state.componentStates.entrySet().iterator(); iter
+ .hasNext();) {
+ Map.Entry stateEntry = (Map.Entry) iter.next();
+ PerIdState idState = (PerIdState) stateEntry.getValue();
+ DataComponentState compState;
+ if (idState.stateInHolder) {
+ // TODO - change RichFaces Tree component, for remove reference
+ // to component from state.
+ compState = createComponentState();
+ ((StateHolder) compState).restoreState(faces,
+ idState.componentState);
+ } else {
+ compState = (DataComponentState) idState.componentState;
+ }
+ Object key = stateEntry.getKey();
+ this._statesMap.put(key, compState);
+ this._modelsMap.put(key, idState.model);
}
+ }
- public void restoreState(FacesContext faces, Object object) {
- DataState state = (DataState) object;
- super.restoreState(faces, state.superState);
- this._ajaxKeys = state.ajaxKeys;
- this._statesMap = new HashMap();
- // Restore serializable models and component states for all rows of
- // parent UIData ( single if this
- // component not child of iterable )
- for (Iterator iter = state.componentStates.entrySet().iterator(); iter
- .hasNext();) {
- Map.Entry stateEntry = (Map.Entry) iter.next();
- PerIdState idState = (PerIdState) stateEntry.getValue();
- DataComponentState compState;
- if (idState.stateInHolder) {
- // TODO - change RichFaces Tree component, for remove reference
- // to component from state.
- compState = createComponentState();
- ((StateHolder) compState).restoreState(faces,
- idState.componentState);
- } else {
- compState = (DataComponentState) idState.componentState;
- }
- Object key = stateEntry.getKey();
- this._statesMap.put(key, compState);
- this._modelsMap.put(key, idState.model);
+ public Object saveState(FacesContext faces) {
+ DataState state = new DataState();
+ state.superState = super.saveState(faces);
+ state.ajaxKeys = this._ajaxKeys;
+ Set encodedIds = getEncodedIds();
+ // Save all states of component and data model for all valies of
+ // clientId, encoded in this request.
+ for (Iterator iter = this._statesMap.entrySet().iterator(); iter
+ .hasNext();) {
+ Map.Entry stateEntry = (Map.Entry) iter.next();
+ DataComponentState dataComponentState = ((DataComponentState) stateEntry
+ .getValue());
+ Object stateKey = stateEntry.getKey();
+ if (encodedIds.isEmpty() || encodedIds.contains(stateKey)) {
+ PerIdState idState = new PerIdState();
+ idState.model = getExtendedDataModel().getSerializableModel(
+ dataComponentState.getRange());
+ // Save component state , depended if implemented interfaces.
+ if (null == dataComponentState) {
+ idState.componentState = null;
+ } else if (dataComponentState instanceof Serializable) {
+ idState.componentState = dataComponentState;
+ } else if (dataComponentState instanceof StateHolder) {
+ // TODO - change RichFaces Tree component, for remove
+ // reference to component from state.
+ // Change this code to reference for saveAttachedState.
+ idState.componentState = ((StateHolder) dataComponentState)
+ .saveState(faces);
+ idState.stateInHolder = true;
}
- }
-
- public Object saveState(FacesContext faces) {
- DataState state = new DataState();
- state.superState = super.saveState(faces);
- state.ajaxKeys = this._ajaxKeys;
- Set encodedIds = getEncodedIds();
- // Save all states of component and data model for all valies of
- // clientId, encoded in this request.
- for (Iterator iter = this._statesMap.entrySet().iterator(); iter
- .hasNext();) {
- Map.Entry stateEntry = (Map.Entry) iter.next();
- DataComponentState dataComponentState = ((DataComponentState) stateEntry
- .getValue());
- Object stateKey = stateEntry.getKey();
- if (encodedIds.isEmpty() || encodedIds.contains(stateKey)) {
- PerIdState idState = new PerIdState();
- idState.model = getExtendedDataModel().getSerializableModel(
- dataComponentState.getRange());
- // Save component state , depended if implemented interfaces.
- if (null == dataComponentState) {
- idState.componentState = null;
- } else if (dataComponentState instanceof Serializable) {
- idState.componentState = dataComponentState;
- } else if (dataComponentState instanceof StateHolder) {
- // TODO - change RichFaces Tree component, for remove
- // reference to component from state.
- // Change this code to reference for saveAttachedState.
- idState.componentState = ((StateHolder) dataComponentState)
- .saveState(faces);
- idState.stateInHolder = true;
- }
- if (null != idState.model || null != idState.componentState) {
- state.componentStates.put(stateKey, idState);
- }
- }
+ if (null != idState.model || null != idState.componentState) {
+ state.componentStates.put(stateKey, idState);
}
- return state;
+ }
}
+ return state;
+ }
}
Modified: trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UISelector.java
===================================================================
--- trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UISelector.java 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UISelector.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -90,7 +90,7 @@
Object key = (Object) iter.next();
PropertyUtils.setProperty(child, iterationProperty, key);
if (true) {
- childrenRenderer.encodeAjaxChild(context, this, path,
+ childrenRenderer.encodeAjaxChildren(context, this, path,
ids, renderedAreas);
}
Modified: trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/AjaxActionComponent.java
===================================================================
--- trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/AjaxActionComponent.java 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/AjaxActionComponent.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -22,6 +22,7 @@
package org.ajax4jsf.framework.ajax;
import javax.faces.component.UICommand;
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
@@ -30,98 +31,114 @@
import org.ajax4jsf.framework.renderer.AjaxRendererUtils;
-
/**
* @author shura (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1.2.3 $ $Date: 2007/02/06 16:23:21 $
- *
+ *
*/
-public abstract class AjaxActionComponent extends UICommand implements
- AjaxComponent, AjaxSource {
-
- /* (non-Javadoc)
- * @see javax.faces.component.UIComponentBase#broadcast(javax.faces.event.FacesEvent)
- */
- public void broadcast(FacesEvent event) throws AbortProcessingException {
- // perform default
- super.broadcast(event);
- if (event instanceof AjaxEvent) {
- FacesContext context = getFacesContext();
- // complete re-Render fields. AjaxEvent deliver before render response.
- setupReRender(context);
- // Put data for send in response
- Object data = getData();
- if(null != data){
- AjaxContext.getCurrentInstance(context).setResponseData(data);
- }
- }
- }
+public abstract class AjaxActionComponent extends UICommand implements
+ AjaxComponent, AjaxSource {
+ public static final String FOCUS_DATA_ID = "_A4J.AJAX.focus";
- /**
- * Template method with old signature, for backward compability.
- */
- protected void setupReRender(){
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIComponentBase#broadcast(javax.faces.event.FacesEvent)
+ */
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ // perform default
+ super.broadcast(event);
+ if (event instanceof AjaxEvent) {
+ FacesContext context = getFacesContext();
+ // complete re-Render fields. AjaxEvent deliver before render
+ // response.
+ setupReRender(context);
+ // Put data for send in response
+ Object data = getData();
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ if (null != data) {
+ ajaxContext.setResponseData(data);
+ }
+ String focus = getFocus();
+ if (null != focus) {
+ // search for component in tree.
+ // TODO - use more pourful search, as in h:outputLabel component.
+ UIComponent focusComponent = findComponent(focus);
+ if(null != focusComponent){
+ focus = focusComponent.getClientId(context);
+ }
+ ajaxContext.getResponseDataMap().put(FOCUS_DATA_ID, focus);
+ }
}
-
- /**
- * Template methods for fill set of resions to render in subclasses.
- * @param facesContext TODO
- */
- protected void setupReRender(FacesContext facesContext) {
- AjaxContext.getCurrentInstance(facesContext).addRegionsFromComponent(this);
- setupReRender();
- }
+ }
+ /**
+ * Template method with old signature, for backward compability.
+ */
+ protected void setupReRender() {
+ }
- /* (non-Javadoc)
- * @see javax.faces.component.UIComponentBase#queueEvent(javax.faces.event.FacesEvent)
- */
- public void queueEvent(FacesEvent event) {
- if (event instanceof ActionEvent && event.getComponent()==this) {
- if (isImmediate()) {
- event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
- } else if (isBypassUpdates()) {
- event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
- }else {
- event.setPhaseId(PhaseId.INVOKE_APPLICATION);
- }
- getParent().queueEvent(event);
- } else {
- super.queueEvent(event);
- }
- }
+ /**
+ * Template methods for fill set of resions to render in subclasses.
+ *
+ * @param facesContext
+ * TODO
+ */
+ protected void setupReRender(FacesContext facesContext) {
+ AjaxContext.getCurrentInstance(facesContext).addRegionsFromComponent(
+ this);
+ setupReRender();
+ }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.AjaxSource#addAjaxListener(org.ajax4jsf.framework.ajax.AjaxListener)
- */
- public void addAjaxListener(AjaxListener listener) {
- addFacesListener(listener);
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIComponentBase#queueEvent(javax.faces.event.FacesEvent)
+ */
+ public void queueEvent(FacesEvent event) {
+ if (event instanceof ActionEvent && event.getComponent() == this) {
+ if (isImmediate()) {
+ event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+ } else if (isBypassUpdates()) {
+ event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
+ } else {
+ event.setPhaseId(PhaseId.INVOKE_APPLICATION);
+ }
+ getParent().queueEvent(event);
+ } else {
+ super.queueEvent(event);
}
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.AjaxSource#addAjaxListener(org.ajax4jsf.framework.ajax.AjaxListener)
+ */
+ public void addAjaxListener(AjaxListener listener) {
+ addFacesListener(listener);
+ }
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.AjaxSource#getAjaxListeners()
- */
- public AjaxListener[] getAjaxListeners() {
- AjaxListener al[] = (AjaxListener [])
- getFacesListeners(AjaxListener.class);
- return (al);
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.AjaxSource#getAjaxListeners()
+ */
+ public AjaxListener[] getAjaxListeners() {
+ AjaxListener al[] = (AjaxListener[]) getFacesListeners(AjaxListener.class);
+ return (al);
- }
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.AjaxSource#removeAjaxListener(org.ajax4jsf.framework.ajax.AjaxListener)
+ */
+ public void removeAjaxListener(AjaxListener listener) {
+ removeFacesListener(listener);
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.AjaxSource#removeAjaxListener(org.ajax4jsf.framework.ajax.AjaxListener)
- */
- public void removeAjaxListener(AjaxListener listener) {
- removeFacesListener(listener);
-
- }
+ }
-
-
-
-
}
Modified: trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/AjaxComponent.java
===================================================================
--- trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/AjaxComponent.java 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/AjaxComponent.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -178,5 +178,17 @@
* @param timeout new value in ms.
*/
public abstract void setTimeout(int timeout);
+
+
+ /**
+ * Setter for a 'focus' bean property - id of component( or of DOM element ), to set focus after AJAX request.
+ * @param focus
+ */
+ public abstract void setFocus(String focus);
+
+ /**
+ * @return
+ */
+ public abstract String getFocus();
}
\ No newline at end of file
Modified: trunk/framework/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java
===================================================================
--- trunk/framework/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/framework/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -63,8 +63,27 @@
* @param ids -
* list of Id to render.
* @throws IOException
+ * @deprecated Use {@link #encodeAjaxChildren(FacesContext,UIComponent,String,Set,Set)} instead
*/
public void encodeAjaxChild(FacesContext context, UIComponent component, String path, Set ids, Set renderedAreas) throws IOException {
+ encodeAjaxChildren(context, component, path, ids, renderedAreas);
+ }
+
+ /**
+ * Iterate over all childs of components. If component id contains in list ,
+ * or, if list is empty, compotents is submitted form - render it. TODO -
+ * Instead of calculate full path for every component, build current Path
+ * for componet and send as parameter.
+ *
+ * @param context -
+ * current context
+ * @param component -
+ * curent faces component.
+ * @param ids -
+ * list of Id to render.
+ * @throws IOException
+ */
+ public void encodeAjaxChildren(FacesContext context, UIComponent component, String path, Set ids, Set renderedAreas) throws IOException {
if (log.isDebugEnabled()) {
log.debug(Messages.getMessage(Messages.ENCODE_CHILD_AJAX_INFO,
path, component.getId()));
@@ -74,62 +93,74 @@
currentPath += component.getId() + NamingContainer.SEPARATOR_CHAR;
}
for (Iterator it = component.getFacetsAndChildren(); it.hasNext();) {
- boolean found = false;
UIComponent element = (UIComponent) it.next();
- if (element.isRendered()) { // skip not-rendered components.
- if (!ids.isEmpty()) {
- // list for rendering may contains absolute id ( best ),
- // component Id or client ID
- String elementId = element.getId();
- String absoluteId = currentPath + elementId;
- // String clientId = element.getClientId(context);
- if (ids.contains(absoluteId) || ids.contains(elementId)) {
- if (log.isDebugEnabled()) {
- log
- .debug(Messages.getMessage(
- Messages.RENDER_AJAX_AREA_INFO,
- absoluteId));
- }
- // renderChild(context, element);
- found = true;
- }
- }
- if (element instanceof AjaxOutput) {
- if (((AjaxOutput) element).isAjaxRendered()) {
- // renderChild(context, element);
- found = true;
- }
-
- }
-
- if (!found) {
- if (element instanceof AjaxChildrenEncoder) {
- ((AjaxChildrenEncoder) element).encodeAjaxChild(
- context, currentPath, ids, renderedAreas);
- } else {
- // Special case - for control components, not produced
- // html code - such as message bundles loaders,
- // MyFaces aliases etc. we call encodeBegin/end methods
- // even if components not in rendered areas.
- boolean special = isSpecialElement(context, element);
- if (special) {
- element.encodeBegin(context);
- }
- encodeAjaxChild(context, element, currentPath, ids,
- renderedAreas);
- if (special) {
- element.encodeEnd(context);
- }
-
- }
- } else {
- renderedAreas.add(element.getClientId(context));
- renderChild(context, element);
- }
- }
+ encodeAjaxComponent(context, element, currentPath, ids, renderedAreas);
}
}
+ /**
+ * @param context
+ * @param component
+ * @param currentPath
+ * @param ids
+ * @param renderedAreas
+ * @throws IOException
+ */
+ public void encodeAjaxComponent(FacesContext context, UIComponent component, String currentPath, Set ids, Set renderedAreas) throws IOException {
+ if (component.isRendered()) { // skip not-rendered components.
+ boolean found = false;
+ if (!ids.isEmpty()) {
+ // list for rendering may contains absolute id ( best ),
+ // component Id or client ID
+ String elementId = component.getId();
+ String absoluteId = currentPath + elementId;
+ // String clientId = element.getClientId(context);
+ if (ids.contains(absoluteId) || ids.contains(elementId)) {
+ if (log.isDebugEnabled()) {
+ log
+ .debug(Messages.getMessage(
+ Messages.RENDER_AJAX_AREA_INFO,
+ absoluteId));
+ }
+ // renderChild(context, element);
+ found = true;
+ }
+ }
+ if (!found && component instanceof AjaxOutput) {
+ if (((AjaxOutput) component).isAjaxRendered()) {
+ // renderChild(context, element);
+ found = true;
+ }
+
+ }
+
+ if (!found) {
+ if (component instanceof AjaxChildrenEncoder) {
+ ((AjaxChildrenEncoder) component).encodeAjaxChild(
+ context, currentPath, ids, renderedAreas);
+ } else {
+ // Special case - for control components, not produced
+ // html code - such as message bundles loaders,
+ // MyFaces aliases etc. we call encodeBegin/end methods
+ // even if components not in rendered areas.
+ boolean special = isSpecialElement(context, component);
+ if (special) {
+ component.encodeBegin(context);
+ }
+ encodeAjaxChildren(context, component, currentPath, ids,
+ renderedAreas);
+ if (special) {
+ component.encodeEnd(context);
+ }
+
+ }
+ } else {
+ renderedAreas.add(component.getClientId(context));
+ renderChild(context, component);
+ }
+ }
+ }
+
private Set _specialComponentTypes = null;
/**
Modified: trunk/framework/src/main/java/org/ajax4jsf/framework/renderer/AjaxContainerRenderer.java
===================================================================
--- trunk/framework/src/main/java/org/ajax4jsf/framework/renderer/AjaxContainerRenderer.java 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/framework/src/main/java/org/ajax4jsf/framework/renderer/AjaxContainerRenderer.java 2007-04-14 00:39:00 UTC (rev 85)
@@ -122,7 +122,7 @@
// if(! (component instanceof NamingContainer)){
path = path.substring(0, path
.lastIndexOf(NamingContainer.SEPARATOR_CHAR) + 1);
- encodeAjaxChild(context, root, path, ids, renderedAreas);
+ encodeAjaxComponent(context, root, path, ids, renderedAreas);
// Write information about encoded areas after submission.
AjaxRendererUtils.encodeAreas(context, component);
}
Modified: trunk/framework/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- trunk/framework/src/main/javascript/ajaxjsf/JSFAJAX.js 2007-04-14 00:37:54 UTC (rev 84)
+++ trunk/framework/src/main/javascript/ajaxjsf/JSFAJAX.js 2007-04-14 00:39:00 UTC (rev 85)
@@ -661,7 +661,25 @@
listener.onafterajax(req,req.domEvt,data);
}
}
-
+ // Set focus, if nessesary.
+ var responseFocus = req.getElementById("_A4J.AJAX.focus");
+ if(responseFocus){
+ var focusId = Sarissa.getText(responseFocus,true);
+ var focusElement=false;
+ if(req.form){
+ // Attempt to get form control for name. By Richfaces naming convensions,
+ // complex component must set clientId as DOM id for a root element ,
+ // and as input element name.
+ focusElement = req.form.elements[focusId];
+ }
+ if(!focusElement){
+ // If not found as control element, search in DOM.
+ focusElement = document.getElementById(focusId);
+ }
+ if(focusElement){
+ focusElement.focus();
+ }
+ }
} else {
// No response XML
LOG.error( "Error parsing XML" );
17 years, 8 months
JBoss Ajax4JSF SVN: r84 - in trunk/cdk/generator/src/main: java/org/ajax4jsf/builder/generator and 2 other directories.
by ajax4jsf-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-13 20:37:54 -0400 (Fri, 13 Apr 2007)
New Revision: 84
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBean.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TagBean.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TestClassHolder.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentTestGenerator.java
trunk/cdk/generator/src/main/resources/META-INF/schema/component-config.dtd
trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm
Log:
Test generation enhanced:
- classname & superclassname in tests can be made optional with reasonal defaults
- dangerous tests commented for now
- 2 quick & dirty test data sets implemented for now
- component getters tests implemented. El things & javax.faces.* stuff skipped for now
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBean.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBean.java 2007-04-13 18:57:52 UTC (rev 83)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBean.java 2007-04-14 00:37:54 UTC (rev 84)
@@ -398,4 +398,15 @@
}
return false;
}
+
+ @Override
+ public TestClassHolder getTest() {
+ return super.getTest();
+ }
+
+ @Override
+ public void setTest(TestClassHolder test) {
+ super.setTest(test);
+ test.setClassname(getClassname() + "ComponentTest");
+ }
}
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TagBean.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TagBean.java 2007-04-13 18:57:52 UTC (rev 83)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TagBean.java 2007-04-14 00:37:54 UTC (rev 84)
@@ -81,4 +81,14 @@
this._generate = generate;
}
+ @Override
+ public void setTest(TestClassHolder test) {
+ super.setTest(test);
+ test.setClassname(getClassname() + "TagTest");
+ }
+
+ @Override
+ public TestClassHolder getTest() {
+ return super.getTest();
+ }
}
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TestClassHolder.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TestClassHolder.java 2007-04-13 18:57:52 UTC (rev 83)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TestClassHolder.java 2007-04-14 00:37:54 UTC (rev 84)
@@ -9,7 +9,7 @@
private String _classname;
- private String _superclassname;
+ private String _superclassname = "org.ajax4jsf.tests.AbstractAjax4JsfTestCase";
public String getClassname() {
return _classname;
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentTestGenerator.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentTestGenerator.java 2007-04-13 18:57:52 UTC (rev 83)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentTestGenerator.java 2007-04-14 00:37:54 UTC (rev 84)
@@ -28,6 +28,9 @@
VelocityContext context = new VelocityContext();
Template template = getTemplate();
context.put("generator",this);
+
+ context.put("testDataGenerator", new TestDataGenerator(getClassLoader(), getLog()));
+
// Put common properties
for (Iterator iter = config.iterator(); iter.hasNext();) {
ComponentBean component = (ComponentBean) iter.next();
Modified: trunk/cdk/generator/src/main/resources/META-INF/schema/component-config.dtd
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/schema/component-config.dtd 2007-04-13 18:57:52 UTC (rev 83)
+++ trunk/cdk/generator/src/main/resources/META-INF/schema/component-config.dtd 2007-04-14 00:37:54 UTC (rev 84)
@@ -48,7 +48,7 @@
bodyContent (JSP|empty) "JSP"
>
-<!ELEMENT test (classname,superclassname)>
+<!ELEMENT test (classname?,superclassname?)>
<!--!ELEMENT classname (#PCDATA)-->
<!ELEMENT superclassname (#PCDATA)>
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm 2007-04-13 18:57:52 UTC (rev 83)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm 2007-04-14 00:37:54 UTC (rev 84)
@@ -33,6 +33,9 @@
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.component.UIViewRoot;
+
+import org.ajax4jsf.tests.MockValueBinding;
+
//import ${component.classname};
#if(${generator.key})
@@ -81,12 +84,8 @@
component.setId("component");
#foreach( $prop in $component.properties )
- #if(!$prop.exist && $prop.name != "value")
- #if($prop.classname == "java.lang.String")
- component.${prop.setterName}( " __$prop.name" );
- #elseif($prop.classname == "java.lang.Boolean")
- component.${prop.setterName}( new Boolean(true) );
- #end
+ #if(!$prop.exist && !$prop.elonly && !$prop.classname.startsWith("javax.faces."))
+ component.${prop.setterName}($testDataGenerator.getTestData(${prop}) );
#end
#end
@@ -104,13 +103,17 @@
}
public void testComponent() throws Exception {
-
+ #if(${component.renderer})
+ assertEquals("${component.renderer.name}", component.getRendererType());
+ #end
+
+/*
HtmlPage renderedView = renderView();
assertNotNull(renderedView);
System.out.println(renderedView.getWebResponse().getContentAsString());
HtmlElement element = renderedView.getHtmlElementById(form.getId() + ":" + component.getId());
assertNotNull(element);
-
+*/
// values[0] = component.saveState(facesContext);
}
@@ -122,15 +125,30 @@
public void testContext(){
Object state = component.saveState(facesContext);
-
+/*
UIViewRoot root = facesContext.getViewRoot();
root.processDecodes(facesContext);
root.processValidators(facesContext);
root.processUpdates(facesContext);
root.processApplication(facesContext);
-
+*/
testRestoreState(state);
}
+
+ public void testGetters() {
+ ${component.simpleClassName} component = new ${component.simpleClassName}();
+
+#foreach( $prop in $component.properties )
+ #if(!$prop.exist && !$prop.elonly && !$prop.classname.startsWith("javax.faces."))
+ component.setValueBinding("${prop.name}", new MockValueBinding($testDataGenerator.getTestVeData(${prop}), ${testDataGenerator.getTestVeClass(${prop})}.class));
+ assertEquals($testDataGenerator.getTestData(${prop}), component.${prop.getterName}());
+ component.${prop.setterName}($testDataGenerator.getTestData1(${prop}) );
+ assertEquals($testDataGenerator.getTestData1(${prop}), component.${prop.getterName}());
+ #end
+#end
+
+
+ }
private void testRestoreState(Object state){
${component.simpleClassName} restoredComponent = new ${component.simpleClassName}();
@@ -144,4 +162,11 @@
}
-}
\ No newline at end of file
+ private void assertEquals(double d1, double d2) {
+ assertEquals(d1, d2, 0);
+ }
+
+ private void assertEquals(float d1, float d2) {
+ assertEquals(d1, d2, 0);
+ }
+}
17 years, 8 months
JBoss Ajax4JSF SVN: r83 - trunk/cdk/generator/src/main/resources/META-INF/templates.
by ajax4jsf-svn-commits@lists.jboss.org
Author: dbiatenia
Date: 2007-04-13 14:57:52 -0400 (Fri, 13 Apr 2007)
New Revision: 83
Modified:
trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm
trunk/cdk/generator/src/main/resources/META-INF/templates/tagtest.vm
Log:
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm 2007-04-13 18:57:37 UTC (rev 82)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm 2007-04-13 18:57:52 UTC (rev 83)
@@ -81,8 +81,12 @@
component.setId("component");
#foreach( $prop in $component.properties )
- #if(!$prop.exist)
- component.${prop.setterName}( " __$prop.name" );
+ #if(!$prop.exist && $prop.name != "value")
+ #if($prop.classname == "java.lang.String")
+ component.${prop.setterName}( " __$prop.name" );
+ #elseif($prop.classname == "java.lang.Boolean")
+ component.${prop.setterName}( new Boolean(true) );
+ #end
#end
#end
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates/tagtest.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates/tagtest.vm 2007-04-13 18:57:37 UTC (rev 82)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates/tagtest.vm 2007-04-13 18:57:52 UTC (rev 83)
@@ -10,7 +10,8 @@
import javax.faces.component.UIComponent;
import javax.faces.webapp.UIComponentTag;
import ${component.classname};
-
+import javax.faces.application.Application;
+import javax.faces.el.ValueBinding;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
@@ -85,11 +86,24 @@
public void testSetPropertiesUIComponent() {
${component.simpleClassName} component = new ${component.simpleClassName}();
-/*
+ // create binding
+ Application application = null;
+ ValueBinding binding = null;
+
#foreach( $prop in $tag.properties )
- tag.${prop.setterName}("__${prop.name}");
+ #if($prop.el)
+ application = facesContext.getApplication();
+ binding = application.createValueBinding(component.getOnclick());
+ component.setValueBinding("${prop.name}", binding);
+ #if($prop.classname == "java.lang.String")
+ component.${prop.setterName}( " __$prop.name" );
+ #elseif($prop.classname == "java.lang.Boolean")
+ component.${prop.setterName}( new Boolean(true) );
+ #end
+ #end
+ //tag.${prop.setterName}("__${prop.name}");
#end
-*/
+
tag.setProperties(component);
/*
17 years, 8 months
JBoss Ajax4JSF SVN: r82 - trunk/cdk/generator/src/main/resources/META-INF/templates12.
by ajax4jsf-svn-commits@lists.jboss.org
Author: dbiatenia
Date: 2007-04-13 14:57:37 -0400 (Fri, 13 Apr 2007)
New Revision: 82
Modified:
trunk/cdk/generator/src/main/resources/META-INF/templates12/componenttest.vm
trunk/cdk/generator/src/main/resources/META-INF/templates12/tagtest.vm
Log:
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates12/componenttest.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates12/componenttest.vm 2007-04-12 19:04:29 UTC (rev 81)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates12/componenttest.vm 2007-04-13 18:57:37 UTC (rev 82)
@@ -81,8 +81,12 @@
component.setId("component");
#foreach( $prop in $component.properties )
- #if(!$prop.exist)
- component.${prop.setterName}( " __$prop.name" );
+ #if(!$prop.exist && $prop.name != "value")
+ #if($prop.classname == "java.lang.String")
+ component.${prop.setterName}( " __$prop.name" );
+ #elseif($prop.classname == "java.lang.Boolean")
+ component.${prop.setterName}( new Boolean(true) );
+ #end
#end
#end
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates12/tagtest.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates12/tagtest.vm 2007-04-12 19:04:29 UTC (rev 81)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates12/tagtest.vm 2007-04-13 18:57:37 UTC (rev 82)
@@ -10,7 +10,8 @@
import javax.faces.component.UIComponent;
import javax.faces.webapp.UIComponentTag;
import ${component.classname};
-
+import javax.faces.application.Application;
+import javax.faces.el.ValueBinding;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
@@ -85,11 +86,24 @@
public void testSetPropertiesUIComponent() {
${component.simpleClassName} component = new ${component.simpleClassName}();
-/*
+ // create binding
+ Application application = null;
+ ValueBinding binding = null;
+
#foreach( $prop in $tag.properties )
- tag.${prop.setterName}("__${prop.name}");
+ #if($prop.el)
+ application = facesContext.getApplication();
+ binding = application.createValueBinding(component.getOnclick());
+ component.setValueBinding("${prop.name}", binding);
+ #if($prop.classname == "java.lang.String")
+ component.${prop.setterName}( " __$prop.name" );
+ #elseif($prop.classname == "java.lang.Boolean")
+ component.${prop.setterName}( new Boolean(true) );
+ #end
+ #end
+ //tag.${prop.setterName}("__${prop.name}");
#end
-*/
+
tag.setProperties(component);
/*
17 years, 8 months
JBoss Ajax4JSF SVN: r81 - trunk/test/src/main/java/org/ajax4jsf/tests.
by ajax4jsf-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2007-04-12 15:04:29 -0400 (Thu, 12 Apr 2007)
New Revision: 81
Modified:
trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
Log:
JavaScript disabled for WebClient as not treated prototype.js well producing kilometers stack traces. Method createWebClient() introduced to setup client if need
Modified: trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java
===================================================================
--- trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-04-12 14:12:56 UTC (rev 80)
+++ trunk/test/src/main/java/org/ajax4jsf/tests/AbstractAjax4JsfTestCase.java 2007-04-12 19:04:29 UTC (rev 81)
@@ -183,13 +183,21 @@
}
}
+ protected WebClient createWebClient() {
+ WebClient client = new WebClient();
+ //disable javascript for now as HtmlUnit doesn't treat prototype.js well
+ client.setJavaScriptEnabled(false);
+
+ return client;
+ }
+
/**
*
*/
protected void setupWebClient() {
ajaxContext = null;
// setup webClient for got response content.
- webClient = new WebClient();
+ webClient = createWebClient();
webConnection = new MockWebConnection(webClient) {
public WebResponse getResponse(WebRequestSettings settings)
throws IOException {
17 years, 8 months
JBoss Ajax4JSF SVN: r80 - trunk/cdk/generator/src/main/resources/META-INF/templates.
by ajax4jsf-svn-commits@lists.jboss.org
Author: dbiatenia
Date: 2007-04-12 10:12:56 -0400 (Thu, 12 Apr 2007)
New Revision: 80
Modified:
trunk/cdk/generator/src/main/resources/META-INF/templates/tagtest.vm
Log:
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates/tagtest.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates/tagtest.vm 2007-04-12 14:12:30 UTC (rev 79)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates/tagtest.vm 2007-04-12 14:12:56 UTC (rev 80)
@@ -86,6 +86,13 @@
public void testSetPropertiesUIComponent() {
${component.simpleClassName} component = new ${component.simpleClassName}();
/*
+ #foreach( $prop in $tag.properties )
+ tag.${prop.setterName}("__${prop.name}");
+ #end
+*/
+ tag.setProperties(component);
+
+/*
#foreach( $prop in $component.properties )
#if( !$prop.existintag )
#if(!$prop.el)
@@ -139,4 +146,14 @@
#end
*/
}
+
+ public void testGetRendererType(){
+ assertNotNull(tag.getRendererType());
+ }
+
+ public void testGetComponentType(){
+ assertNotNull(tag.getComponentType());
+ }
+
+
}
17 years, 8 months
JBoss Ajax4JSF SVN: r79 - trunk/cdk/generator/src/main/resources/META-INF/templates12.
by ajax4jsf-svn-commits@lists.jboss.org
Author: dbiatenia
Date: 2007-04-12 10:12:30 -0400 (Thu, 12 Apr 2007)
New Revision: 79
Modified:
trunk/cdk/generator/src/main/resources/META-INF/templates12/tagtest.vm
Log:
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates12/tagtest.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates12/tagtest.vm 2007-04-12 14:11:24 UTC (rev 78)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates12/tagtest.vm 2007-04-12 14:12:30 UTC (rev 79)
@@ -86,6 +86,13 @@
public void testSetPropertiesUIComponent() {
${component.simpleClassName} component = new ${component.simpleClassName}();
/*
+ #foreach( $prop in $tag.properties )
+ tag.${prop.setterName}("__${prop.name}");
+ #end
+*/
+ tag.setProperties(component);
+
+/*
#foreach( $prop in $component.properties )
#if( !$prop.existintag )
#if(!$prop.el)
@@ -139,4 +146,14 @@
#end
*/
}
+
+ public void testGetRendererType(){
+ assertNotNull(tag.getRendererType());
+ }
+
+ public void testGetComponentType(){
+ assertNotNull(tag.getComponentType());
+ }
+
+
}
17 years, 8 months