Author: alexsmirnov
Date: 2007-03-30 20:27:58 -0400 (Fri, 30 Mar 2007)
New Revision: 47
Added:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SerializableDataModel.java
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UISelector.java
Modified:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/AjaxDataEncoder.java
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/DataComponentState.java
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/DataVisitor.java
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/ExtendedDataModel.java
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/Range.java
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/RepeatState.java
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SequenceDataModel.java
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SequenceRange.java
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UIRepeat.java
Log:
Fix Issue
http://jira.jboss.com/jira/browse/AJSF-11 in 1.0 branch
Modified:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/AjaxDataEncoder.java
===================================================================
---
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/AjaxDataEncoder.java 2007-03-30
17:44:16 UTC (rev 46)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/AjaxDataEncoder.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -1,7 +1,7 @@
/**
* License Agreement.
*
- * Ajax4jsf 1.0 - Natural Ajax for Java Server Faces (JSF)
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
Modified:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/DataComponentState.java
===================================================================
---
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/DataComponentState.java 2007-03-30
17:44:16 UTC (rev 46)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/DataComponentState.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -1,7 +1,7 @@
/**
* License Agreement.
*
- * Ajax4jsf 1.0 - Natural Ajax for Java Server Faces (JSF)
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
@@ -32,7 +32,7 @@
* @author shura
*
*/
-public interface DataComponentState extends StateHolder {
+public interface DataComponentState {
/**
* Build used data objects range for iteration.
Modified:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/DataVisitor.java
===================================================================
---
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/DataVisitor.java 2007-03-30
17:44:16 UTC (rev 46)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/DataVisitor.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -1,7 +1,7 @@
/**
* License Agreement.
*
- * Ajax4jsf 1.0 - Natural Ajax for Java Server Faces (JSF)
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
Modified:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/ExtendedDataModel.java
===================================================================
---
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/ExtendedDataModel.java 2007-03-30
17:44:16 UTC (rev 46)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/ExtendedDataModel.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -1,7 +1,7 @@
/**
* License Agreement.
*
- * Ajax4jsf 1.0 - Natural Ajax for Java Server Faces (JSF)
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
@@ -57,7 +57,7 @@
* for example - to avoid requests to database until all data is validated.
* @return
*/
- public ExtendedDataModel getSerializableModel(Range range){
+ public SerializableDataModel getSerializableModel(Range range){
// By default, model not serializable.
return null;
}
Modified: branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/Range.java
===================================================================
---
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/Range.java 2007-03-30
17:44:16 UTC (rev 46)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/Range.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -1,7 +1,7 @@
/**
* License Agreement.
*
- * Ajax4jsf 1.0 - Natural Ajax for Java Server Faces (JSF)
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
Modified:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/RepeatState.java
===================================================================
---
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/RepeatState.java 2007-03-30
17:44:16 UTC (rev 46)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/RepeatState.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -1,7 +1,7 @@
/**
* License Agreement.
*
- * Ajax4jsf 1.0 - Natural Ajax for Java Server Faces (JSF)
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
@@ -29,13 +29,17 @@
* @author shura
*
*/
-public class RepeatState implements DataComponentState {
+public class RepeatState implements DataComponentState,Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5552520123654180445L;
+
private int _rows = -1;
private int _first = 0;
- private boolean _transient = true;
/**
* @return the first
@@ -73,37 +77,5 @@
return new SequenceRange(getFirst(),getRows());
}
- /* (non-Javadoc)
- * @see javax.faces.component.StateHolder#isTransient()
- */
- public boolean isTransient() {
- return this._transient;
- }
- /* (non-Javadoc)
- * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext,
java.lang.Object)
- */
- public void restoreState(FacesContext context, Object state) {
- }
-
- /* (non-Javadoc)
- * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
- */
- public Object saveState(FacesContext context) {
- return null;
- }
-
- private static final class State implements Serializable{
- private int first;
- private int rows;
- }
-
- /* (non-Javadoc)
- * @see javax.faces.component.StateHolder#setTransient(boolean)
- */
- public void setTransient(boolean newTransientValue) {
- this._transient = newTransientValue;
-
- }
-
}
Modified:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SequenceDataModel.java
===================================================================
---
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SequenceDataModel.java 2007-03-30
17:44:16 UTC (rev 46)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SequenceDataModel.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -1,7 +1,7 @@
/**
* License Agreement.
*
- * Ajax4jsf 1.0 - Natural Ajax for Java Server Faces (JSF)
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
@@ -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,30 +111,23 @@
* @see org.ajax4jsf.ajax.repeat.ExtendedDataModel#getRowKey()
*/
public Object getRowKey() {
- int index = wrapped.getRowIndex();
+ int index = wrappedModel.getRowIndex();
if(index<0){
return null;
}
return new Integer(index);
}
- /* (non-Javadoc)
- * @see
org.ajax4jsf.ajax.repeat.ExtendedDataModel#getSerializableModel(org.ajax4jsf.ajax.repeat.Range)
- */
- public ExtendedDataModel getSerializableModel(Range range) {
- // By default data not serializable
- return null;
- }
/* (non-Javadoc)
* @see org.ajax4jsf.ajax.repeat.ExtendedDataModel#setRowKey(java.lang.Object)
*/
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());
}
}
@@ -143,7 +136,7 @@
*/
public int getRowCount() {
// TODO Auto-generated method stub
- return wrapped.getRowCount();
+ return wrappedModel.getRowCount();
}
/* (non-Javadoc)
@@ -151,7 +144,7 @@
*/
public Object getRowData() {
// TODO Auto-generated method stub
- return wrapped.getRowData();
+ return wrappedModel.getRowData();
}
/* (non-Javadoc)
@@ -159,7 +152,7 @@
*/
public int getRowIndex() {
// TODO Auto-generated method stub
- return wrapped.getRowIndex();
+ return wrappedModel.getRowIndex();
}
/* (non-Javadoc)
@@ -167,7 +160,7 @@
*/
public Object getWrappedData() {
// TODO Auto-generated method stub
- return wrapped.getWrappedData();
+ return wrappedModel.getWrappedData();
}
/* (non-Javadoc)
@@ -175,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:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SequenceRange.java
===================================================================
---
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SequenceRange.java 2007-03-30
17:44:16 UTC (rev 46)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SequenceRange.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -1,7 +1,7 @@
/**
* License Agreement.
*
- * Ajax4jsf 1.0 - Natural Ajax for Java Server Faces (JSF)
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
Added:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SerializableDataModel.java
===================================================================
---
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SerializableDataModel.java
(rev 0)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/SerializableDataModel.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -0,0 +1,39 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.ajax.repeat;
+
+import java.io.Serializable;
+
+/**
+ * Serializable version of {@link ExtendedDataModel}, for save lightweight version of
data
+ *
+ * @author shura
+ *
+ */
+public abstract class SerializableDataModel extends ExtendedDataModel implements
Serializable {
+
+ /**
+ * Method called after update all model values. For example, developer can update
+ * database with new values of modified rows.
+ */
+ public abstract void update();
+}
Modified:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java
===================================================================
---
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java 2007-03-30
17:44:16 UTC (rev 46)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -1,7 +1,7 @@
/**
* License Agreement.
*
- * Ajax4jsf 1.0 - Natural Ajax for Java Server Faces (JSF)
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
@@ -34,6 +34,7 @@
import javax.faces.application.FacesMessage;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.NamingContainer;
+import javax.faces.component.StateHolder;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
@@ -49,6 +50,8 @@
import org.ajax4jsf.framework.ajax.AjaxEvent;
import org.ajax4jsf.framework.renderer.AjaxChildrenRenderer;
+import com.sun.org.apache.bcel.internal.generic.GETSTATIC;
+
/**
* Base class for iterable components, like dataTable, Tomahawk dataList,
* Facelets repeat, tree etc., with support for partial rendering on AJAX
@@ -59,6 +62,11 @@
*/
public abstract class UIDataAdaptor extends UIData implements AjaxDataEncoder {
+ /**
+ *
+ */
+ public static final String COMPONENT_STATE_ATTRIBUTE = "componentState";
+
public final static DataModel EMPTY_MODEL = new ListDataModel(
Collections.EMPTY_LIST);
@@ -73,7 +81,7 @@
public void process(FacesContext context, Object rowKey, Object argument)
throws IOException {
- setRowKey(context,rowKey);
+ setRowKey(context, rowKey);
Iterator childIterator = dataChildren();
while (childIterator.hasNext()) {
UIComponent component = (UIComponent) childIterator.next();
@@ -126,19 +134,19 @@
* Base client id's of this component, for wich invoked encode... methods.
* Component will save state and serialisable models for this keys only.
*/
- private transient Set _encoded;
+ private Set _encoded;
/**
* Storage for data model instances with different client id's of this
* component. In case of child for UIData component, this map will keep data
* models for different iterations between phases.
*/
- private transient Map _modelsMap = new HashMap();
+ private Map _modelsMap = new HashMap();
/**
* Reference for curent data model
*/
- private transient ExtendedDataModel _currentModel = null;
+ private ExtendedDataModel _currentModel = null;
/**
* States of this component for diferent iterations, same as for models.
@@ -148,13 +156,15 @@
/**
* Reference for current component state.
*/
- private transient DataComponentState _currentState = null;
+ private DataComponentState _currentState = null;
/**
* Name of EL variable for current component state.
*/
- private String _varState;
+ private String _stateVar;
+ private String _rowKeyVar;
+
/**
* Key for current value in model.
*/
@@ -170,18 +180,33 @@
*
* @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)
*
@@ -253,18 +278,22 @@
return this._rowKey;
}
- public void setRowKey(Object key){
+ public void setRowKey(Object key) {
setRowKey(FacesContext.getCurrentInstance(), key);
}
+
/**
* Setup current roy by key. Perform same functionality as
* {@link UIData#setRowIndex(int)}, but for key object - it may be not only
* row number in sequence data, but, for example - path to current node in
* tree.
- * @param faces - current FacesContext
- * @param key new key value.
+ *
+ * @param faces -
+ * current FacesContext
+ * @param key
+ * new key value.
*/
- public void setRowKey(FacesContext faces,Object key) {
+ public void setRowKey(FacesContext faces, Object key) {
ExtendedDataModel localModel = getExtendedDataModel();
// save child state
this.saveChildState(faces);
@@ -349,7 +378,7 @@
/**
* Instance of default renderer in ajax responses.
*/
- private transient AjaxChildrenRenderer _childrenRenderer = null;
+ private AjaxChildrenRenderer _childrenRenderer = null;
/**
* getter for simple {@link AjaxChildrenRenderer} instance in case of ajax
@@ -389,23 +418,52 @@
* 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.
- * @param faces current faces context
+ *
+ * @param faces
+ * current faces context
* @param localModel
* @param rowSelected
*/
- protected void setupVariable(FacesContext faces, DataModel localModel, boolean
rowSelected) {
- String var = getVar();
+ protected void setupVariable(FacesContext faces, DataModel localModel,
+ boolean rowSelected) {
+ Map attrs = faces.getExternalContext().getRequestMap();
+ 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 var
+ * @param attrs
+ * @param rowData
+ */
+ private void setupVariable(String var, Map attrs, Object rowData) {
if (var != null) {
- Map attrs = faces.getExternalContext().getRequestMap();
- if (rowSelected && isRowAvailable()) {
- attrs.put(getVar(), localModel.getRowData());
- } 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.
*/
@@ -460,7 +518,7 @@
*
* @param state
*/
- protected void setComponentState(DataComponentState state) {
+ public void setComponentState(DataComponentState state) {
this._currentState = state;
this._statesMap.put(getBaseClientId(getFacesContext()),
this._currentState);
@@ -470,17 +528,37 @@
* @return current state of this component.
*/
public DataComponentState getComponentState() {
+ DataComponentState state = null;
if (this._currentState == null) {
- String baseClientId = getBaseClientId(getFacesContext());
- DataComponentState state = (DataComponentState) this._statesMap
- .get(baseClientId);
- if (null == state) {
- state = createComponentState();
- this._statesMap.put(baseClientId, state);
+ // Check for binding state to user bean.
+ ValueBinding valueBinding = getValueBinding(UIDataAdaptor.COMPONENT_STATE_ATTRIBUTE);
+ FacesContext facesContext = getFacesContext();
+ if (null != valueBinding) {
+ state = (DataComponentState) valueBinding
+ .getValue(facesContext);
+ if (null == state) {
+ // Create default state
+ state = createComponentState();
+ if (!valueBinding.isReadOnly(facesContext)) {
+ // Store created state in user bean.
+ valueBinding.setValue(facesContext, state);
+ }
+ }
+ } else {
+ // Check for stored state in map for parent iterations
+ String baseClientId = getBaseClientId(facesContext);
+ state = (DataComponentState) this._statesMap.get(baseClientId);
+ if (null == state) {
+ // Create default component state
+ state = createComponentState();
+ this._statesMap.put(baseClientId, state);
+ }
+ this._currentState = state;
}
- this._currentState = state;
+ } else {
+ state = this._currentState;
}
- return this._currentState;
+ return state;
}
/**
@@ -497,7 +575,8 @@
StringBuffer id = new StringBuffer(getBaseClientId(faces));
Object rowKey = getRowKey();
if (rowKey != null) {
- id.append(NamingContainer.SEPARATOR_CHAR).append(rowKey.toString());
+ id.append(NamingContainer.SEPARATOR_CHAR).append(
+ rowKey.toString());
}
Renderer renderer;
if (null != (renderer = getRenderer(faces))) {
@@ -571,7 +650,7 @@
}
}
- private transient Object origValue;
+ private Object origValue;
/**
* Save current state of data variable.
@@ -580,14 +659,17 @@
captureOrigValue(FacesContext.getCurrentInstance());
}
- /**
+ /**
* Save current state of data variable.
- * @param faces current faces context
+ *
+ * @param faces
+ * current faces context
*/
public void captureOrigValue(FacesContext faces) {
- if (getVar() != null) {
+ String var = getVar();
+ if (var != null) {
Map attrs = faces.getExternalContext().getRequestMap();
- this.origValue = attrs.get(getVar());
+ this.origValue = attrs.get(var);
}
}
@@ -597,17 +679,21 @@
public void restoreOrigValue() {
restoreOrigValue(FacesContext.getCurrentInstance());
}
+
/**
* Restore value of data variable after processing phase.
- * @param faces current faces context
+ *
+ * @param faces
+ * current faces context
*/
public void restoreOrigValue(FacesContext faces) {
- if (getVar() != null) {
+ String var = getVar();
+ if (var != null) {
Map attrs = faces.getExternalContext().getRequestMap();
if (this.origValue != null) {
- attrs.put(getVar(), this.origValue);
+ attrs.put(var, this.origValue);
} else {
- attrs.remove(getVar());
+ attrs.remove(var);
}
}
}
@@ -615,7 +701,7 @@
/**
* Saved values of {@link EditableValueHolder} fields per iterations.
*/
- private transient Map childState;
+ private Map childState;
/**
* @param faces
@@ -638,7 +724,8 @@
/**
* Save values of {@link EditableValueHolder} fields before change current
* row.
- * @param faces
+ *
+ * @param faces
*/
protected void saveChildState(FacesContext faces) {
@@ -684,7 +771,8 @@
/**
* Restore values of {@link EditableValueHolder} fields after change current
* row.
- * @param faces
+ *
+ * @param faces
*/
protected void restoreChildState(FacesContext faces) {
@@ -702,7 +790,7 @@
* @param faces
* @param c
* @param childState
- *
+ *
*/
private void restoreChildState(FacesContext faces, UIComponent c,
Map childState) {
@@ -768,11 +856,12 @@
Object argument) {
// stop if not rendered
- if (!this.isRendered())
+ if (!this.isRendered()) {
return;
+ }
// reset rowIndex
this.captureOrigValue(faces);
- this.setRowKey(faces,null);
+ this.setRowKey(faces, null);
try {
Iterator fixedChildren = fixedChildren();
while (fixedChildren.hasNext()) {
@@ -784,7 +873,7 @@
} catch (Exception e) {
throw new FacesException(e);
} finally {
- this.setRowKey(faces,null);
+ this.setRowKey(faces, null);
this.restoreOrigValue(faces);
}
}
@@ -823,7 +912,7 @@
* Reset per-request fields in component.
*
* @param faces
- *
+ *
*/
protected void resetComponent(FacesContext faces) {
// resetDataModel();
@@ -837,6 +926,13 @@
if (!this.isRendered())
return;
this.iterate(faces, updateVisitor, argument);
+ ExtendedDataModel dataModel = getExtendedDataModel();
+ // If no validation errors, update values for serializable model,
+ // restored from view.
+ if (dataModel instanceof SerializableDataModel && (!keepSaved(faces))) {
+ SerializableDataModel serializableModel = (SerializableDataModel) dataModel;
+ serializableModel.update();
+ }
}
public void processUpdates(FacesContext faces) {
@@ -943,7 +1039,7 @@
}
public void populate(EditableValueHolder evh) {
- this.value = evh.getValue();
+ this.value = evh.getLocalValue();
this.valid = evh.isValid();
this.submittedValue = evh.getSubmittedValue();
this.localValueSet = evh.isLocalValueSet();
@@ -991,12 +1087,12 @@
Object oldRowKey = getRowKey();
FacesContext faces = FacesContext.getCurrentInstance();
captureOrigValue(faces);
- setRowKey(faces,revent.getKey());
+ setRowKey(faces, revent.getKey());
FacesEvent rowEvent = revent.getTarget();
rowEvent.getComponent().broadcast(rowEvent);
// For Ajax events, keep row value.
if (!(rowEvent instanceof AjaxEvent)) {
- setRowKey(faces,oldRowKey);
+ setRowKey(faces, oldRowKey);
restoreOrigValue(faces);
}
return;
@@ -1101,9 +1197,17 @@
*/
private static final long serialVersionUID = 9037454770537726418L;
+ /**
+ * Flag setted to true if componentState implements StateHolder
+ */
+ private boolean stateInHolder = false;
+
+ /**
+ * Serializable componentState or
+ */
private Object componentState;
- private ExtendedDataModel model;
+ private SerializableDataModel model;
}
public void restoreState(FacesContext faces, Object object) {
@@ -1118,8 +1222,16 @@
.hasNext();) {
Map.Entry stateEntry = (Map.Entry) iter.next();
PerIdState idState = (PerIdState) stateEntry.getValue();
- DataComponentState compState = createComponentState();
- compState.restoreState(faces, idState.componentState);
+ DataComponentState compState;
+ if (idState.stateInHolder) {
+ // TODO - change RichFaces Tree component, for remove reference
+ // to component from state.
+ compState = createComponentState();
+ ((StateHolder) compState).restoreState(faces,
+ idState.componentState);
+ } else {
+ compState = (DataComponentState) idState.componentState;
+ }
Object key = stateEntry.getKey();
this._statesMap.put(key, compState);
this._modelsMap.put(key, idState.model);
@@ -1130,6 +1242,7 @@
DataState state = new DataState();
state.superState = super.saveState(faces);
state.ajaxKeys = this._ajaxKeys;
+ Set encodedIds = getEncodedIds();
// Save all states of component and data model for all valies of
// clientId, encoded in this request.
for (Iterator iter = this._statesMap.entrySet().iterator(); iter
@@ -1137,13 +1250,24 @@
Map.Entry stateEntry = (Map.Entry) iter.next();
DataComponentState dataComponentState = ((DataComponentState) stateEntry
.getValue());
- Set encodedIds = getEncodedIds();
Object stateKey = stateEntry.getKey();
if (encodedIds.isEmpty() || encodedIds.contains(stateKey)) {
PerIdState idState = new PerIdState();
idState.model = getExtendedDataModel().getSerializableModel(
dataComponentState.getRange());
- idState.componentState = dataComponentState.saveState(faces);
+ // Save component state , depended if implemented interfaces.
+ if (null == dataComponentState) {
+ idState.componentState = null;
+ } 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.
+ // Change this code to reference for saveAttachedState.
+ idState.componentState = ((StateHolder) dataComponentState)
+ .saveState(faces);
+ idState.stateInHolder = true;
+ }
if (null != idState.model || null != idState.componentState) {
state.componentStates.put(stateKey, idState);
}
Modified:
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UIRepeat.java
===================================================================
---
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UIRepeat.java 2007-03-30
17:44:16 UTC (rev 46)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UIRepeat.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -1,7 +1,7 @@
/**
* License Agreement.
*
- * Ajax4jsf 1.0 - Natural Ajax for Java Server Faces (JSF)
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
@@ -26,6 +26,7 @@
import java.util.Iterator;
import java.util.List;
+import javax.faces.context.FacesContext;
import javax.faces.model.ArrayDataModel;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
@@ -41,22 +42,32 @@
* @see org.ajax4jsf.ajax.repeat.UIDataAdaptor#createComponentState()
*/
protected DataComponentState createComponentState() {
- // TODO Auto-generated method stub
- return new RepeatState(){
- public int getFirst() {
- return UIRepeat.this.getFirst();
+ // Create component state based on this instance.
+ return new DataComponentState(){
+
+ public Range getRange() {
+ return new SequenceRange(getFirst(),getRows());
}
- public int getRows() {
- return UIRepeat.this.getRows();
+
+ public boolean isTransient() {
+ // TODO Auto-generated method stub
+ return false;
}
-
- public void setFirst(int first) {
- UIRepeat.this.setFirst(first);
+
+ public void restoreState(FacesContext arg0, Object arg1) {
+ // TODO Auto-generated method stub
+
}
-
- public void setRows(int rows) {
- UIRepeat.this.setRows(rows);
+
+ public Object saveState(FacesContext arg0) {
+ // TODO Auto-generated method stub
+ return null;
}
+
+ public void setTransient(boolean arg0) {
+ // TODO Auto-generated method stub
+
+ }
};
}
@@ -65,8 +76,7 @@
* @see org.ajax4jsf.ajax.repeat.UIDataAdaptor#createDataModel()
*/
protected ExtendedDataModel createDataModel() {
- // TODO Auto-generated method stub
- return new SequenceDataModel(getDataModel());
+ return (ExtendedDataModel) getDataModel();
}
protected DataModel getDataModel(){
@@ -75,19 +85,21 @@
Object current = getValue();
DataModel model;
if (current == null) {
- model = new ListDataModel(Collections.EMPTY_LIST);
+ model = new SequenceDataModel(new ListDataModel(Collections.EMPTY_LIST));
+ } else if (current instanceof ExtendedDataModel) {
+ model = (DataModel) current;
} else if (current instanceof DataModel) {
- model = (DataModel) current;
+ model = new SequenceDataModel((DataModel) current);
} else if (current instanceof List) {
- model = new ListDataModel((List) current);
+ model = new SequenceDataModel(new ListDataModel((List) current));
} else if (Object[].class.isAssignableFrom(current.getClass())) {
- model = new ArrayDataModel((Object[]) current);
+ model = new SequenceDataModel(new ArrayDataModel((Object[]) current));
} else if (current instanceof ResultSet) {
- model = new ResultSetDataModel((ResultSet) current);
+ model = new SequenceDataModel(new ResultSetDataModel((ResultSet) current));
// } else if (current instanceof Result) {
// model = new ResultDataModel((Result) current);
} else {
- model = new ScalarDataModel(current);
+ model = new SequenceDataModel(new ScalarDataModel(current));
}
return (model);
}
Added: branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UISelector.java
===================================================================
--- branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UISelector.java
(rev 0)
+++
branches/version_1_0_7/src/framework/java/org/ajax4jsf/ajax/repeat/UISelector.java 2007-03-31
00:27:58 UTC (rev 47)
@@ -0,0 +1,114 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.ajax.repeat;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.framework.renderer.AjaxChildrenRenderer;
+import org.apache.commons.beanutils.PropertyUtils;
+
+/**
+ * Base class for component, performed AJAX encoding on selected values in
+ * iterable components ( UIData, trees etc )
+ *
+ * @author shura
+ *
+ */
+public abstract class UISelector extends UIComponentBase implements
+ AjaxDataEncoder {
+
+ private static final AjaxChildrenRenderer childrenRenderer = new AjaxChildrenRenderer()
{
+
+ protected Class getComponentClass() {
+ return UISelector.class;
+ }
+
+ };
+
+ /**
+ * Name of serRow ( or simple ) method for setup current value in iterable
+ * component
+ *
+ * @parameter
+ * @return the acceptClass
+ */
+ public abstract String getIterationProperty();
+
+ /**
+ * @param newSelectMethod
+ * the value to set
+ */
+ public abstract void setIterationProperty(String newSelectMethod);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ajax.AjaxChildrenEncoder#encodeAjaxChild(javax.faces.context.FacesContext,
+ * java.lang.String, java.util.Set, java.util.Set)
+ */
+ public void encodeAjaxChild(FacesContext context, String path, Set ids,
+ Set renderedAreas) throws IOException {
+ if (getChildCount() != 1) {
+ throw new FacesException(
+ "Selector component must have one, and only one, child");
+ }
+ UIComponent child = (UIComponent) getChildren().get(0);
+ Set ajaxKeys = getAjaxKeys();
+ if (null != ajaxKeys) {
+ String iterationProperty = getIterationProperty();
+ try {
+ Object savedKey = PropertyUtils.getProperty(child,
+ iterationProperty);
+ for (Iterator iter = ajaxKeys.iterator(); iter.hasNext();) {
+ Object key = (Object) iter.next();
+ PropertyUtils.setProperty(child, iterationProperty, key);
+ if (true) {
+ childrenRenderer.encodeAjaxChild(context, this, path,
+ ids, renderedAreas);
+ }
+
+ }
+ PropertyUtils.setProperty(child, iterationProperty, savedKey);
+
+ } catch (IllegalAccessException e) {
+ throw new FacesException(
+ "Illegal access to iteration selection property "+iterationProperty+"
on component "+child.getClientId(context),e);
+ } catch (InvocationTargetException e) {
+ throw new FacesException(
+ "Error in iteration selection property "+iterationProperty+" on
component "+child.getClientId(context),e.getCause());
+ } catch (NoSuchMethodException e) {
+ throw new FacesException(
+ "No iteration selection property "+iterationProperty+" on component
"+child.getClientId(context),e);
+ }
+ }
+
+ }
+
+}