Author: andrei_exadel
Date: 2009-01-05 06:07:37 -0500 (Mon, 05 Jan 2009)
New Revision: 12092
Modified:
trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsHandler.java
Log:
RF-5300
Modified: trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsHandler.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsHandler.java 2009-01-05
10:24:20 UTC (rev 12091)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsHandler.java 2009-01-05
11:07:37 UTC (rev 12092)
@@ -28,6 +28,7 @@
package org.richfaces.taglib;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
@@ -41,6 +42,7 @@
import javax.faces.component.UIComponent;
import javax.servlet.jsp.JspTagException;
+import org.richfaces.component.UIColumn;
import org.richfaces.el.ELBuilder;
import org.richfaces.iterator.ForEachIterator;
import org.richfaces.iterator.SimpleForEachIterator;
@@ -65,6 +67,8 @@
public class ColumnsHandler extends MetaTagHandler {
com.sun.facelets.tag.jsf.ComponentHandler handler;
+
+ static final String DYNAMIC_COLUMN_MARKER = "_richfaces_columns";
/** value attribute */
private TagAttribute value;
@@ -181,6 +185,13 @@
});
return ruleset;
}
+
+ @Override
+ protected void applyNextHandler(FaceletContext ctx, UIComponent c)
+ throws IOException, FacesException, ELException {
+ c.getAttributes().put(DYNAMIC_COLUMN_MARKER, Boolean.TRUE);
+ super.applyNextHandler(ctx, c);
+ }
};
}
@@ -188,12 +199,12 @@
/**
* Extracts tags attributes values
*/
- private void initVariables(FaceletContext ctx/*, IterationContext itContext*/) {
- initColumnsCount(ctx/*, itContext*/);
- initIndex(ctx/*, itContext*/);
- initVar(ctx/*, itContext*/);
- initBegin(ctx/*, itContext*/);
- initEnd(ctx/*, itContext*/);
+ private void initVariables(FaceletContext ctx) {
+ initColumnsCount(ctx);
+ initIndex(ctx);
+ initVar(ctx);
+ initBegin(ctx);
+ initEnd(ctx);
}
/**
@@ -201,9 +212,9 @@
*
* @throws JspTagException
*/
- private void prepare(FaceletContext ctx/*, IterationContext itContext*/) {
+ private void prepare(FaceletContext ctx) {
- initVariables(ctx/*, itContext*/);
+ initVariables(ctx);
IterationContext itContext = getIterationContext();
@@ -231,20 +242,20 @@
// TODO: handle exception
}
- correctFirst(ctx/*, itContext*/);
+ correctFirst(ctx);
}
/**
* Inits first iteration item
*/
- private void correctFirst(FaceletContext ctx/*, IterationContext itContext*/) {
+ private void correctFirst(FaceletContext ctx) {
IterationContext itContext = getIterationContext();
if (itContext.items != null) {
if (itContext._begin > 0 && (itContext._index < itContext._begin)) {
- while ((itContext._index < itContext._begin && hasNext(/*itContext*/))) {
- next(ctx/*, itContext*/);
+ while ((itContext._index < itContext._begin && hasNext())) {
+ next(ctx);
}
- if (!hasNext(/*itContext*/)) {
+ if (!hasNext()) {
itContext._index = 0;
}
}
@@ -257,7 +268,7 @@
* @return
* @throws JspTagException
*/
- private boolean hasNext(/*IterationContext itContext*/) {
+ private boolean hasNext() {
IterationContext itContext = getIterationContext();
try {
if (itContext._end != 0) {
@@ -277,7 +288,7 @@
* @return
* @throws JspTagException
*/
- private Object next(FaceletContext ctx/*, IterationContext itContext*/) {
+ private Object next(FaceletContext ctx) {
IterationContext itContext = getIterationContext();
try {
Object o = itContext.items.next();
@@ -291,7 +302,7 @@
/**
* Extracts integer value from end attr
*/
- private void initColumnsCount(FaceletContext ctx/*, IterationContext itContext*/) {
+ private void initColumnsCount(FaceletContext ctx) {
IterationContext itContext = getIterationContext();
this.columns = getAttribute("columns");
if (columns != null) {
@@ -311,7 +322,7 @@
/**
* Extracts integer value from begin attr
*/
- private void initBegin(FaceletContext ctx/*, IterationContext itContext*/) {
+ private void initBegin(FaceletContext ctx) {
IterationContext itContext = getIterationContext();
this.begin = getAttribute("begin");
if (begin != null) {
@@ -337,7 +348,7 @@
/**
* Extracts integer value from end attr
*/
- private void initEnd(FaceletContext ctx/*, IterationContext itContext*/) {
+ private void initEnd(FaceletContext ctx) {
IterationContext itContext = getIterationContext();
this.end = getAttribute("end");
if (end != null) {
@@ -362,7 +373,7 @@
/**
* Extracts string value from var attr
*/
- private void initVar(FaceletContext ctx/*, IterationContext itContext*/) {
+ private void initVar(FaceletContext ctx) {
IterationContext itContext = getIterationContext();
this.var = getAttribute("var");
if (var != null) {
@@ -378,7 +389,7 @@
/**
* Extracts string value from index attr
*/
- private void initIndex(FaceletContext ctx/*, IterationContext itContext*/) {
+ private void initIndex(FaceletContext ctx) {
IterationContext itContext = getIterationContext();
this.index = getAttribute("index");
if (index != null) {
@@ -420,42 +431,52 @@
IterationContext iterationContext = new IterationContext();
iterationContextLocal.set(iterationContext);
- prepare(ctx/*, iterationContext*/); // prepare data
+ clearOldColumns(parent);
+ prepare(ctx); // prepare data
try {
- while (hasNext(/*iterationContext*/)) { // for each
- exposeVariables(ctx/*, iterationContext*/);
- //super.apply(ctx, parent);
+ while (hasNext()) { // for each
+ exposeVariables(ctx);
handler.apply(ctx, parent);
- next(ctx/*, iterationContext*/);
+ next(ctx);
}
} catch (Exception e) {
// TODO: handle exception
} finally {
- release(/*iterationContext*/);
- unExposeVariables(ctx/*, iterationContext*/);
+ release();
+ unExposeVariables(ctx);
}
}
- protected void applyNextHandler(FaceletContext ctx, UIComponent c)
- throws IOException, FacesException, ELException {
- // TODO Auto-generated method stub
- //super.applyNextHandler(ctx, c);
-
+
+ private void clearOldColumns (UIComponent parent) {
+ if (parent.getChildren() != null) {
+ Iterator<UIComponent> childrenIt = parent.getChildren().iterator();
+ List<UIComponent> forDelete = new ArrayList<UIComponent>();
+ while (childrenIt.hasNext()) {
+ UIComponent c = childrenIt.next();
+ if (c instanceof UIColumn && c.getAttributes().get(DYNAMIC_COLUMN_MARKER)
!= null
+ && (Boolean)c.getAttributes().get(DYNAMIC_COLUMN_MARKER)) {
+ forDelete.add(c);
+ }
+ }
+ if (forDelete.size() > 0) {
+ Iterator<UIComponent> it = forDelete.iterator();
+ while (it.hasNext()) {
+ parent.getChildren().remove(it.next());
+ }
+ }
+ }
+
}
-
- private void onComponentCreated(UIComponent c) {
-
- }
-
/**
* Sets page request variables
*
* @throws JspTagException
*/
- private void exposeVariables(FaceletContext ctx/*, IterationContext itContext*/) {
+ private void exposeVariables(FaceletContext ctx) {
IterationContext itContext = getIterationContext();
VariableMapper vm = ctx.getVariableMapper();
int k = itContext._index;
@@ -465,7 +486,7 @@
if (value != null) {
ValueExpression srcVE = value.getValueExpression(ctx,
Object.class);
- ValueExpression ve = getVarExpression(ctx, srcVE/*, itContext*/);
+ ValueExpression ve = getVarExpression(ctx, srcVE);
vm.setVariable(itContext._itemId, ve);
}
}
@@ -488,7 +509,7 @@
* Removes page attributes that we have exposed and, if applicable, restores
* them to their prior values (and scopes).
*/
- private void unExposeVariables(FaceletContext ctx/*, IterationContext itContext*/) {
+ private void unExposeVariables(FaceletContext ctx) {
IterationContext itContext = getIterationContext();
VariableMapper vm = ctx.getVariableMapper();
// "nested" variables are now simply removed
@@ -533,7 +554,7 @@
/**
* Release iteration variables
*/
- private void release(/*IterationContext itContext*/) {
+ private void release() {
IterationContext itContext = getIterationContext();
itContext.items = null;
itContext._index = 0;