Author: nbelaevski
Date: 2010-05-10 13:04:06 -0400 (Mon, 10 May 2010)
New Revision: 16960
Modified:
root/examples/core-demo/trunk/src/main/java/org/richfaces/demo/RepeatBean.java
root/examples/core-demo/trunk/src/main/webapp/repeat.xhtml
Log:
https://jira.jboss.org/jira/browse/RF-8487
Modified: root/examples/core-demo/trunk/src/main/java/org/richfaces/demo/RepeatBean.java
===================================================================
---
root/examples/core-demo/trunk/src/main/java/org/richfaces/demo/RepeatBean.java 2010-05-10
16:36:05 UTC (rev 16959)
+++
root/examples/core-demo/trunk/src/main/java/org/richfaces/demo/RepeatBean.java 2010-05-10
17:04:06 UTC (rev 16960)
@@ -36,6 +36,44 @@
@SessionScoped
public class RepeatBean {
+ public static final class MatrixCell {
+
+ private int value = 0;
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+
+ public void clearValueAction() {
+ setValue(0);
+ }
+
+ public void increaseValueAction() {
+ value++;
+ }
+
+ public void decreaseValueAction() {
+ value--;
+ }
+ }
+
+ public static final class MatrixRow {
+
+ private List<MatrixCell> cells = new ArrayList<MatrixCell>();
+
+ public List<MatrixCell> getCells() {
+ return cells;
+ }
+
+ public void addCell(MatrixCell cell) {
+ cells.add(cell);
+ }
+ }
+
public static final class Data {
private String text;
@@ -56,10 +94,14 @@
}
+ private static final int MATRIX_DIMENSION = 4;
+
private List<Data> dataList;
private Data selectedDataItem = null;
+ private List<MatrixRow> matrixRows;
+
public RepeatBean() {
dataList = new ArrayList<Data>();
@@ -68,6 +110,19 @@
data.setText(MessageFormat.format("Item {0}", i));
dataList.add(data);
}
+
+ matrixRows = new ArrayList<MatrixRow>();
+
+ for (int i = 0; i < MATRIX_DIMENSION; i++) {
+ MatrixRow matrixRow = new MatrixRow();
+
+ for (int j = 0; j < MATRIX_DIMENSION; j++) {
+ MatrixCell matrixCell = new MatrixCell();
+ matrixRow.addCell(matrixCell);
+ }
+
+ matrixRows.add(matrixRow);
+ }
}
/**
@@ -90,4 +145,8 @@
public void setSelectedDataItem(Data selectedDataItem) {
this.selectedDataItem = selectedDataItem;
}
+
+ public List<MatrixRow> getMatrixRows() {
+ return matrixRows;
+ }
}
Modified: root/examples/core-demo/trunk/src/main/webapp/repeat.xhtml
===================================================================
--- root/examples/core-demo/trunk/src/main/webapp/repeat.xhtml 2010-05-10 16:36:05 UTC
(rev 16959)
+++ root/examples/core-demo/trunk/src/main/webapp/repeat.xhtml 2010-05-10 17:04:06 UTC
(rev 16960)
@@ -7,26 +7,88 @@
xmlns:a4j="http://richfaces.org/a4j">
<f:view>
<h:head>
+ <style type="text/css">
+ .cell {
+ width: 120px;
+ padding: 10px;
+ }
+
+ .cell-even.row-even,.cell-odd.row-odd {
+ background-color: #CFC;
+ }
+ </style>
</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 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:form id="matrixForm">
+ <h:panelGroup id="matrixInput" layout="block">
+ <h:messages />
+ <table>
+ <tbody>
+ <a4j:repeat value="#{repeatBean.matrixRows}" var="row"
+ iterationStatusVar="rowStatus">
+ <tr>
+ <a4j:repeat value="#{row.cells}" var="cell"
+ iterationStatusVar="cellStatus">
+ <td><h:panelGroup layout="block"
+ styleClass="cell #{rowStatus.even ? 'row-even' :
'row-odd'} #{cellStatus.even ? 'cell-even' :
'cell-odd'}">
+ <h:inputText value="#{cell.value}" size="3">
+ <f:convertNumber />
+ <f:ajax render=":matrixForm:matrixInput :matrixOutput" />
+ </h:inputText>
+
+ <h:commandLink action="#{cell.clearValueAction}"
value="C">
+ <f:ajax render=":matrixForm:matrixInput :matrixOutput" />
+ </h:commandLink>
+ <h:outputText value=" / " />
+ <h:commandLink action="#{cell.increaseValueAction}"
value="+">
+ <f:ajax render=":matrixForm:matrixInput :matrixOutput" />
+ </h:commandLink>
+ <h:outputText value=" / " />
+ <h:commandLink action="#{cell.decreaseValueAction}"
value="-">
+ <f:ajax render=":matrixForm:matrixInput :matrixOutput" />
+ </h:commandLink>
+ </h:panelGroup></td>
+ </a4j:repeat>
+ </tr>
+ </a4j:repeat>
+ </tbody>
+ </table>
+ </h:panelGroup>
+
+ </h:form>
+ <h:panelGroup id="matrixOutput" layout="block">
+ <table>
+ <tbody>
+ <a4j:repeat value="#{repeatBean.matrixRows}" var="row">
+ <tr>
+ <a4j:repeat value="#{row.cells}" var="cell">
+ <td><h:panelGroup styleClass="cell"
layout="block">
+ #{cell.value}
+ </h:panelGroup></td>
+ </a4j:repeat>
+ </tr>
+ </a4j:repeat>
+ </tbody>
+ </table>
+ </h:panelGroup>
</h:body>
</f:view>
</html>
\ No newline at end of file