click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r959295 - in /click/trunk/click: extras/src/org/apache/click/extras/control/FormTable.java framework/src/org/apache/click/control/Table.java
Date Wed, 30 Jun 2010 13:07:08 GMT
Author: sabob
Date: Wed Jun 30 13:07:08 2010
New Revision: 959295

URL: http://svn.apache.org/viewvc?rev=959295&view=rev
Log:
removed dependency on getParameters, use Context instead

Modified:
    click/trunk/click/extras/src/org/apache/click/extras/control/FormTable.java
    click/trunk/click/framework/src/org/apache/click/control/Table.java

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/FormTable.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/FormTable.java?rev=959295&r1=959294&r2=959295&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/FormTable.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/FormTable.java Wed Jun 30
13:07:08 2010
@@ -19,6 +19,7 @@
 package org.apache.click.extras.control;
 
 import java.util.List;
+import org.apache.click.Context;
 
 import org.apache.click.control.Button;
 import org.apache.click.control.Column;
@@ -476,90 +477,97 @@ public class FormTable extends Table {
 
         boolean continueProcessing = super.onProcess();
 
-        if (!controlLink.isClicked() && getForm().isFormSubmission()) {
-            Field pageField = getForm().getField(PAGE);
-            pageField.onProcess();
-            if (StringUtils.isNotBlank(pageField.getValue())) {
-                setPageNumber(Integer.parseInt(pageField.getValue()));
-            }
+        if (controlLink.isClicked()) {
+            Context context = getContext();
+            getForm().getField(PAGE).setValue(context.getRequestParameter(PAGE));
 
-            Field columnField = getForm().getField(COLUMN);
-            columnField.onProcess();
-            setSortedColumn(columnField.getValue());
-
-            Field ascendingField = getForm().getField(ASCENDING);
-            ascendingField.onProcess();
-            setSortedAscending("true".equals(ascendingField.getValue()));
-
-            // Ensure data is retrieved before getRowCount can be called
-            getRowList();
-
-            // Range sanity check
-            int pageNumber = Math.min(getPageNumber(), getRowCount() - 1);
-            pageNumber = Math.max(pageNumber, 0);
-            setPageNumber(pageNumber);
-
-            //Have to sort list here before we process each field. Otherwise if
-            //sortRowList() is only called in Table.toString(), the fields values set here
-            //will not correspond to their rows in the rowList.
-            sortRowList();
-
-            int firstRow = 0;
-            int lastRow = 0;
-
-            if (getDataProvider() instanceof PagingDataProvider) {
-                lastRow = getRowList().size();
-            } else {
-                firstRow = getFirstRow();
-                lastRow = getLastRow();
-            }
+            getForm().getField(COLUMN).setValue(context.getRequestParameter(COLUMN));
+
+            String ascending = context.getRequestParameter(ASCENDING);
+            getForm().getField(ASCENDING).setValue(ascending);
 
-            List rowList = getRowList();
-            List columnList = getColumnList();
+            // Table.onProcess() flips the sort order, so to ensure the ASCENDING
+            // Field value is in sync with the Table, we flip the field value as
+            // well.
+            String sort = context.getRequestParameter(SORT);
+            if ("true".equals(sort) || ascending == null) {
+                getForm().getField(ASCENDING).setValue("true".equals(ascending) ? "false"
: "true");
+            }
 
-            for (int i = firstRow; i < lastRow; i++) {
-                Object row = rowList.get(i);
+        } else {
 
-                for (int j = 0; j < columnList.size(); j++) {
+            if (getForm().isFormSubmission()) {
+                Field pageField = getForm().getField(PAGE);
+                pageField.onProcess();
+                if (StringUtils.isNotBlank(pageField.getValue())) {
+                    setPageNumber(Integer.parseInt(pageField.getValue()));
+                }
 
-                    Column column = (Column) columnList.get(j);
+                Field columnField = getForm().getField(COLUMN);
+                columnField.onProcess();
+                setSortedColumn(columnField.getValue());
+
+                Field ascendingField = getForm().getField(ASCENDING);
+                ascendingField.onProcess();
+                setSortedAscending("true".equals(ascendingField.getValue()));
+
+                // Ensure data is retrieved before getRowCount can be called
+                getRowList();
+
+                // Range sanity check
+                int pageNumber = Math.min(getPageNumber(), getRowCount() - 1);
+                pageNumber = Math.max(pageNumber, 0);
+                setPageNumber(pageNumber);
+
+                //Have to sort list here before we process each field. Otherwise if
+                //sortRowList() is only called in Table.toString(), the fields values set
here
+                //will not correspond to their rows in the rowList.
+                sortRowList();
+
+                int firstRow = 0;
+                int lastRow = 0;
+
+                if (getDataProvider() instanceof PagingDataProvider) {
+                    lastRow = getRowList().size();
+                } else {
+                    firstRow = getFirstRow();
+                    lastRow = getLastRow();
+                }
 
-                    if (column instanceof FieldColumn) {
-                        FieldColumn fieldColumn = (FieldColumn) column;
-                        Field field = fieldColumn.getField();
+                List rowList = getRowList();
+                List columnList = getColumnList();
 
-                        if (field != null) {
-                            field.setName(column.getName() + "_" + i);
+                for (int i = firstRow; i < lastRow; i++) {
+                    Object row = rowList.get(i);
 
-                            field.onProcess();
+                    for (int j = 0; j < columnList.size(); j++) {
 
-                            if (field.isValid()) {
-                                fieldColumn.setProperty(row, column.getName(),
-                                    field.getValueObject());
-                            } else {
-                                getForm().setError(getMessage("formtable-error"));
+                        Column column = (Column) columnList.get(j);
+
+                        if (column instanceof FieldColumn) {
+                            FieldColumn fieldColumn = (FieldColumn) column;
+                            Field field = fieldColumn.getField();
+
+                            if (field != null) {
+                                HtmlStringBuffer buffer = new HtmlStringBuffer();
+                                buffer.append(column.getName());
+                                buffer.append("_");
+                                buffer.append(i);
+                                field.setName(buffer.toString());
+
+                                field.onProcess();
+
+                                if (field.isValid()) {
+                                    fieldColumn.setProperty(row, column.getName(),
+                                        field.getValueObject());
+                                } else {
+                                    getForm().setError(getMessage("formtable-error"));
+                                }
                             }
                         }
                     }
                 }
             }
-        } else {
-            String page = controlLink.getParameter(PAGE);
-            getForm().getField(PAGE).setValue(page);
-
-            String column = controlLink.getParameter(COLUMN);
-            getForm().getField(COLUMN).setValue(column);
-
-            String ascending =  controlLink.getParameter(ASCENDING);
-            getForm().getField(ASCENDING).setValue(ascending);
-
-            // Table.onProcess() flips the sort order, so to ensure the ASCENDING
-            // Field value is in sync with the Table, we flip the field value as
-            // well.
-            String sort = controlLink.getParameter(SORT);
-            if ("true".equals(sort) || ascending == null) {
-                getForm().getField(ASCENDING).setValue("true".equals(ascending) ? "false"
: "true");
-            }
         }
 
         return continueProcessing;

Modified: click/trunk/click/framework/src/org/apache/click/control/Table.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Table.java?rev=959295&r1=959294&r2=959295&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Table.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Table.java Wed Jun 30 13:07:08
2010
@@ -388,7 +388,7 @@ public class Table extends AbstractContr
 
     /** The table HTML &lt;caption&gt; element */
     protected String caption;
-    
+
     /** The map of table columns keyed by column name. */
     protected Map<String, Column> columns = new HashMap<String, Column>();
 
@@ -1391,33 +1391,30 @@ public class Table extends AbstractContr
     @Override
     public boolean onProcess() {
         ActionLink controlLink = getControlLink();
-        controlLink.defineParameter(PAGE);
-        controlLink.defineParameter(COLUMN);
-        controlLink.defineParameter(ASCENDING);
-        controlLink.defineParameter(SORT);
 
         controlLink.onProcess();
 
         if (controlLink.isClicked()) {
-            String page = controlLink.getParameter(PAGE);
+            Context context = getContext();
+            String page = context.getRequestParameter(PAGE);
             if (NumberUtils.isNumber(page)) {
                 setPageNumber(Integer.parseInt(page));
             } else {
                 setPageNumber(0);
             }
 
-            String column = controlLink.getParameter(COLUMN);
+            String column = context.getRequestParameter(COLUMN);
             if (column != null) {
                 setSortedColumn(column);
             }
 
-            String ascending =  controlLink.getParameter(ASCENDING);
+            String ascending = context.getRequestParameter(ASCENDING);
             if (ascending != null) {
                 setSortedAscending("true".equals(ascending));
             }
 
             // Flip sorting order
-            if ("true".equals(controlLink.getParameter(SORT))) {
+            if ("true".equals(context.getRequestParameter(SORT))) {
                 setSortedAscending(!isSortedAscending());
             }
         }
@@ -1525,8 +1522,8 @@ public class Table extends AbstractContr
 
         buffer.closeTag();
         buffer.append("\n");
-        
-        String caption = getCaption(); 
+
+        String caption = getCaption();
         if (caption != null) {
             buffer.elementStart("caption");
             buffer.closeTag();



Mime
View raw message