[ http://jira.codehaus.org/browse/DISPL-120?page=comments#action_82965 ] 
            
S Vinod commented on DISPL-120:
-------------------------------

I have implemented a different solution for the same problem. One can pass 
java.util.HashMap which contains the multiple parameters needed .

The changes one has to do are 
a.   ColumnTag.java

1.  imports

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; 
import java.util.HashMap;
import java.util.Iterator;


2 .  public class ColumnTag extends BodyTagSupport implements 
MediaUtil.SupportsMedia


                    // evaluate expression.
                    // note the value is fixed, not based on any object created 
during iteration
                    // this is here for compatibility with the old version 
mainly
                    Object paramValue = 
tableTag.evaluateExpression(expression.toString());
                    String key;
                    if ( paramValue instanceof java.util.HashMap) 
                    {                            
                        Iterator itr = 
((HashMap)paramValue).keySet().iterator();
                                        while(itr.hasNext())
                                        {
                                                key=(String) itr.next();
                                                colHref.addParameter(key, 
((HashMap)paramValue).get(key));                                                
                      
                                        }                                       
         
                    }
                    else
                    {                    
                        colHref.addParameter(this.paramId, paramValue);
                    }



b :  Column.java

1 imports 

import java.util.HashMap;
import java.util.Iterator;

2.      private Href getColumnHref(String columnContent)

                        if (paramValue != null)
                                try {
                                        
                                        
                                            String key;
                            if ( paramValue instanceof java.util.HashMap) 
                            {                            
                                Iterator itr = 
((HashMap)paramValue).keySet().iterator();
                                                while(itr.hasNext())
                                                {
                                                        key=(String) itr.next();
                                                        
colHref.addParameter(key, URLEncoder
                                                                        
.encode((String)((HashMap)paramValue).get(key), 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);
                                }



Now in JSP you can pass any java.util.HapMap like one does using struts 
html:link tag !!!


ALL THE BEST !!!!!!!!!

contact me : [EMAIL PROTECTED] for any queries

Vinod










> Multiple Parameters in Column URL (patch included)
> --------------------------------------------------
>
>                 Key: DISPL-120
>                 URL: http://jira.codehaus.org/browse/DISPL-120
>             Project: DisplayTag
>          Issue Type: Improvement
>          Components: Tag Library
>    Affects Versions: 1.0
>            Reporter: Ravikumar Tadikonda
>            Priority: Minor
>             Fix For: TBD
>
>         Attachments: displaytag-2.0.jar
>
>
> 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.
>       */

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
displaytag-devel mailing list
displaytag-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-devel

Reply via email to