Author: nbelaevski
Date: 2010-04-08 14:22:59 -0400 (Thu, 08 Apr 2010)
New Revision: 16749
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java
Log:
UIDataAdaptor changes:
- keepSaved attribute added
- PSH support for "rowKeyConveter" implemented
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-04-08
15:37:06 UTC (rev 16748)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-04-08
18:22:59 UTC (rev 16749)
@@ -37,6 +37,9 @@
import javax.faces.component.ContextCallback;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.NamingContainer;
+import javax.faces.component.PartialStateHolder;
+import javax.faces.component.StateHelper;
+import javax.faces.component.StateHolder;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.component.UIForm;
@@ -125,13 +128,17 @@
}
};
+ //TODO nick - PSH support?
private DataComponentState componentState = null;
private ExtendedDataModel<?> extendedDataModel = null;
private Object rowKey = null;
private String clientId;
+
private Object originalVarValue;
+ private Converter rowKeyConverter;
+
/**
* @author Nick Belaevski
*
@@ -198,7 +205,7 @@
}
private enum PropertyKeys {
- lastId, var, rowKeyVar, stateVar, childState, rowKeyConverter
+ lastId, var, rowKeyVar, stateVar, childState, rowKeyConverter,
rowKeyConverterSet, keepSaved
}
public UIDataAdaptor() {
@@ -550,6 +557,25 @@
}
/**
+ * Boolean attribute that defines whether this iteration component will reset saved
children's state
+ * before rendering. By default state is reset if there are no faces messages with
severity error or higher.
+ * @return
+ */
+ public boolean isKeepSaved() {
+ Object value = getStateHelper().eval(PropertyKeys.keepSaved);
+
+ if (value == null) {
+ return keepSaved(getFacesContext());
+ } else {
+ return Boolean.valueOf(value.toString());
+ }
+ }
+
+ public void setKeepSaved(boolean keepSaved) {
+ getStateHelper().put(PropertyKeys.keepSaved, keepSaved);
+ }
+
+ /**
* 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.
@@ -631,15 +657,27 @@
}
public Converter getRowKeyConverter() {
+ if (this.rowKeyConverter != null) {
+ return this.rowKeyConverter;
+ }
+
return (Converter) getStateHelper().eval(PropertyKeys.rowKeyConverter);
}
public void setRowKeyConverter(Converter converter) {
+ StateHelper stateHelper = getStateHelper();
+ if (initialStateMarked()) {
+ stateHelper.put(PropertyKeys.rowKeyConverterSet, Boolean.TRUE);
+ }
- // TODO - handle partial state saving
- getStateHelper().put(PropertyKeys.rowKeyConverter, converter);
+ this.rowKeyConverter = converter;
}
+ private boolean isSetRowKeyConverter() {
+ Boolean value = (Boolean) getStateHelper().get(PropertyKeys.rowKeyConverterSet);
+ return Boolean.TRUE.equals(value);
+ }
+
@Override
public String getClientId(FacesContext facesContext) {
if (facesContext == null) {
@@ -857,7 +895,7 @@
// If no validation errors, update values for serializable model,
// restored from view.
- if ((dataModel instanceof SerializableDataModel) && (!keepSaved(faces)))
{
+ if ((dataModel instanceof SerializableDataModel) && (!isKeepSaved())) {
SerializableDataModel serializableModel = (SerializableDataModel) dataModel;
serializableModel.update();
@@ -917,7 +955,7 @@
Object savedChildState = getStateHelper().get(PropertyKeys.childState);
// TODO - verify the check for null: savedChildState == null
- if (savedChildState == null || !keepSaved(context)) {
+ if (savedChildState == null || !isKeepSaved()) {
resetChildState();
}
}
@@ -933,7 +971,7 @@
protected void preEncodeBegin(FacesContext context) {
resetDataModel();
- if (!keepSaved(context)) {
+ if (!isKeepSaved()) {
//TODO - this also resets state for the nested iteration components - is it
correct?
resetChildState();
}
@@ -945,17 +983,71 @@
super.encodeBegin(context);
}
+ @Override
+ public void markInitialState() {
+ super.markInitialState();
+
+ if (rowKeyConverter instanceof PartialStateHolder) {
+ ((PartialStateHolder) rowKeyConverter).markInitialState();
+ }
+ }
+
+ @Override
+ public void clearInitialState() {
+ super.clearInitialState();
+
+ if (rowKeyConverter instanceof PartialStateHolder) {
+ ((PartialStateHolder) rowKeyConverter).clearInitialState();
+ }
+ }
+
/*
* (non-Javadoc)
* @see
javax.faces.component.UIComponentBase#saveState(javax.faces.context.FacesContext)
*/
@Override
public Object saveState(FacesContext context) {
+ Object parentState = super.saveState(context);
+ Object savedComponentState = new DataAdaptorStateHelper(componentState,
extendedDataModel).saveState(context);
- // TODO - partial state saving handling
+ Object converterState = null;
+ boolean nullDelta = true;
+
+ boolean converterHasPartialState = false;
+
+ if (initialStateMarked()) {
+ if (!isSetRowKeyConverter() && rowKeyConverter != null &&
rowKeyConverter instanceof PartialStateHolder) {
+ // Delta
+ StateHolder holder = (StateHolder) rowKeyConverter;
+ if (!holder.isTransient()) {
+ Object attachedState = holder.saveState(context);
+ if (attachedState != null) {
+ nullDelta = false;
+ converterState = attachedState;
+ }
+ converterHasPartialState = true;
+ } else {
+ converterState = null;
+ }
+ } else if (isSetRowKeyConverter() || rowKeyConverter != null) {
+ // Full
+ converterState = saveAttachedState(context, rowKeyConverter);
+ nullDelta = false;
+ }
+
+ if (parentState == null && savedComponentState == null &&
nullDelta) {
+ // No values
+ return null;
+ }
+ } else {
+ converterState = saveAttachedState(context, rowKeyConverter);
+ }
+
return new Object[] {
- super.saveState(context),
- new DataAdaptorStateHelper(componentState,
extendedDataModel).saveState(context)
+ parentState,
+ savedComponentState,
+ converterHasPartialState,
+ converterState
};
}
@@ -966,9 +1058,12 @@
*/
@Override
public void restoreState(FacesContext context, Object stateObject) {
+ if (stateObject == null) {
+ return ;
+ }
+
Object[] state = (Object[]) stateObject;
- // TODO Auto-generated method stub
super.restoreState(context, state[0]);
if (state[1] != null) {
@@ -980,6 +1075,14 @@
componentState = dataAdaptorStateHelper.getDataComponentState();
extendedDataModel = dataAdaptorStateHelper.getExtendedDataModel();
}
+
+ boolean converterHasPartialState = Boolean.TRUE.equals(state[2]);
+ Object savedConverterState = state[3];
+ if (converterHasPartialState) {
+ ((StateHolder) rowKeyConverter).restoreState(context, savedConverterState);
+ } else {
+ rowKeyConverter = (Converter) UIComponentBase.restoreAttachedState(context,
savedConverterState);
+ }
}
private boolean matchesBaseId(String clientId, String baseId, char separatorChar) {