Author: nbelaevski
Date: 2010-03-04 12:11:54 -0500 (Thu, 04 Mar 2010)
New Revision: 16527
Added:
root/examples/trunk/components/core-demo/src/main/java/org/richfaces/demo/RepeatBean.java
root/examples/trunk/components/core-demo/src/main/webapp/repeat.xhtml
root/framework/trunk/impl/src/main/java/org/richfaces/component/SequenceIterationStatus.java
root/framework/trunk/impl/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java
root/ui/trunk/components/core/src/main/java/org/richfaces/component/UIRepeat.java
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/RepeatRenderer.java
Modified:
root/examples/trunk/components/core-demo/src/main/webapp/welcome.xhtml
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java
root/framework/trunk/impl/src/main/java/org/richfaces/component/UISequence.java
root/ui/trunk/components/core/pom.xml
root/ui/trunk/components/core/src/main/config/faces-config.xml
root/ui/trunk/components/core/src/main/resources/META-INF/a4j.taglib.xml
root/ui/trunk/version-matrix/pom.xml
Log:
a4j:repeat check-in
Added:
root/examples/trunk/components/core-demo/src/main/java/org/richfaces/demo/RepeatBean.java
===================================================================
---
root/examples/trunk/components/core-demo/src/main/java/org/richfaces/demo/RepeatBean.java
(rev 0)
+++
root/examples/trunk/components/core-demo/src/main/java/org/richfaces/demo/RepeatBean.java 2010-03-04
17:11:54 UTC (rev 16527)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@ManagedBean
+@SessionScoped
+public class RepeatBean {
+
+ public static final class Data {
+
+ private String text;
+
+ /**
+ * @return the text
+ */
+ public String getText() {
+ return text;
+ }
+
+ /**
+ * @param text the text to set
+ */
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ }
+
+ private List<Data> dataList;
+
+ private Data selectedDataItem = null;
+
+ public RepeatBean() {
+ dataList = new ArrayList<Data>();
+
+ for (int i = 0; i < 10; i++) {
+ Data data = new Data();
+ data.setText(MessageFormat.format("Item {0}", i));
+ dataList.add(data);
+ }
+ }
+
+ /**
+ * @return the data
+ */
+ public List<Data> getDataList() {
+ return dataList;
+ }
+
+ /**
+ * @return the selectedDataItem
+ */
+ public Data getSelectedDataItem() {
+ return selectedDataItem;
+ }
+
+ /**
+ * @param selectedDataItem the selectedDataItem to set
+ */
+ public void setSelectedDataItem(Data selectedDataItem) {
+ this.selectedDataItem = selectedDataItem;
+ }
+}
Added: root/examples/trunk/components/core-demo/src/main/webapp/repeat.xhtml
===================================================================
--- root/examples/trunk/components/core-demo/src/main/webapp/repeat.xhtml
(rev 0)
+++ root/examples/trunk/components/core-demo/src/main/webapp/repeat.xhtml 2010-03-04
17:11:54 UTC (rev 16527)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j">
+<f:view>
+ <h:head>
+ </h:head>
+ <h:body>
+ <h:form>
+ <h:panelGroup id="group">
+ #{repeatBean.selectedDataItem.text}
+ </h:panelGroup>
+
+ <ul>
+ <a4j:repeat value="#{repeatBean.dataList}" var="item"
iterationStatusVar="status">
+ <li>
+ <h:inputText value="#{item.text}" />
+ <h:commandLink value="Link">
+ <f:ajax render="@form" execute="@form" />
+ <f:setPropertyActionListener target="#{repeatBean.selectedDataItem}"
value="#{item}" />
+ </h:commandLink>
+ #{status}
+ </li>
+ </a4j:repeat>
+ </ul>
+ </h:form>
+ </h:body>
+</f:view>
+</html>
\ No newline at end of file
Modified: root/examples/trunk/components/core-demo/src/main/webapp/welcome.xhtml
===================================================================
--- root/examples/trunk/components/core-demo/src/main/webapp/welcome.xhtml 2010-03-04
13:58:58 UTC (rev 16526)
+++ root/examples/trunk/components/core-demo/src/main/webapp/welcome.xhtml 2010-03-04
17:11:54 UTC (rev 16527)
@@ -1,48 +1,27 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:ui="http://java.sun.com/jsf/facelets">
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
</h:head>
-<h:body>
-<center>
-<h1>Welcome To RichFaces 4.x Core Demo</h1>
-<ul>
-<li>
-<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/support.jsf">a4j:ajax</h:outputLink>
-</li>
-<li>
-<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/button.jsf">a4j:commandButton</h:outputLink>
-</li>
-<li>
-<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/link.jsf">a4j:commandLink</h:outputLink>
-</li>
-<li>
-<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/log.jsf">a4j:log</h:outputLink>
-</li>
-<li>
-<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/mediaOutput.jsf">a4j:mediaOutput</h:outputLink>
-</li>
-<li>
-<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/outputPanel.jsf">a4j:outputPanel</h:outputLink>
-</li>
-<li>
-<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/push.jsf">a4j:push</h:outputLink>
-</li>
-<li>
-<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/function.jsf">a4j:jsFunction</h:outputLink>
-</li>
-<li>
-<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/status.jsf">a4j:status</h:outputLink>
-</li>
-<li>
-<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/dynamicExecute.jsf">Server
side execute/render</h:outputLink>
-</li>
-<li>
-<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/queue.jsf">a4j:queue</h:outputLink>
-</li>
-</ul>
-</center>
-</h:body>
+<h:body>
+ <center>
+ <h1>Welcome To RichFaces 4.x Core Demo</h1>
+ <ul>
+ <li><h:link outcome="support">a4j:ajax</h:link></li>
+ <li><h:link
outcome="button">a4j:commandButton</h:link></li>
+ <li><h:link
outcome="link">a4j:commandLink</h:link></li>
+ <li><h:link outcome="log">a4j:log</h:link></li>
+ <li><h:link
outcome="mediaOutput">a4j:mediaOutput</h:link></li>
+ <li><h:link
outcome="outputPanel">a4j:outputPanel</h:link></li>
+ <li><h:link outcome="push">a4j:push</h:link></li>
+ <li><h:link
outcome="function">a4j:jsFunction</h:link></li>
+ <li><h:link
outcome="status">a4j:status</h:link></li>
+ <li><h:link outcome="dynamicExecute">Server side
execute/render</h:link></li>
+ <li><h:link outcome="queue">a4j:queue</h:link></li>
+ <li><h:link
outcome="repeat">a4j:repeat</h:link></li>
+ </ul>
+ </center>
+</h:body>
</html>
\ No newline at end of file
Added:
root/framework/trunk/impl/src/main/java/org/richfaces/component/SequenceIterationStatus.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/component/SequenceIterationStatus.java
(rev 0)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/component/SequenceIterationStatus.java 2010-03-04
17:11:54 UTC (rev 16527)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import java.io.Serializable;
+
+import javax.servlet.jsp.jstl.core.LoopTagStatus;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class SequenceIterationStatus implements LoopTagStatus, Serializable {
+
+ private static final long serialVersionUID = 1968212566967489719L;
+
+ private Integer begin;
+
+ private Integer count;
+
+ private Integer end;
+
+ private int index;
+
+ private Integer rowCount;
+
+ private boolean first;
+
+ private boolean last;
+
+ private boolean even;
+
+ public SequenceIterationStatus(Integer begin, Integer end, int index, Integer
rowCount) {
+ this.begin = begin;
+ this.end = end;
+ this.index = index;
+ this.rowCount = rowCount;
+
+ int iBegin = (begin != null ? begin.intValue() : 0);
+
+ int iRowCountEnd = (rowCount != null ? rowCount.intValue() - 1 :
Integer.MAX_VALUE);
+ int iEnd = (end != null ? end.intValue() : Integer.MAX_VALUE);
+ int iLastIdx = Math.min(iEnd, iRowCountEnd);
+
+ this.first = (index == iBegin);
+
+ this.last = (index >= iLastIdx);
+
+ this.count = (index - iBegin) + 1;
+ this.even = ((count % 2) == 0);
+ }
+
+ public Integer getBegin() {
+ return begin;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public Object getCurrent() {
+ return null;
+ }
+
+ public Integer getEnd() {
+ return end;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public Integer getStep() {
+ return 1;
+ }
+
+ public boolean isFirst() {
+ return first;
+ }
+
+ public boolean isLast() {
+ return last;
+ }
+
+ public Integer getRowCount() {
+ return rowCount;
+ }
+
+ public boolean isEven() {
+ return even;
+ }
+
+ public boolean isOdd() {
+ return !isEven();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("begin= " + begin);
+ sb.append(", end= " + end);
+ sb.append(", index= " + index);
+ sb.append(", count= " + count);
+ sb.append(", first= " + first);
+ sb.append(", last= " + last);
+ sb.append(", even= " + even);
+ sb.append(", rowCount= " + rowCount);
+
+ return sb.toString();
+ }
+}
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-03-04
13:58:58 UTC (rev 16526)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-03-04
17:11:54 UTC (rev 16527)
@@ -131,6 +131,58 @@
private String clientId;
private Object originalVarValue;
+ /**
+ * @author Nick Belaevski
+ *
+ */
+ private final class DataVisitorForVisitTree implements DataVisitor {
+ /**
+ *
+ */
+ private final VisitCallback callback;
+ /**
+ *
+ */
+ private final VisitContext visitContext;
+ /**
+ *
+ */
+ private boolean visitResult;
+
+ /**
+ * @param callback
+ * @param visitContext
+ */
+ private DataVisitorForVisitTree(VisitCallback callback, VisitContext
visitContext) {
+ this.callback = callback;
+ this.visitContext = visitContext;
+ }
+
+ public DataVisitResult process(FacesContext context, Object rowKey, Object
argument) {
+ setRowKey(context, rowKey);
+
+ if (isRowAvailable()) {
+ Iterator<UIComponent> dataChildrenItr = dataChildren();
+
+ while (dataChildrenItr.hasNext()) {
+ UIComponent dataChild = dataChildrenItr.next();
+
+ if (dataChild.visitTree(visitContext, callback)) {
+ visitResult = true;
+
+ return DataVisitResult.STOP;
+ }
+ }
+ }
+
+ return DataVisitResult.CONTINUE;
+ }
+
+ public boolean getVisitResult() {
+ return visitResult;
+ }
+ }
+
private enum PropertyKeys {
ajaxKeys, lastId, var, rowKeyVar, stateVar, childState, rowKeyConverter
}
@@ -139,6 +191,10 @@
super();
}
+ protected Map<String, Object> getVariablesMap(FacesContext facesContext) {
+ return facesContext.getExternalContext().getRequestMap();
+ }
+
/*
* (non-Javadoc)
* @see javax.faces.component.UIComponent#getFamily()
@@ -531,7 +587,7 @@
* @param rowSelected
*/
protected void setupVariable(FacesContext faces, boolean rowSelected) {
- Map<String, Object> attrs = faces.getExternalContext().getRequestMap();
+ Map<String, Object> attrs = getVariablesMap(faces);
if (rowSelected) {
@@ -674,7 +730,7 @@
String var = getVar();
if (var != null) {
- Map<String, Object> attrs =
faces.getExternalContext().getRequestMap();
+ Map<String, Object> attrs = getVariablesMap(faces);
this.originalVarValue = attrs.get(var);
}
@@ -691,7 +747,7 @@
String var = getVar();
if (var != null) {
- Map<String, Object> attrs =
faces.getExternalContext().getRequestMap();
+ Map<String, Object> attrs = getVariablesMap(faces);
if (this.originalVarValue != null) {
attrs.put(var, this.originalVarValue);
@@ -1087,31 +1143,11 @@
private boolean visitDataChildren(final VisitContext visitContext, final
VisitCallback callback) {
FacesContext facesContext = visitContext.getFacesContext();
- final boolean[] singleBoolean = new boolean[]{false};
- this.walk(facesContext, new DataVisitor() {
- public DataVisitResult process(FacesContext context, Object rowKey, Object
argument) {
- setRowKey(context, rowKey);
+ DataVisitorForVisitTree dataVisitor = new DataVisitorForVisitTree(callback,
visitContext);
+ this.walk(facesContext, dataVisitor, null);
- if (isRowAvailable()) {
- Iterator<UIComponent> dataChildrenItr = dataChildren();
-
- while (dataChildrenItr.hasNext()) {
- UIComponent dataChild = dataChildrenItr.next();
-
- if (dataChild.visitTree(visitContext, callback)) {
- singleBoolean[0] = true;
-
- return DataVisitResult.STOP;
- }
- }
- }
-
- return DataVisitResult.CONTINUE;
- }
- }, null);
-
- return singleBoolean[0];
+ return dataVisitor.getVisitResult();
}
@Override
Modified: root/framework/trunk/impl/src/main/java/org/richfaces/component/UISequence.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/component/UISequence.java 2010-03-04
13:58:58 UTC (rev 16526)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/component/UISequence.java 2010-03-04
17:11:54 UTC (rev 16527)
@@ -22,10 +22,10 @@
package org.richfaces.component;
-import org.ajax4jsf.model.DataComponentState;
-import org.ajax4jsf.model.ExtendedDataModel;
-import org.ajax4jsf.model.RepeatState;
-import org.ajax4jsf.model.SequenceDataModel;
+import java.sql.ResultSet;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import javax.faces.component.UINamingContainer;
import javax.faces.context.FacesContext;
@@ -37,16 +37,23 @@
import javax.faces.model.ResultSetDataModel;
import javax.faces.model.ScalarDataModel;
import javax.servlet.jsp.jstl.sql.Result;
-import java.sql.ResultSet;
-import java.util.Collections;
-import java.util.List;
+import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.RepeatState;
+import org.ajax4jsf.model.SequenceDataModel;
+import org.ajax4jsf.model.SequenceRange;
+
/**
* @author Nick Belaevski
*/
public class UISequence extends UIDataAdaptor {
+
+ private Object iterationStatusVarObject;
+
protected enum PropertyKeys {
- first, rows, value
+ first, rows, value, iterationStatusVar
}
@SuppressWarnings("unchecked")
@@ -116,7 +123,8 @@
}
/*
- * (non-Javadoc)
+ * (non-Javadoc)
+ *
* @see org.richfaces.component.UIDataAdaptor#getRowKeyConverter()
*/
@@ -150,4 +158,80 @@
public void setValue(Object value) {
getStateHelper().put(PropertyKeys.value, value);
}
+
+ public String getIterationStatusVar() {
+ return (String) getStateHelper().get(PropertyKeys.iterationStatusVar);
+ }
+
+ public void setIterationStatusVar(String iterationStatusVar) {
+ getStateHelper().put(PropertyKeys.iterationStatusVar, iterationStatusVar);
+ }
+
+ public int getRowIndex() {
+ return getExtendedDataModel().getRowIndex();
+ }
+
+ @Override
+ public void captureOrigValue(FacesContext faces) {
+ super.captureOrigValue(faces);
+
+ String iterationStatusVar = getIterationStatusVar();
+ if (iterationStatusVar != null) {
+ Map<String, Object> variablesMap = getVariablesMap(faces);
+
+ iterationStatusVarObject = variablesMap.get(iterationStatusVar);
+ }
+ }
+
+ @Override
+ public void restoreOrigValue(FacesContext faces) {
+ super.restoreOrigValue(faces);
+
+ String iterationStatusVar = getIterationStatusVar();
+ if (iterationStatusVar != null) {
+ Map<String, Object> variablesMap = getVariablesMap(faces);
+
+ if (iterationStatusVarObject != null) {
+ variablesMap.put(iterationStatusVar, iterationStatusVarObject);
+ } else {
+ variablesMap.remove(iterationStatusVar);
+ }
+ }
+ }
+
+ @Override
+ protected void setupVariable(FacesContext faces, boolean rowSelected) {
+ super.setupVariable(faces, rowSelected);
+
+ String iterationStatusVar = getIterationStatusVar();
+ if (iterationStatusVar != null) {
+ Map<String, Object> requestMap = getVariablesMap(faces);
+
+ if (rowSelected) {
+ Integer begin = null;
+ Integer end = null;
+
+ Range range = getComponentState().getRange();
+ if (range instanceof SequenceRange) {
+ SequenceRange sequenceRange = (SequenceRange) range;
+
+ begin = sequenceRange.getFirstRow();
+ int iRows = sequenceRange.getRows();
+
+ if (iRows > 0) {
+ // end is zero-based
+ end = begin + iRows - 1;
+ }
+ }
+
+ SequenceIterationStatus iterationStatus = new
SequenceIterationStatus(begin, end,
+ getRowIndex(), getRowCount());
+
+ requestMap.put(iterationStatusVar, iterationStatus);
+ } else {
+ requestMap.remove(iterationStatusVar);
+ }
+ }
+ }
+
}
Added:
root/framework/trunk/impl/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java
===================================================================
---
root/framework/trunk/impl/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java
(rev 0)
+++
root/framework/trunk/impl/src/test/java/org/richfaces/component/SequenceIterationStatusTest.java 2010-03-04
17:11:54 UTC (rev 16527)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SequenceIterationStatusTest {
+
+ @Test
+ public void testFirst() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 10, 0, 100);
+ assertTrue(s1.isFirst());
+ assertFalse(s1.isLast());
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 10, 1, 100);
+ assertFalse(s2.isFirst());
+ assertFalse(s2.isLast());
+
+ SequenceIterationStatus s3 = new SequenceIterationStatus(0, 0, 0, 100);
+ assertTrue(s3.isFirst());
+ assertTrue(s3.isLast());
+
+ SequenceIterationStatus s4 = new SequenceIterationStatus(5, 10, 5, 100);
+ assertTrue(s4.isFirst());
+ assertFalse(s4.isLast());
+
+ SequenceIterationStatus s5 = new SequenceIterationStatus(5, 10, 6, 100);
+ assertFalse(s5.isFirst());
+ assertFalse(s5.isLast());
+
+ SequenceIterationStatus s6 = new SequenceIterationStatus(null, 10, 0, 100);
+ assertTrue(s6.isFirst());
+ assertFalse(s6.isLast());
+ }
+
+ @Test
+ public void testLast() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 9, 9, 100);
+ assertTrue(s1.isLast());
+ assertFalse(s1.isFirst());
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 9, 8, 100);
+ assertFalse(s2.isLast());
+ assertFalse(s2.isFirst());
+
+ SequenceIterationStatus s3 = new SequenceIterationStatus(0, 100, 9, 10);
+ assertTrue(s3.isLast());
+ assertFalse(s3.isFirst());
+
+ SequenceIterationStatus s4 = new SequenceIterationStatus(0, 100, 8, 10);
+ assertFalse(s4.isLast());
+ assertFalse(s4.isFirst());
+
+ SequenceIterationStatus s5 = new SequenceIterationStatus(0, null, 9, 10);
+ assertTrue(s5.isLast());
+ assertFalse(s5.isFirst());
+
+ SequenceIterationStatus s6 = new SequenceIterationStatus(0, null, 8, 10);
+ assertFalse(s6.isLast());
+ assertFalse(s6.isFirst());
+ }
+
+ @Test
+ public void testIsEvenOdd() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 0, 10);
+ assertTrue(s1.isOdd());
+ assertFalse(s1.isEven());
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 100, 1, 10);
+ assertTrue(s2.isEven());
+ assertFalse(s2.isOdd());
+
+ SequenceIterationStatus s3 = new SequenceIterationStatus(5, 100, 7, 10);
+ assertTrue(s3.isOdd());
+ assertFalse(s3.isEven());
+
+ SequenceIterationStatus s4 = new SequenceIterationStatus(5, 100, 6, 10);
+ assertTrue(s4.isEven());
+ assertFalse(s4.isOdd());
+ }
+
+ @Test
+ public void testGetRowCount() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 0, 200);
+ assertEquals(Integer.valueOf(200), s1.getRowCount());
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 400, 100, 150);
+ assertEquals(Integer.valueOf(150), s2.getRowCount());
+ }
+
+ @Test
+ public void testGetIndex() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 30, 200);
+ assertTrue(30 == s1.getIndex());
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 400, 100, 150);
+ assertTrue(100 == s2.getIndex());
+ }
+
+ @Test
+ public void testGetCount() throws Exception {
+ SequenceIterationStatus s1 = new SequenceIterationStatus(0, 100, 0, 10);
+ assertTrue(s1.getCount() == 1);
+
+ SequenceIterationStatus s2 = new SequenceIterationStatus(0, 100, 1, 10);
+ assertTrue(s2.getCount() == 2);
+
+ SequenceIterationStatus s3 = new SequenceIterationStatus(5, 100, 7, 10);
+ assertTrue(s3.getCount() == 3);
+
+ SequenceIterationStatus s4 = new SequenceIterationStatus(5, 100, 8, 10);
+ assertTrue(s4.getCount() == 4);
+ }
+}
Modified: root/ui/trunk/components/core/pom.xml
===================================================================
--- root/ui/trunk/components/core/pom.xml 2010-03-04 13:58:58 UTC (rev 16526)
+++ root/ui/trunk/components/core/pom.xml 2010-03-04 17:11:54 UTC (rev 16527)
@@ -51,21 +51,31 @@
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-impl</artifactId>
</dependency>
- <dependency>
- <groupId>org.jboss.test-jsf</groupId>
- <artifactId>htmlunit-client</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.test-jsf</groupId>
- <artifactId>jsf-mock</artifactId>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>htmlunit-client</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-mock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-test-stage</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
Modified: root/ui/trunk/components/core/src/main/config/faces-config.xml
===================================================================
--- root/ui/trunk/components/core/src/main/config/faces-config.xml 2010-03-04 13:58:58 UTC
(rev 16526)
+++ root/ui/trunk/components/core/src/main/config/faces-config.xml 2010-03-04 17:11:54 UTC
(rev 16527)
@@ -102,5 +102,10 @@
<renderer-type>org.richfaces.QueueRenderer</renderer-type>
<renderer-class>org.richfaces.renderkit.html.QueueRenderer</renderer-class>
</renderer>
+ <renderer>
+ <component-family>javax.faces.Data</component-family>
+ <renderer-type>org.richfaces.RepeatRenderer</renderer-type>
+ <renderer-class>org.richfaces.renderkit.html.RepeatRenderer</renderer-class>
+ </renderer>
</render-kit>
</faces-config>
\ No newline at end of file
Added: root/ui/trunk/components/core/src/main/java/org/richfaces/component/UIRepeat.java
===================================================================
--- root/ui/trunk/components/core/src/main/java/org/richfaces/component/UIRepeat.java
(rev 0)
+++
root/ui/trunk/components/core/src/main/java/org/richfaces/component/UIRepeat.java 2010-03-04
17:11:54 UTC (rev 16527)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import org.richfaces.cdk.annotations.Component;
+import org.richfaces.cdk.annotations.Tag;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@Component(generate = false, tag = @Tag(name = "repeat"))
+public class UIRepeat extends UISequence {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.Repeat";
+
+ public static final String COMPONENT_FAMILY = "javax.faces.Data";
+
+ public UIRepeat() {
+ setRendererType("org.richfaces.RepeatRenderer");
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+}
Added:
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/RepeatRenderer.java
===================================================================
---
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/RepeatRenderer.java
(rev 0)
+++
root/ui/trunk/components/core/src/main/java/org/richfaces/renderkit/html/RepeatRenderer.java 2010-03-04
17:11:54 UTC (rev 16527)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.renderkit.html;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
+
+import org.ajax4jsf.model.DataVisitResult;
+import org.ajax4jsf.model.DataVisitor;
+import org.richfaces.component.UIRepeat;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+(a)org.richfaces.cdk.annotations.Renderer("org.richfaces.RepeatRenderer")
+public class RepeatRenderer extends Renderer {
+
+ @Override
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
+ final UIRepeat repeater = (UIRepeat) component;
+ try {
+ DataVisitor visitor = new DataVisitor() {
+
+ public DataVisitResult process(FacesContext context, Object rowKey,
Object argument) {
+ repeater.setRowKey(rowKey);
+
+ if (repeater.isRowAvailable()) {
+ if (repeater.getChildCount() > 0) {
+ for (UIComponent child : repeater.getChildren()) {
+ try {
+ child.encodeAll(context);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ return DataVisitResult.CONTINUE;
+ }
+ };
+
+ repeater.walk(context, visitor, null);
+ } finally {
+ repeater.setRowKey(null);
+ }
+ }
+
+}
Modified: root/ui/trunk/components/core/src/main/resources/META-INF/a4j.taglib.xml
===================================================================
--- root/ui/trunk/components/core/src/main/resources/META-INF/a4j.taglib.xml 2010-03-04
13:58:58 UTC (rev 16526)
+++ root/ui/trunk/components/core/src/main/resources/META-INF/a4j.taglib.xml 2010-03-04
17:11:54 UTC (rev 16527)
@@ -68,6 +68,13 @@
<renderer-type>org.richfaces.QueueRenderer</renderer-type>
</component>
</tag>
+ <tag>
+ <tag-name>repeat</tag-name>
+ <component>
+ <component-type>org.richfaces.Repeat</component-type>
+ <renderer-type>org.richfaces.RepeatRenderer</renderer-type>
+ </component>
+ </tag>
<tag>
<tag-name>ajax</tag-name>
Modified: root/ui/trunk/version-matrix/pom.xml
===================================================================
--- root/ui/trunk/version-matrix/pom.xml 2010-03-04 13:58:58 UTC (rev 16526)
+++ root/ui/trunk/version-matrix/pom.xml 2010-03-04 17:11:54 UTC (rev 16527)
@@ -112,6 +112,11 @@
<artifactId>jsf-mock</artifactId>
<version>1.0.0</version>
</dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-test-stage</artifactId>
+ <version>1.0.0</version>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -161,7 +166,28 @@
<version>2.0-alpha-4</version>
</dependency>
<!-- end -->
- </dependencies>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version >1.5.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version >1.5.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version >1.5.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ <version >1.5.8</version>
+ </dependency>
+ </dependencies>
</dependencyManagement>
<build>