myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r411317 - in /myfaces/tomahawk/trunk/sandbox: core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/ examples/src/main/java/org/apache/myfaces/examples/valueChangeNotifier/ examples/src/main/webapp/
Date Fri, 02 Jun 2006 22:23:03 GMT
Author: imario
Date: Fri Jun  2 15:23:02 2006
New Revision: 411317

URL: http://svn.apache.org/viewvc?rev=411317&view=rev
Log:
TOMAHAWK-462: Save/Restore state (rowIndex) of parent UIDatas (tables) to make the valueChangeNotififer
work with them

Added:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/RestoreStateCommand.java
  (with props)
Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/ValueChangeCollector.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/ValueChangeManager.java
    myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/valueChangeNotifier/NotifierBean.java
    myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/valueChangeNotifier.jsp

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/RestoreStateCommand.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/RestoreStateCommand.java?rev=411317&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/RestoreStateCommand.java
(added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/RestoreStateCommand.java
Fri Jun  2 15:23:02 2006
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.custom.valueChangeNotifier;
+
+public interface RestoreStateCommand
+{
+	public void saveCurrentState();
+	public void restoreCurrentState();
+	
+	public void restoreEventState();
+}
\ No newline at end of file

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/RestoreStateCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/RestoreStateCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/RestoreStateCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/ValueChangeCollector.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/ValueChangeCollector.java?rev=411317&r1=411316&r2=411317&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/ValueChangeCollector.java
(original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/ValueChangeCollector.java
Fri Jun  2 15:23:02 2006
@@ -15,7 +15,12 @@
  */
 package org.apache.myfaces.custom.valueChangeNotifier;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIData;
 import javax.faces.context.FacesContext;
 import javax.faces.event.AbortProcessingException;
 import javax.faces.event.ValueChangeEvent;
@@ -32,7 +37,7 @@
 {
 	private String method = null;
 	private boolean isTransient = false;
-	
+
 	public ValueChangeCollector()
 	{
 	}
@@ -49,12 +54,52 @@
 	public void processValueChange(ValueChangeEvent event)
 			throws AbortProcessingException
 	{
-		ValueChangeEvent clonedEvent = new ValueChangeEvent(event
-				.getComponent(), event.getOldValue(), event.getNewValue());
+		UIComponent valueChangeComponent = event.getComponent();
+		List restoreStateCommands = new ArrayList(); 
+		collectStates(restoreStateCommands, valueChangeComponent); 
+		
+		ValueChangeEvent clonedEvent = new ValueChangeEvent(
+			event.getComponent(),
+			event.getOldValue(),
+			event.getNewValue());
 
 		ValueChangeManager manager = ValueChangeManager.getManager(FacesContext
 				.getCurrentInstance());
-		manager.addEvent(method, clonedEvent);
+		manager.addEvent(method, clonedEvent, restoreStateCommands);
+	}
+
+	protected void collectStates(List restoreStateCommands, UIComponent component)
+	{
+		while (component != null)
+		{
+			if (component instanceof UIData)
+			{
+				final UIData data = (UIData) component;
+				final int rowIndex = data.getRowIndex();
+				
+				restoreStateCommands.add(new RestoreStateCommand()
+				{
+					int currentRowIndex;
+					
+					public void saveCurrentState()
+					{
+						currentRowIndex = data.getRowIndex();
+					}
+					
+					public void restoreCurrentState()
+					{
+						data.setRowIndex(currentRowIndex);
+					}
+
+					public void restoreEventState()
+					{
+						data.setRowIndex(rowIndex);
+					}
+				});
+			}
+			
+			component = component.getParent(); 
+		}
 	}
 
 	public Object saveState(FacesContext context)

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/ValueChangeManager.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/ValueChangeManager.java?rev=411317&r1=411316&r2=411317&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/ValueChangeManager.java
(original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/valueChangeNotifier/ValueChangeManager.java
Fri Jun  2 15:23:02 2006
@@ -46,12 +46,15 @@
 	{
 		private final String method;
 		private final ValueChangeEvent event;
+		private final List restoreStateCommands;
 
 		public Entry(String method,
-				ValueChangeEvent event)
+				ValueChangeEvent event,
+				List restoreStateCommands)
 		{
 			this.method = method;
 			this.event = event;
+			this.restoreStateCommands = restoreStateCommands;
 		}
 	}
 
@@ -63,9 +66,10 @@
 	 * add a new event 
 	 */
 	public void addEvent(String method,
-			ValueChangeEvent event)
+			ValueChangeEvent event,
+			List restoreStateCommands)
 	{
-		events.add(new Entry(method, event));
+		events.add(new Entry(method, event, restoreStateCommands));
 	}
 
 	/**
@@ -79,12 +83,15 @@
 			while (iterEvents.hasNext())
 			{
 				Entry entry = (Entry) iterEvents.next();
-	
+
+				saveCurrentStates(entry.restoreStateCommands);
+				
 				try
 				{
+					restoreEventStates(entry.restoreStateCommands);
+					
 					MethodBinding mb = context.getApplication().createMethodBinding(entry.method, SIGNATURE);
 					mb.invoke(context, new Object[] { entry.event });
-					
 				}
 				catch (MethodNotFoundException e)
 				{
@@ -95,11 +102,42 @@
 					// ignore any other value change event
 					return;
 				}
+				finally
+				{
+					restoreCurrentStates(entry.restoreStateCommands);
+				}
 			}
 		}
 		finally
 		{
 			events.clear();			
+		}
+	}
+
+	protected void saveCurrentStates(List restoreStateCommands)
+	{
+		for (int i = 0; i<restoreStateCommands.size(); i++)
+		{
+			RestoreStateCommand cmd = (RestoreStateCommand) restoreStateCommands.get(i);
+			cmd.saveCurrentState();
+		}
+	}
+	
+	protected void restoreCurrentStates(List restoreStateCommands)
+	{
+		for (int i = restoreStateCommands.size()-1; i>=0; i--)
+		{
+			RestoreStateCommand cmd = (RestoreStateCommand) restoreStateCommands.get(i);
+			cmd.restoreCurrentState();
+		}
+	}
+
+	protected void restoreEventStates(List restoreStateCommands)
+	{
+		for (int i = restoreStateCommands.size()-1; i>=0; i--)
+		{
+			RestoreStateCommand cmd = (RestoreStateCommand) restoreStateCommands.get(i);
+			cmd.restoreEventState();
 		}
 	}
 

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/valueChangeNotifier/NotifierBean.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/valueChangeNotifier/NotifierBean.java?rev=411317&r1=411316&r2=411317&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/valueChangeNotifier/NotifierBean.java
(original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/valueChangeNotifier/NotifierBean.java
Fri Jun  2 15:23:02 2006
@@ -1,8 +1,11 @@
 package org.apache.myfaces.examples.valueChangeNotifier;
 
+import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
+import javax.faces.component.UIData;
 import javax.faces.event.AbortProcessingException;
 import javax.faces.event.ValueChangeEvent;
 import javax.faces.model.SelectItem;
@@ -10,42 +13,148 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-public class NotifierBean {
-	
+public class NotifierBean
+{
+
 	private static Log log = LogFactory.getLog(NotifierBean.class);
-	
+
 	private String selectedCategory;
 	private List categories;
+	private List listData;
+	private UIData listDataBinding;
+
+	public static class EntryList implements Serializable
+	{
+		private List listData;
+
+		public List getListData()
+		{
+			return listData;
+		}
+
+		public void setListData(List listData)
+		{
+			this.listData = listData;
+		}
+	}
 	
+	public static class Entry implements Serializable
+	{
+		private String data;
+
+		public Entry()
+		{
+		}
+
+		public String getData()
+		{
+			return data;
+		}
+
+		public void setData(String data)
+		{
+			this.data = data;
+		}
+		
+		public String toString()
+		{
+			return "Entry=" + data;
+		}
+	}
+
 	public NotifierBean()
 	{
 		categories = new ArrayList();
 		categories.add(new SelectItem("a", "Category A"));
 		categories.add(new SelectItem("b", "Category b"));
+		
+		Entry a1 = new Entry();
+		a1.setData("A1");
+		Entry b1 = new Entry();
+		b1.setData("B1");
+		Entry c1 = new Entry();
+		c1.setData("C1");
+		Entry d1 = new Entry();
+		d1.setData("D1");
+		List listData1 = Arrays.asList(new Entry[]
+		{
+				a1,b1,c1,d1
+		});
+		Entry a2 = new Entry();
+		a2.setData("A2");
+		Entry b2 = new Entry();
+		b2.setData("B2");
+		Entry c2 = new Entry();
+		c2.setData("C2");
+		Entry d2 = new Entry();
+		d2.setData("D2");
+		List listData2 = Arrays.asList(new Entry[]
+		{
+				a2,b2,c2,d2
+		});
+		
+		EntryList al1 = new EntryList();
+		al1.setListData(listData1);
+		EntryList al2 = new EntryList();
+		al2.setListData(listData2);
+		
+		listData = Arrays.asList(new EntryList[]
+		                                       {
+				al1, al2
+		                                       });
 	}
-	
-	public void valueChange(ValueChangeEvent vce) throws AbortProcessingException 
+
+	public void valueChange(ValueChangeEvent vce)
+			throws AbortProcessingException
 	{
-		if(log.isInfoEnabled()){
-            log.info("invoked valueChange method with " + vce.getNewValue() + " as its new
value");
+		if (log.isInfoEnabled())
+		{
+			log.info("invoked valueChange method with " + vce.getNewValue()
+					+ " as its new value");
+			
+			if (listDataBinding != null)
+			{
+				log.info("current uiData row=" + listDataBinding.getRowIndex());
+				if (listDataBinding.getRowIndex() > -1)
+				{
+					log.info("current uiData rowData=" + listDataBinding.getRowData());
+				}
+			}
 		}
-		
 	}
 
-	public String getSelectedCategory() {
+	public List getListData()
+	{
+		return listData;
+	}
+
+	public String getSelectedCategory()
+	{
 		return selectedCategory;
 	}
 
-	public void setSelectedCategory(String selectedCategory) {
+	public void setSelectedCategory(String selectedCategory)
+	{
 		this.selectedCategory = selectedCategory;
 	}
 
-	public List getCategories() {
+	public List getCategories()
+	{
 		return categories;
 	}
 
-	public void setCategories(List categories) {
+	public void setCategories(List categories)
+	{
 		this.categories = categories;
 	}
 
+	public UIData getListDataBinding()
+	{
+		return listDataBinding;
+	}
+
+	public void setListDataBinding(UIData listDataBinding)
+	{
+		this.listDataBinding = listDataBinding;
+	}
 }

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/valueChangeNotifier.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/valueChangeNotifier.jsp?rev=411317&r1=411316&r2=411317&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/valueChangeNotifier.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/valueChangeNotifier.jsp Fri Jun
 2 15:23:02 2006
@@ -1,11 +1,21 @@
-<%@ page session="false" contentType="text/html;charset=utf-8"%>
-<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
-<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
-<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
-<%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="s"%>
+<%@ page
+	session="false"
+	contentType="text/html;charset=utf-8"%>
+<%@ taglib
+	uri="http://java.sun.com/jsf/html"
+	prefix="h"%>
+<%@ taglib
+	uri="http://java.sun.com/jsf/core"
+	prefix="f"%>
+<%@ taglib
+	uri="http://myfaces.apache.org/tomahawk"
+	prefix="t"%>
+<%@ taglib
+	uri="http://myfaces.apache.org/sandbox"
+	prefix="s"%>
 <html>
 
-<%@include file="inc/head.inc" %>
+<%@include file="inc/head.inc"%>
 
 <!--
 /*
@@ -28,18 +38,41 @@
 <body>
 
 <f:view>
-    <h:form>
-      <h:selectOneMenu value="#{notifierBean.selectedCategory}" onchange="submit()">
-      
-	      <s:valueChangeNotifier method="#{notifierBean.valueChange}" />
-	      <f:selectItems value="#{notifierBean.categories}" />
-	  
-	  </h:selectOneMenu>    
-    </h:form>
+	<h:form>
+		<h:selectOneMenu
+			value="#{notifierBean.selectedCategory}"
+			onchange="submit()">
+
+			<s:valueChangeNotifier method="#{notifierBean.valueChange}" />
+			<f:selectItems value="#{notifierBean.categories}" />
+
+		</h:selectOneMenu>
+
+		<h:dataTable
+			value="#{notifierBean.listData}"
+			var="item"
+			border="1">
+			<h:column>
+				<h:dataTable
+					value="#{item.listData}"
+					var="itemSub"
+					binding="#{notifierBean.listDataBinding}"
+					border="1">
+					<h:column>
+						<h:inputText value="#{itemSub.data}">
+							<s:valueChangeNotifier method="#{notifierBean.valueChange}" />
+						</h:inputText>
+					</h:column>
+				</h:dataTable>
+			</h:column>
+		</h:dataTable>
+
+		<h:commandButton />
+	</h:form>
 </f:view>
 
-<%@include file="inc/page_footer.jsp" %>
+<%@include file="inc/page_footer.jsp"%>
 
 </body>
 
-</html>
\ No newline at end of file
+</html>



Mime
View raw message