[seam-commits] Seam SVN: r7377 - in trunk: seam-gen/view and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Feb 6 00:20:46 EST 2008


Author: norman.richards at jboss.com
Date: 2008-02-06 00:20:45 -0500 (Wed, 06 Feb 2008)
New Revision: 7377

Modified:
   trunk/seam-gen/icefaces/view/list.page.xml.ftl
   trunk/seam-gen/icefaces/view/list.xhtml.ftl
   trunk/seam-gen/view/list.page.xml.ftl
   trunk/seam-gen/view/list.xhtml.ftl
   trunk/src/main/org/jboss/seam/framework/Query.java
Log:
JBSEAM-2492

Modified: trunk/seam-gen/icefaces/view/list.page.xml.ftl
===================================================================
--- trunk/seam-gen/icefaces/view/list.page.xml.ftl	2008-02-05 23:18:14 UTC (rev 7376)
+++ trunk/seam-gen/icefaces/view/list.page.xml.ftl	2008-02-06 05:20:45 UTC (rev 7377)
@@ -14,7 +14,8 @@
 <#assign listName = componentName + "List">
 
    <param name="firstResult" value="${'#'}{${listName}.firstResult}"/>
-   <param name="order" value="${'#'}{${listName}.order}"/>
+   <param name="sort" value="${'#'}{${listName}.orderColumn}"/>
+   <param name="dir" value="${'#'}{${listName}.orderDirection}"/>
    <param name="from"/>
 <#foreach property in pojo.allPropertiesIterator>
 <#if !c2h.isCollection(property) && !c2h.isManyToOne(property) && property != pojo.versionProperty!>

Modified: trunk/seam-gen/icefaces/view/list.xhtml.ftl
===================================================================
--- trunk/seam-gen/icefaces/view/list.xhtml.ftl	2008-02-05 23:18:14 UTC (rev 7376)
+++ trunk/seam-gen/icefaces/view/list.xhtml.ftl	2008-02-06 05:20:45 UTC (rev 7377)
@@ -97,8 +97,9 @@
             <f:facet name="header">
                 <s:link styleClass="columnHeader"
 		             id="list${property.name}LinkId"
-                             value="${property.name} ${'#'}{${listName}.order=='${property.name} asc' ? messages.down : ( ${listName}.order=='${property.name} desc' ? messages.up : '' )}">
-                    <f:param name="order" value="${'#'}{${listName}.order=='${property.name} asc' ? '${property.name} desc' : '${property.name} asc'}"/>
+		             value="${property.name} ${'#'}{${listName}.orderColumn=='${property.name}' ? (${listName}.orderDirection=='desc' ? messages.down : messages.up)  : ''}">                   
+                    <f:param name="sort" value="${property.name}" />
+                    <f:param name="dir" value="${'#'}{${listName}.orderDirection=='asc' ? 'desc' : 'asc'}"/>
                 </s:link>
             </f:facet>
             ${'#'}{${componentName}.${property.name}}&amp;nbsp;

Modified: trunk/seam-gen/view/list.page.xml.ftl
===================================================================
--- trunk/seam-gen/view/list.page.xml.ftl	2008-02-05 23:18:14 UTC (rev 7376)
+++ trunk/seam-gen/view/list.page.xml.ftl	2008-02-06 05:20:45 UTC (rev 7377)
@@ -8,7 +8,9 @@
 <#assign componentName = util.lower(entityName)>
 <#assign listName = componentName + "List">
    <param name="firstResult" value="${'#'}{${listName}.firstResult}"/>
-   <param name="order" value="${'#'}{${listName}.order}"/>
+   <param name="sort" value="${'#'}{${listName}.orderColumn}"/>
+   <param name="dir" value="${'#'}{${listName}.orderDirection}"/>
+   
    <param name="from"/>
 <#foreach property in pojo.allPropertiesIterator>
 <#if !c2h.isCollection(property) && !c2h.isManyToOne(property) && property != pojo.versionProperty!>

Modified: trunk/seam-gen/view/list.xhtml.ftl
===================================================================
--- trunk/seam-gen/view/list.xhtml.ftl	2008-02-05 23:18:14 UTC (rev 7376)
+++ trunk/seam-gen/view/list.xhtml.ftl	2008-02-06 05:20:45 UTC (rev 7377)
@@ -81,8 +81,9 @@
         <h:column>
             <f:facet name="header">
                 <s:link styleClass="columnHeader"
