You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/09/02 17:31:14 UTC
svn commit: r991983 - in /myfaces/tomahawk/trunk/core20/src:
main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java
test/java/org/apache/myfaces/component/html/ext/HtmlDataTableTest.java
Author: lu4242
Date: Thu Sep 2 15:31:14 2010
New Revision: 991983
URL: http://svn.apache.org/viewvc?rev=991983&view=rev
Log:
TOMAHAWK-1545 Components inside detailStamp facet requires clientId reset each time setRowIndex is called
Modified:
myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java
myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/component/html/ext/HtmlDataTableTest.java
Modified: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java?rev=991983&r1=991982&r2=991983&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java (original)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlDataTable.java Thu Sep 2 15:31:14 2010
@@ -110,7 +110,7 @@ public abstract class AbstractHtmlDataTa
public static final String NEWSPAPER_COLUMNS_PROPERTY = "newspaperColumns";
public static final String SPACER_FACET_NAME = "spacer";
public static final String NEWSPAPER_ORIENTATION_PROPERTY = "newspaperOrientation";
-
+
public static final String DETAIL_STAMP_FACET_NAME = "detailStamp";
private Map<String, _SerializableDataModel> _preservedDataModel = new HashMap<String, _SerializableDataModel>();
@@ -119,7 +119,7 @@ public abstract class AbstractHtmlDataTa
private Map<Integer, Boolean> _expandedNodes = new HashMap<Integer, Boolean>();
- private Map<String, Object> _detailRowStates = new HashMap<String, Object>();
+ //private Map<String, Object> _detailRowStates = new HashMap<String, Object>();
private TableContext _tableContext = null;
@@ -444,21 +444,21 @@ public abstract class AbstractHtmlDataTa
public void setRowIndex(int rowIndex)
{
- FacesContext facesContext = FacesContext.getCurrentInstance();
+ //FacesContext facesContext = FacesContext.getCurrentInstance();
if (rowIndex < -1)
{
throw new IllegalArgumentException("rowIndex is less than -1");
}
- UIComponent facet = getFacet(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
+ //UIComponent facet = getFacet(HtmlTableRenderer.DETAIL_STAMP_FACET_NAME);
/*Just for obtaining an iterator which must be passed to saveDescendantComponentStates()*/
- ArrayList<UIComponent> detailStampList = new ArrayList<UIComponent>(1);
- detailStampList.add(facet);
- if (getRowIndex() != -1 && facet != null)
- {
- _detailRowStates.put(getContainerClientId(facesContext), saveDescendantComponentStates(detailStampList.iterator(), false));
- }
+ //ArrayList<UIComponent> detailStampList = new ArrayList<UIComponent>(1);
+ //detailStampList.add(facet);
+ //if (getRowIndex() != -1 && facet != null)
+ //{
+ // _detailRowStates.put(getContainerClientId(facesContext), saveDescendantComponentStates(detailStampList.iterator(), false));
+ //}
String rowIndexVar = getRowIndexVar();
String rowCountVar = getRowCountVar();
@@ -521,14 +521,14 @@ public abstract class AbstractHtmlDataTa
super.setRowIndex(rowIndex);
}
- if (rowIndex != -1 && facet != null)
- {
- Object rowState = _detailRowStates.get(getContainerClientId(facesContext));
+ //if (rowIndex != -1 && facet != null)
+ //{
+ // Object rowState = _detailRowStates.get(getContainerClientId(facesContext));
- restoreDescendantComponentStates(detailStampList.iterator(),
- rowState, false);
+ // restoreDescendantComponentStates(detailStampList.iterator(),
+ // rowState, false);
- }
+ //}
if (getStateHelper().get(PropertyKeys.varDetailToggler) != null)
{
@@ -538,6 +538,35 @@ public abstract class AbstractHtmlDataTa
}
@Override
+ protected Object saveDescendantComponentStates()
+ {
+ if (getFacetCount() > 0)
+ {
+ UIComponent detailStampFacet = getFacet(DETAIL_STAMP_FACET_NAME);
+ if (detailStampFacet != null)
+ {
+ return saveDescendantComponentStates(new _DetailStampFacetAndChildrenIterator(detailStampFacet, getChildren()), false);
+ }
+ }
+ return super.saveDescendantComponentStates();
+ }
+
+ @Override
+ protected void restoreDescendantComponentStates(Object state)
+ {
+ if (getFacetCount() > 0)
+ {
+ UIComponent detailStampFacet = getFacet(DETAIL_STAMP_FACET_NAME);
+ if (detailStampFacet != null)
+ {
+ restoreDescendantComponentStates(new _DetailStampFacetAndChildrenIterator(detailStampFacet, getChildren()), state, false);
+ return;
+ }
+ }
+ super.restoreDescendantComponentStates(state);
+ }
+
+ @Override
protected void restoreFullDescendantComponentDeltaStates(FacesContext facesContext,
Map<String, Object> rowState, Object initialState)
{
@@ -549,8 +578,8 @@ public abstract class AbstractHtmlDataTa
restoreFullDescendantComponentDeltaStates(facesContext, new _DetailStampFacetAndChildrenIterator(detailStampFacet, getChildren()), rowState, initialState, false, getContainerClientId(facesContext));
return;
}
- }
- restoreFullDescendantComponentDeltaStates(facesContext, getChildren().iterator(), rowState, initialState, false, getContainerClientId(facesContext));
+ }
+ super.restoreFullDescendantComponentDeltaStates(facesContext, rowState, initialState);
}
@Override
@@ -566,7 +595,7 @@ public abstract class AbstractHtmlDataTa
return;
}
}
- restoreFullDescendantComponentStates(facesContext, getChildren().iterator(), initialState, false);
+ super.restoreFullDescendantComponentStates(facesContext, initialState);
}
@Override
@@ -581,7 +610,7 @@ public abstract class AbstractHtmlDataTa
return saveDescendantInitialComponentStates(facesContext, new _DetailStampFacetAndChildrenIterator(detailStampFacet, getChildren()), false);
}
}
- return saveDescendantInitialComponentStates(facesContext, getChildren().iterator(), false);
+ return super.saveDescendantInitialComponentStates(facesContext);
}
@Override
@@ -595,9 +624,10 @@ public abstract class AbstractHtmlDataTa
return saveFullDescendantComponentStates(facesContext, null, new _DetailStampFacetAndChildrenIterator(detailStampFacet, getChildren()), false, getContainerClientId(facesContext));
}
}
- return saveFullDescendantComponentStates(facesContext, null, getChildren().iterator(), false, getContainerClientId(facesContext));
+ return super.saveFullDescendantComponentStates(facesContext);
}
+ /*
@Override
public void deleteRowStateForRow(int deletedIndex)
{
@@ -668,7 +698,7 @@ public abstract class AbstractHtmlDataTa
}
}
}
- }
+ }*/
public void processDecodes(FacesContext context)
{
@@ -856,14 +886,19 @@ public abstract class AbstractHtmlDataTa
process(context, facet, processAction);
- if ( rowIndex == (last - 1) )
- {
- ArrayList<UIComponent> detailStampList = new ArrayList<UIComponent>(1);
- detailStampList.add(facet);
- _detailRowStates.put(
- getContainerClientId(FacesContext.getCurrentInstance()),
- saveDescendantComponentStates(detailStampList.iterator(),false));
- }
+ // This code comes from TOMAHAWK-493, but really the problem was caused by
+ // TOMAHAWK-1534, by a bad comparison of rowIndex. The solution proposed is override
+ // the default iterator for save/restore on HtmlDataTableHack.setRowIndex(), to
+ // include the detailStamp. In this way, we'll be sure that the state is correctly
+ // saved and the component clientId is reset for all components that requires it
+ //if ( rowIndex == (last - 1) )
+ //{
+ // ArrayList<UIComponent> detailStampList = new ArrayList<UIComponent>(1);
+ // detailStampList.add(facet);
+ // _detailRowStates.put(
+ // getContainerClientId(FacesContext.getCurrentInstance()),
+ // saveDescendantComponentStates(detailStampList.iterator(),false));
+ //}
}
}
}
Modified: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/component/html/ext/HtmlDataTableTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/component/html/ext/HtmlDataTableTest.java?rev=991983&r1=991982&r2=991983&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/component/html/ext/HtmlDataTableTest.java (original)
+++ myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/component/html/ext/HtmlDataTableTest.java Thu Sep 2 15:31:14 2010
@@ -29,12 +29,16 @@ import javax.faces.component.UIColumn;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.component.UIInput;
+import javax.faces.component.UIOutput;
+import javax.faces.component.UIPanel;
+import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.model.ListDataModel;
import junit.framework.Test;
+import org.apache.myfaces.component.html.ext.HtmlDataTablePreserveRowComponentStateTest.RowData;
import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
import org.apache.myfaces.test.utils.TestUtils;
@@ -206,4 +210,143 @@ public class HtmlDataTableTest extends A
}
}
+ public void testDetailStampRowState1() throws Exception
+ {
+ List<RowData> model = new ArrayList<RowData>();
+ model.add(new RowData("text1","style1"));
+ model.add(new RowData("text1","style2"));
+ model.add(new RowData("text1","style3"));
+ model.add(new RowData("text1","style4"));
+
+ //Put on request map to be resolved later
+ request.setAttribute("list", model);
+
+ UIViewRoot root = facesContext.getViewRoot();
+ HtmlDataTable table = new HtmlDataTable();
+ UIColumn column = new UIColumn();
+ UIPanel detailStampPanel = new UIPanel();
+ UIOutput text = new UIOutput();
+ UIOutput detailStampText = new UIOutput();
+
+ //This is only required if markInitiaState fix is not used
+ root.setId("root");
+ table.setId("table");
+ detailStampPanel.setId("detailStamp");
+ column.setId("column");
+ text.setId("text");
+ detailStampText.setId("detailStampText");
+
+ table.setVar("row");
+ table.setPreserveRowComponentState(true);
+ table.setValueExpression("value", application.
+ getExpressionFactory().createValueExpression(
+ facesContext.getELContext(),"#{list}",List.class));
+
+ text.setValueExpression("value", application.
+ getExpressionFactory().createValueExpression(
+ facesContext.getELContext(),"#{row.text}",String.class));
+
+ detailStampText.setValueExpression("value", application.
+ getExpressionFactory().createValueExpression(
+ facesContext.getELContext(),"#{row.text}",String.class));
+
+ root.getChildren().add(table);
+ table.getChildren().add(column);
+ table.getFacets().put(AbstractHtmlDataTable.DETAIL_STAMP_FACET_NAME, detailStampPanel);
+ column.getChildren().add(text);
+ detailStampPanel.getChildren().add(detailStampText);
+
+ //Check the value expressions are working and change the component state
+ for (int i = 0; i < model.size(); i++)
+ {
+ RowData rowData = model.get(i);
+ table.setRowIndex(i);
+ assertEquals(rowData.getText(), text.getValue());
+ assertEquals(rowData.getText(), detailStampText.getValue());
+ }
+
+ //Reset row index
+ table.setRowIndex(-1);
+
+ //Check the values were not lost
+ for (int i = 0; i < model.size(); i++)
+ {
+ table.setRowIndex(i);
+ assertEquals(model.get(i).getText(), text.getValue());
+ assertEquals(model.get(i).getText(), detailStampText.getValue());
+ }
+
+ }
+
+ public void testDetailStampRowState2() throws Exception
+ {
+ List<RowData> model = new ArrayList<RowData>();
+ model.add(new RowData("text1","style1"));
+ model.add(new RowData("text1","style2"));
+ model.add(new RowData("text1","style3"));
+ model.add(new RowData("text1","style4"));
+
+ //Put on request map to be resolved later
+ request.setAttribute("list", model);
+
+ UIViewRoot root = facesContext.getViewRoot();
+ HtmlDataTable table = new HtmlDataTable();
+ UIColumn column = new UIColumn();
+ UIPanel detailStampPanel = new UIPanel();
+ UIOutput text = new UIOutput();
+ UIOutput detailStampText = new UIOutput();
+
+ //This is only required if markInitiaState fix is not used
+ root.setId("root");
+ table.setId("table");
+ detailStampPanel.setId("detailStamp");
+ column.setId("column");
+ text.setId("text");
+ detailStampText.setId("detailStampText");
+
+ table.setVar("row");
+ table.setPreserveRowComponentState(true);
+ table.setValueExpression("value", application.
+ getExpressionFactory().createValueExpression(
+ facesContext.getELContext(),"#{list}",List.class));
+
+ text.setValueExpression("value", application.
+ getExpressionFactory().createValueExpression(
+ facesContext.getELContext(),"#{row.text}",String.class));
+
+ detailStampText.setValueExpression("value", application.
+ getExpressionFactory().createValueExpression(
+ facesContext.getELContext(),"#{row.text}",String.class));
+
+ root.getChildren().add(table);
+ table.getChildren().add(column);
+ table.getFacets().put(AbstractHtmlDataTable.DETAIL_STAMP_FACET_NAME, detailStampPanel);
+ column.getChildren().add(text);
+ detailStampPanel.getChildren().add(detailStampText);
+
+ //Check the value expressions are working and change the component state
+ for (int i = 0; i < model.size(); i++)
+ {
+ RowData rowData = model.get(i);
+ table.setRowIndex(i);
+ assertEquals(rowData.getText(), text.getValue());
+ assertEquals(rowData.getText(), detailStampText.getValue());
+ }
+
+ //Reset row index
+ table.setRowIndex(-1);
+
+ //Remove a row
+ table.deleteRowStateForRow(1);
+ model.remove(1);
+
+ //Check the values were not lost
+ for (int i = 0; i < model.size(); i++)
+ {
+ table.setRowIndex(i);
+ assertEquals(model.get(i).getText(), text.getValue());
+ assertEquals(model.get(i).getText(), detailStampText.getValue());
+ }
+ }
+
}