Author: alexsmirnov
Date: 2007-03-14 10:44:06 -0400 (Wed, 14 Mar 2007)
New Revision: 36
Modified:
trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/SequenceDataModel.java
trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java
Log:
Resolved AJSF-5 and RF-4 , name for EL-variable with current row index can be set by
rowKeyVar
attribute
Modified: trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/SequenceDataModel.java
===================================================================
---
trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/SequenceDataModel.java 2007-03-13
18:11:49 UTC (rev 35)
+++
trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/SequenceDataModel.java 2007-03-14
14:44:06 UTC (rev 36)
@@ -32,14 +32,14 @@
*/
public class SequenceDataModel extends ExtendedDataModel {
- DataModel wrapped;
+ private DataModel wrappedModel;
/**
* @param wrapped
*/
public SequenceDataModel(DataModel wrapped) {
super();
- this.wrapped = wrapped;
+ this.wrappedModel = wrapped;
}
/* (non-Javadoc)
@@ -83,7 +83,7 @@
public void walk(FacesContext context, DataVisitor visitor, Range range, Object
argument) throws IOException {
final SequenceRange seqRange = (SequenceRange) range;
int rows = seqRange.getRows();
- int rowCount = wrapped.getRowCount();
+ int rowCount = wrappedModel.getRowCount();
int currentRow = seqRange.getFirstRow();
if(rows > 0){
rows += currentRow;
@@ -96,8 +96,8 @@
rows = -1;
}
while (rows < 0 || currentRow < rows) {
- wrapped.setRowIndex(currentRow);
- if(wrapped.isRowAvailable()){
+ wrappedModel.setRowIndex(currentRow);
+ if(wrappedModel.isRowAvailable()){
visitor.process(context, new Integer(currentRow), argument);
} else {
break;
@@ -111,7 +111,7 @@
* @see org.ajax4jsf.ajax.repeat.ExtendedDataModel#getRowKey()
*/
public Object getRowKey() {
- int index = wrapped.getRowIndex();
+ int index = wrappedModel.getRowIndex();
if(index<0){
return null;
}
@@ -124,10 +124,10 @@
*/
public void setRowKey(Object key) {
if(null == key){
- wrapped.setRowIndex(-1);
+ wrappedModel.setRowIndex(-1);
} else {
Integer index = (Integer) key;
- wrapped.setRowIndex(index.intValue());
+ wrappedModel.setRowIndex(index.intValue());
}
}
@@ -136,7 +136,7 @@
*/
public int getRowCount() {
// TODO Auto-generated method stub
- return wrapped.getRowCount();
+ return wrappedModel.getRowCount();
}
/* (non-Javadoc)
@@ -144,7 +144,7 @@
*/
public Object getRowData() {
// TODO Auto-generated method stub
- return wrapped.getRowData();
+ return wrappedModel.getRowData();
}
/* (non-Javadoc)
@@ -152,7 +152,7 @@
*/
public int getRowIndex() {
// TODO Auto-generated method stub
- return wrapped.getRowIndex();
+ return wrappedModel.getRowIndex();
}
/* (non-Javadoc)
@@ -160,7 +160,7 @@
*/
public Object getWrappedData() {
// TODO Auto-generated method stub
- return wrapped.getWrappedData();
+ return wrappedModel.getWrappedData();
}
/* (non-Javadoc)
@@ -168,21 +168,35 @@
*/
public boolean isRowAvailable() {
// TODO Auto-generated method stub
- return wrapped.isRowAvailable();
+ return wrappedModel.isRowAvailable();
}
/* (non-Javadoc)
* @see javax.faces.model.DataModel#setRowIndex(int)
*/
public void setRowIndex(int rowIndex) {
- wrapped.setRowIndex(rowIndex);
+ wrappedModel.setRowIndex(rowIndex);
}
/* (non-Javadoc)
* @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
*/
public void setWrappedData(Object data) {
- wrapped.setWrappedData(data);
+ wrappedModel.setWrappedData(data);
}
+ /**
+ * @return the wrappedModel
+ */
+ protected DataModel getWrappedModel() {
+ return this.wrappedModel;
+ }
+
+ /**
+ * @param wrappedModel the wrappedModel to set
+ */
+ protected void setWrappedModel(DataModel wrappedModel) {
+ this.wrappedModel = wrappedModel;
+ }
+
}
Modified: trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java
===================================================================
--- trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java 2007-03-13
18:11:49 UTC (rev 35)
+++ trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java 2007-03-14
14:44:06 UTC (rev 36)
@@ -161,7 +161,9 @@
/**
* Name of EL variable for current component state.
*/
- private String _varState;
+ private String _stateVar;
+
+ private String _rowKeyVar;
/**
* Key for current value in model.
@@ -178,18 +180,32 @@
*
* @return the varState
*/
- public String getVarState() {
- return _varState;
+ public String getStateVar() {
+ return _stateVar;
}
/**
* @param varStatus
* the varStatus to set
*/
- public void setVarState(String varStatus) {
- this._varState = varStatus;
+ public void setStateVar(String varStatus) {
+ this._stateVar = varStatus;
}
+ /**
+ * @return the rowKeyVar
+ */
+ public String getRowKeyVar() {
+ return this._rowKeyVar;
+ }
+
+ /**
+ * @param rowKeyVar the rowKeyVar to set
+ */
+ public void setRowKeyVar(String rowKeyVar) {
+ this._rowKeyVar = rowKeyVar;
+ }
+
/*
* (non-Javadoc)
*
@@ -409,23 +425,31 @@
*/
protected void setupVariable(FacesContext faces, DataModel localModel,
boolean rowSelected) {
- String var = getVar();
Map attrs = faces.getExternalContext().getRequestMap();
- String varState = getVarState();
+ boolean rowAvailable = isRowAvailable();
+ // Current row data.
+ setupOrRemoveVariable(rowSelected, getVar(), attrs, rowAvailable,
localModel.getRowData());
+ // Component state variable.
+ setupOrRemoveVariable(rowSelected, getStateVar(), attrs, rowAvailable,
getComponentState());
+ // Row key Data variable.
+ setupOrRemoveVariable(rowSelected, getRowKeyVar(), attrs, rowAvailable, getRowKey());
+ }
+
+ /**
+ * @param rowSelected
+ * @param var
+ * @param attrs
+ * @param rowAvailable
+ * @param rowData
+ */
+ private void setupOrRemoveVariable(boolean rowSelected, String var, Map attrs, boolean
rowAvailable, Object rowData) {
if (var != null) {
- if (rowSelected && isRowAvailable()) {
- attrs.put(var, localModel.getRowData());
+ if (rowSelected && rowAvailable) {
+ attrs.put(var, rowData);
} else {
attrs.remove(var);
}
}
- if (varState != null) {
- if (rowSelected && isRowAvailable()) {
- attrs.put(varState, getComponentState());
- } else {
- attrs.remove(varState);
- }
- }
}
/**