-                             value="${property.name} ${'#'}{${listName}.order=='${property.name} asc' ? messages.down : ( ${listName}.order=='${property.name} desc' ? messages.up : '' )}">
-                    <f:param name="order" value="${'#'}{${listName}.order=='${property.name} asc' ? '${property.name} desc' : '${property.name} asc'}"/>
+                             value="${property.name} ${'#'}{${listName}.orderColumn=='${property.name}' ? (${listName}.orderDirection=='desc' ? messages.down : messages.up)  : ''}">                   
+                    <f:param name="sort" value="${property.name}" />
+                    <f:param name="dir" value="${'#'}{${listName}.orderDirection=='asc' ? 'desc' : 'asc'}"/>
                 </s:link>
             </f:facet>
             ${'#'}{${componentName}.${property.name}}

Modified: trunk/src/main/org/jboss/seam/framework/Query.java
===================================================================
--- trunk/src/main/org/jboss/seam/framework/Query.java	2008-02-05 23:18:14 UTC (rev 7376)
+++ trunk/src/main/org/jboss/seam/framework/Query.java	2008-02-06 05:20:45 UTC (rev 7377)
@@ -30,14 +30,18 @@
    private static final Pattern ORDER_PATTERN = Pattern.compile("\\s(order)(\\s)+by\\s", Pattern.CASE_INSENSITIVE);
    private static final Pattern WHERE_PATTERN = Pattern.compile("\\s(where)\\s", Pattern.CASE_INSENSITIVE);
 
-   private static final Pattern ORDER_CLAUSE_PATTERN = Pattern.compile("^[\\w\\.,\\s]*$");
+   private static final Pattern ORDER_COLUMN_PATTERN = Pattern.compile("^\\w*$");
 
-   
+   private static final String DIR_ASC = "asc";
+   private static final String DIR_DESC = "desc";
+
    private String ejbql;
    private Integer firstResult;
    private Integer maxResults;
    private List<String> restrictions = new ArrayList<String>(0);
    private String order;
+   private String orderColumn;
+   private String orderDirection;
    
    private DataModel dataModel;
    
@@ -359,22 +363,69 @@
    }
 
    /**
-    * The order of the query
+    * The order clause of the query
     */
-   public String getOrder()
-   {
-      return order;
+   
+   public String getOrder() {
+       String column    = getOrderColumn();
+
+       if (column == null) {
+           return order;
+       }
+       
+       String direction = getOrderDirection();
+       
+       if (direction == null) {
+           return column;
+       } else {
+           return column + ' ' + direction;
+       }   
    }
 
    public void setOrder(String order)
    {      
-       if (order!= null && !ORDER_CLAUSE_PATTERN.matcher(order).find()) {
-           throw new IllegalArgumentException("invalid order clause");
-       }
        this.order = order;
        refresh();
    }
    
+   public String getOrderDirection() {
+       return orderDirection;
+   }
+
+   public void setOrderDirection(String orderDirection) {
+       this.orderDirection = sanitizeOrderDirection(orderDirection);
+   }
+   
+   private String sanitizeOrderDirection(String direction) {
+       if (direction == null || direction.length()==0) {
+           return null;
+       } else if (direction.equalsIgnoreCase(DIR_ASC)) {
+           return DIR_ASC;
+       } else if (direction.equalsIgnoreCase(DIR_DESC)) {
+           return DIR_DESC;
+       } else {
+           throw new IllegalArgumentException("invalid order direction");
+       }
+   }
+
+   public String getOrderColumn() {
+       return orderColumn;
+   }
+
+   public void setOrderColumn(String orderColumn) {
+       this.orderColumn = sanitizeOrderColumn(orderColumn);
+   }
+
+   private String sanitizeOrderColumn(String columnName) {
+       if (columnName == null || columnName.trim().length() == 0) {
+           return null;
+       } else if (ORDER_COLUMN_PATTERN.matcher(columnName).find()) {
+           return columnName;
+       } else {
+           throw new IllegalArgumentException("invalid order column");
+       }
+   }
+   
    protected List<ValueExpression> getQueryParameters()
    {
       return queryParameters;




More information about the seam-commits mailing list