DisplayTag
  1. DisplayTag
  2. DISPL-120

Multiple Parameters in Column URL (patch included)

    Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.0
    • Fix Version/s: TBD
    • Component/s: Tag Library
    • Labels:
      None

      Description

      Multiple Parameters in Column URL

         I have added functionality in displaytag to have more than one parameter in column href.
      this functionality also support to add displaytag id , row number in href.


      example :


       <display:table name="sessionScope.productDetails" id="detailGrid" defaultsort="1" requestURI="" pagesize="25">
         <display:column property="productcode" href="" paramId="grid,rowNumber,productcode,status" paramProperty=":id,:rowNum,productcode,status"/>
         <display:column property="description" />
         <display:column property="status" title="Actions" />
       </display:table>
       

      this will result in creating link like

      http://formurl?grid=detailGrid&rowNumber=listRownumber&productcode=productcode&status=status


      paramId : The list of the parameters separated by ','
      paramProperty : The list of property in the same order as paramId seperated by ','.


            If the paramId has more than one parameter, the paramProperty list must have the same number of property
            If the paramId has only one parameter and paramProperty is null then the current column value will be added to the href.
              This is an existing functionalty and will ensule that this enhancement will not break the existing code.
            
            I defined two predefined paramProperty :id, :rowNum
            :id parameter will give the id value of the table tag .
            :rowNum will give the current row Number
            
       
       I need this functionality in my current application that I am using displaytag . When I search on the mailing list for help the answer I got is use Decorator or Scriptlet.
       
       I need this kind of functionality in my project, which has lot of grids and I will end up with writing TableDecorator for each grid or writing Scriptlet in each grid.
       
       I thought that this is very trivial functionality and lots of users like me are looking for this kind of functionality built into this tag.
       
       I want this functionality to be implemented in displaytag . I am attaching the diff . Pls have a look at this.
       
      PS: This enhancement will satisfy the following mailing list discussions.
       
       http://sourceforge.net/mailarchive/forum.php?thread_id=5967258&forum_id=28703
       http://sourceforge.net/mailarchive/forum.php?thread_id=5935358&forum_id=28703
       https://sourceforge.net/forum/forum.php?thread_id=975630&forum_id=249317
       https://sourceforge.net/forum/forum.php?thread_id=1094161&forum_id=249317
        
       
       Thanks
       -Ravi.
      CVS patch :


      Index: src/java/org/displaytag/model/Column.java
      ===================================================================
      RCS file: /cvsroot/displaytag/displaytag/src/java/org/displaytag/model/Column.java,v
      retrieving revision 1.17
      diff -u -r1.17 Column.java
      --- src/java/org/displaytag/model/Column.java 16 Nov 2004 19:27:31 -0000 1.17
      +++ src/java/org/displaytag/model/Column.java 19 Nov 2004 03:58:52 -0000
      @@ -12,11 +12,13 @@
       package org.displaytag.model;
       
       import org.apache.commons.lang.ObjectUtils;
      +import org.apache.commons.lang.StringUtils;
       import org.apache.commons.lang.builder.ToStringBuilder;
       import org.displaytag.decorator.AutolinkColumnDecorator;
       import org.displaytag.decorator.TableDecorator;
       import org.displaytag.exception.DecoratorException;
       import org.displaytag.exception.ObjectLookupException;
      +import org.displaytag.exception.InvalidTagAttributeValueException;
       import org.displaytag.util.Anchor;
       import org.displaytag.util.CompatibleUrlEncoder;
       import org.displaytag.util.Href;
      @@ -133,7 +135,7 @@
            * @throws ObjectLookupException for errors in bean property lookup
            * @throws DecoratorException if a column decorator is used and an exception is thrown during value decoration
            */
      - public String getOpenTag() throws ObjectLookupException, DecoratorException
      + public String getOpenTag() throws DecoratorException, ObjectLookupException, InvalidTagAttributeValueException
           {
               this.stringValue = createChoppedAndLinkedValue();
       
      @@ -156,7 +158,7 @@
            * @throws ObjectLookupException for errors in bean property lookup
            * @throws DecoratorException if a column decorator is used and an exception is thrown during value decoration
            */
      - public String createChoppedAndLinkedValue() throws ObjectLookupException, DecoratorException
      + public String createChoppedAndLinkedValue() throws DecoratorException, ObjectLookupException, InvalidTagAttributeValueException
           {
       
               String fullValue = ObjectUtils.toString(getValue(true));
      @@ -208,36 +210,61 @@
            * @return generated Href
            * @throws ObjectLookupException for errors in lookin up object properties
            */
      - private Href getColumnHref(String columnContent) throws ObjectLookupException
      + private Href getColumnHref(String columnContent) throws ObjectLookupException ,InvalidTagAttributeValueException
           {
               // copy href
               Href colHref = new Href(this.header.getHref());
       
               // do we need to add a param?
      - if (this.header.getParamName() != null)
      - {
      -
      - Object paramValue;
      -
      - if (this.header.getParamProperty() != null)
      - {
      - // different property, go get it
      - paramValue = LookupUtil.getBeanProperty(this.row.getObject(), this.header.getParamProperty());
      -
      - }
      - else
      - {
      - // same property as content
      - paramValue = columnContent;
      - }
      -
      - if (paramValue != null)
      - {
      - colHref.addParameter(this.header.getParamName(), CompatibleUrlEncoder.encode(
      - paramValue.toString(),
      - this.row.getParentTable().getEncoding()));
      - }
      - }
      + String param = this.header.getParamName();
      + if (param != null)
      + {
      +
      + String[] paramArray = StringUtils.split(param,',');
      +
      + String property = this.header.getParamProperty();
      +
      + if ((property == null ) && paramArray.length == 1)
      + {
      + colHref.addParameter(param, CompatibleUrlEncoder.encode(
      + columnContent.toString(),
      + this.row.getParentTable().getEncoding()));
      +
      + }else
      + {
      +
      + String[] propertyArray = StringUtils.split(property,',');
      +
      + if(paramArray.length != propertyArray.length )
      + throw new InvalidTagAttributeValueException(getClass(), param, property); //$NON-NLS-1$
      +
      +
      + for(int i= 0 ; i < paramArray.length ; i++ )
      + {
      + String propertyString = propertyArray[i];
      + Object paramValue = null;
      +
      + if(propertyString.startsWith(":"))
      + {
      + if(TagConstants.TABLE_TAG_ID.equals(propertyString))
      + paramValue = this.row.getParentTable().getId();
      + else if (TagConstants.TABLE_ROW_NUM.equals(propertyString))
      + paramValue = String.valueOf(this.row.getRowNumber());
      + } else
      + {
      + paramValue = LookupUtil.getBeanProperty(this.row.getObject(), propertyString);
      + }
      +
      + if (paramValue != null)
      + {
      + colHref.addParameter(paramArray[i], CompatibleUrlEncoder.encode(
      + paramValue.toString(),
      + this.row.getParentTable().getEncoding()));
      + }
      + }
      + }
      +
      + }
               return colHref;
           }
       
      Index: src/java/org/displaytag/model/TableModel.java
      ===================================================================
      RCS file: /cvsroot/displaytag/displaytag/src/java/org/displaytag/model/TableModel.java,v
      retrieving revision 1.17
      diff -u -r1.17 TableModel.java
      --- src/java/org/displaytag/model/TableModel.java 16 Nov 2004 23:07:26 -0000 1.17
      +++ src/java/org/displaytag/model/TableModel.java 19 Nov 2004 03:58:52 -0000
      @@ -121,7 +121,15 @@
           {
               this.id = tableId;
           }
      -
      +
      + /**
      + * Getter for the tablemodel id.
      + * @return the tableId id of table tag
      + */
      + public String getId()
      + {
      + return this.id;
      + }
           /**
            * get the full list.
            * @return the full list containing Row objects
      Index: src/java/org/displaytag/tags/TableTag.java
      ===================================================================
      RCS file: /cvsroot/displaytag/displaytag/src/java/org/displaytag/tags/TableTag.java,v
      retrieving revision 1.92
      diff -u -r1.92 TableTag.java
      --- src/java/org/displaytag/tags/TableTag.java 18 Nov 2004 19:42:28 -0000 1.92
      +++ src/java/org/displaytag/tags/TableTag.java 19 Nov 2004 03:58:54 -0000
      @@ -1601,7 +1601,7 @@
            * @throws ObjectLookupException for errors in looking up properties in objects
            * @throws DecoratorException for errors returned by decorators
            */
      - private String getTableBody() throws ObjectLookupException, DecoratorException
      + private String getTableBody() throws DecoratorException, ObjectLookupException, InvalidTagAttributeValueException
           {
               StringBuffer buffer = new StringBuffer();
       
      Index: src/java/org/displaytag/util/TagConstants.java
      ===================================================================
      RCS file: /cvsroot/displaytag/displaytag/src/java/org/displaytag/util/TagConstants.java,v
      retrieving revision 1.14
      diff -u -r1.14 TagConstants.java
      --- src/java/org/displaytag/util/TagConstants.java 13 Nov 2004 15:10:40 -0000 1.14
      +++ src/java/org/displaytag/util/TagConstants.java 19 Nov 2004 03:58:55 -0000
      @@ -255,6 +255,16 @@
            */
           public static final String EMPTY_STRING = ""; //$NON-NLS-1$
       
      + /**
      + * DisplayTag <code>id</code> properiry.
      + */
      + public static final String TABLE_TAG_ID = ":id"; //$NON-NLS-1$
      +
      + /**
      + * DisplayTag <code>rowNum</code> properiry.
      + */
      + public static final String TABLE_ROW_NUM = ":rowNum"; //$NON-NLS-1$
      +
           /**
            * utility class - don't instantiate.
            */

        Activity

        Hide
        kk us added a comment -
        Modifying Column.java to have multiple parameters as below,

         private Href getColumnHref(String columnContent) throws ObjectLookupException
            {
                // copy href
                Href colHref = (Href) this.header.getHref().clone();

                // do we need to add a param?
                if (this.header.getParamName() != null)
                {

                    Object paramValue;

                    if (this.header.getParamProperty() != null)
                    {
                     String[] propArray=this.header.getParamProperty().split(",");
                     if (propArray.length > 1) {
        Map paramMap = new HashMap();
        for (int i=0;i<propArray.length;i++){
        paramMap.put(propArray[i],LookupUtil.getBeanProperty(this.row.getObject(), propArray[i]));
        }

        paramValue = paramMap;
                     } else {
                     paramValue = LookupUtil.getBeanProperty(this.row.getObject(), propArray[0]);
                     }
                    }
                    else
                    {
                        // same property as content
                        paramValue = columnContent;
                    }

                    if (paramValue != null)
        try {
        if (paramValue instanceof Map) {
        Iterator itr = ((HashMap)paramValue).keySet().iterator();
        while(itr.hasNext()) {
        String key=(String) itr.next();
        colHref.addParameter(key, URLEncoder.encode(((HashMap)paramValue).get(key).toString(), StringUtils.defaultString(row.getParentTable().getEncoding(), "UTF8")));
        }
        } else {
        colHref.addParameter(header.getParamName(), URLEncoder.encode(paramValue.toString(), StringUtils.defaultString(row.getParentTable().getEncoding(), "UTF8")));
        }

        } catch (UnsupportedEncodingException e) {
        throw new UnhandledException(e);
        }
                }
                return colHref;
            }
        Show
        kk us added a comment - Modifying Column.java to have multiple parameters as below,  private Href getColumnHref(String columnContent) throws ObjectLookupException     {         // copy href         Href colHref = (Href) this.header.getHref().clone();         // do we need to add a param?         if (this.header.getParamName() != null)         {             Object paramValue;             if (this.header.getParamProperty() != null)             {              String[] propArray=this.header.getParamProperty().split(",");              if (propArray.length > 1) { Map paramMap = new HashMap(); for (int i=0;i<propArray.length;i++){ paramMap.put(propArray[i],LookupUtil.getBeanProperty(this.row.getObject(), propArray[i])); } paramValue = paramMap;              } else {              paramValue = LookupUtil.getBeanProperty(this.row.getObject(), propArray[0]);              }             }             else             {                 // same property as content                 paramValue = columnContent;             }             if (paramValue != null) try { if (paramValue instanceof Map) { Iterator itr = ((HashMap)paramValue).keySet().iterator(); while(itr.hasNext()) { String key=(String) itr.next(); colHref.addParameter(key, URLEncoder.encode(((HashMap)paramValue).get(key).toString(), StringUtils.defaultString(row.getParentTable().getEncoding(), "UTF8"))); } } else { colHref.addParameter(header.getParamName(), URLEncoder.encode(paramValue.toString(), StringUtils.defaultString(row.getParentTable().getEncoding(), "UTF8"))); } } catch (UnsupportedEncodingException e) { throw new UnhandledException(e); }         }         return colHref;     }
        Hide
        vali added a comment -
        good job, thanks for it man, exactly the thing i was looking for..:)
        Show
        vali added a comment - good job, thanks for it man, exactly the thing i was looking for..:)
        Hide
        beeler4 added a comment -
        Thanks kk us!.
        I made an additional change to use paramId so that the parameter names can be different than paramProperty names

        paramId="grid,rowNumber,productcode,status" paramProperty="id,rowNum,productcode,status"
        ...
        if (this.header.getParamProperty() != null){
                     String[] propIds=this.header.getParamName().split(",");
                     String[] propArray=this.header.getParamProperty().split(",");
                     if (propArray.length > 1) {
                        Map paramMap = new HashMap();
                        for (int i=0;i<propArray.length;i++){
                            paramMap.put(propIds[i],LookupUtil.getBeanProperty(this.row.getObject(), propArray[i]));
                         }
                    }
        ...
        Show
        beeler4 added a comment - Thanks kk us!. I made an additional change to use paramId so that the parameter names can be different than paramProperty names paramId="grid,rowNumber,productcode,status" paramProperty="id,rowNum,productcode,status" ... if (this.header.getParamProperty() != null){              String[] propIds=this.header.getParamName().split(",");              String[] propArray=this.header.getParamProperty().split(",");              if (propArray.length > 1) {                 Map paramMap = new HashMap();                 for (int i=0;i<propArray.length;i++){                     paramMap.put(propIds[i],LookupUtil.getBeanProperty(this.row.getObject(), propArray[i]));                  }             } ...
        Hide
        Tom Tibbetts added a comment -
        I know you have the CVS output of the code change. Could you include the actual modified file(s) as a download?
        There needs to be added a trim() call for the parsing of the params for those of us how like to include white space in our param lists. Also, has this patch been submitted to the display tag developer?
        Show
        Tom Tibbetts added a comment - I know you have the CVS output of the code change. Could you include the actual modified file(s) as a download? There needs to be added a trim() call for the parsing of the params for those of us how like to include white space in our param lists. Also, has this patch been submitted to the display tag developer?
        Hide
        fabrizio giustina added a comment -
        renamed to make clear this is not a supported build
        Show
        fabrizio giustina added a comment - renamed to make clear this is not a supported build

          People

          • Reporter:
            Ravikumar Tadikonda
          • Votes:
            5 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

            • Created:
              Updated: