Author: alexsmirnov
Date: 2007-03-15 12:06:28 -0400 (Thu, 15 Mar 2007)
New Revision: 38
Modified:
trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java
Log:
Fix setup row variable method with check is a data availible.
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-14
23:37:35 UTC (rev 37)
+++ trunk/framework/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java 2007-03-15
16:06:28 UTC (rev 38)
@@ -162,7 +162,7 @@
* Name of EL variable for current component state.
*/
private String _stateVar;
-
+
private String _rowKeyVar;
/**
@@ -200,7 +200,8 @@
}
/**
- * @param rowKeyVar the rowKeyVar to set
+ * @param rowKeyVar
+ * the rowKeyVar to set
*/
public void setRowKeyVar(String rowKeyVar) {
this._rowKeyVar = rowKeyVar;
@@ -426,33 +427,43 @@
protected void setupVariable(FacesContext faces, DataModel localModel,
boolean rowSelected) {
Map attrs = faces.getExternalContext().getRequestMap();
- 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());
+ 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());
+
+ } else {
+ removeVariable(getVar(), attrs);
+ removeVariable(getStateVar(), attrs);
+ removeVariable(getRowKeyVar(), attrs);
+ }
}
/**
- * @param rowSelected
* @param var
* @param attrs
- * @param rowAvailable
* @param rowData
*/
- private void setupOrRemoveVariable(boolean rowSelected, String var, Map attrs, boolean
rowAvailable, Object rowData) {
+ private void setupVariable(String var, Map attrs, Object rowData) {
if (var != null) {
- if (rowSelected && rowAvailable) {
- attrs.put(var, rowData);
- } else {
- attrs.remove(var);
- }
+ attrs.put(var, rowData);
}
}
/**
+ * @param var
+ * @param attrs
+ * @param rowData
+ */
+ private void removeVariable(String var, Map attrs) {
+ if (var != null) {
+ attrs.remove(var);
+ }
+ }
+ /**
* Reset data model. this method must be called twice per request - before
* decode phase and before component encoding.
*/
@@ -916,7 +927,8 @@
return;
this.iterate(faces, updateVisitor, argument);
ExtendedDataModel dataModel = getExtendedDataModel();
- // If no validation errors, update values for serializable model, restored from view.
+ // If no validation errors, update values for serializable model,
+ // restored from view.
if (dataModel instanceof SerializableDataModel && (!keepSaved(faces))) {
SerializableDataModel serializableModel = (SerializableDataModel) dataModel;
serializableModel.update();
@@ -1184,7 +1196,7 @@
*
*/
private static final long serialVersionUID = 9037454770537726418L;
-
+
/**
* Flag setted to true if componentState implements StateHolder
*/
@@ -1212,9 +1224,11 @@
PerIdState idState = (PerIdState) stateEntry.getValue();
DataComponentState compState;
if (idState.stateInHolder) {
- // TODO - change RichFaces Tree component, for remove reference to component from
state.
+ // TODO - change RichFaces Tree component, for remove reference
+ // to component from state.
compState = createComponentState();
- ((StateHolder)compState).restoreState(faces, idState.componentState);
+ ((StateHolder) compState).restoreState(faces,
+ idState.componentState);
} else {
compState = (DataComponentState) idState.componentState;
}
@@ -1242,14 +1256,16 @@
idState.model = getExtendedDataModel().getSerializableModel(
dataComponentState.getRange());
// Save component state , depended if implemented interfaces.
- if(null == dataComponentState){
+ if (null == dataComponentState) {
idState.componentState = null;
- } else if (dataComponentState instanceof Serializable ){
+ } 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.
+ } 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.componentState = ((StateHolder) dataComponentState)
+ .saveState(faces);
idState.stateInHolder = true;
}
if (null != idState.model || null != idState.componentState) {