IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Struts 1 Java Discussion :

[Struts-layout 1.3] Tri Date n'importe comment sur layout:collection


Sujet :

Struts 1 Java

  1. #21
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Essaye celle-là (mais je ne peux pas la tester)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
     
    package fr.improve.struts.taglib.layout.collection;
     
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
     
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.jsp.JspException;
     
    import org.apache.struts.taglib.html.Constants;
    import org.apache.struts.util.RequestUtils;
     
    import fr.improve.struts.taglib.layout.collection.header.MultiLevelHeader;
    import fr.improve.struts.taglib.layout.el.Expression;
    import fr.improve.struts.taglib.layout.event.StaticCodeIncludeLayoutEvent;
    import fr.improve.struts.taglib.layout.event.StaticCodeIncludeListener;
    import fr.improve.struts.taglib.layout.sort.SortUtil;
    import fr.improve.struts.taglib.layout.util.IFooterRenderer;
    import fr.improve.struts.taglib.layout.util.IMathCollectionRenderer;
    import fr.improve.struts.taglib.layout.util.IMultiLevelHeaderRenderer;
    import fr.improve.struts.taglib.layout.util.LayoutUtils;
     
     
     
    /**
     * This class is responsible for displaying the collection.<br />
     * Actually, the rendering is done by another class implementing the CollectionInterface.
     * This class just computes differents parameters (headers and items).
     * @author: Jean-Noel Ribette
     **/
    public class CollectionTag extends BaseCollectionTag implements StaticCodeIncludeListener {
        /**
         * Math class
         */
        static Class mathClass;
     
        static {
            try {
                mathClass = RequestUtils.applicationClass("org.apache.commons.math.stat.StatUtils");
            } catch (ClassNotFoundException e) {
                // Math class is not available.
            }
        }
     
        /**
         * String of the static code to generate.
         */
        private String staticCode = "";
     
        /**
         * Map of the numbers for operation 
         */
        protected Map numbers = new HashMap();
     
        /* (non-Javadoc)
         * @see fr.improve.struts.taglib.layout.BodyLayoutTagSupport#reset()
         */
        protected void reset() {
            numbers.clear();
            super.reset();
        }
        /**
         * Store in a List the value of the cells for selected column in a map 
         * @author Damien Viel
         * @version 1.0
         * @throws JspException
         *
         */
        protected void storeMathData(double in_value) throws JspException {
            if (!isFirst()) {
                int lc_ligne = getIndex();
                int lc_col = getColumn();
                Object bean = getBean();
                String property = ((ItemContext)headers.get(lc_col)).getProperty();
                String mathOp =  ((ItemContext)headers.get(lc_col)).getMathOperation();
                if (mathOp!=null) {
                   String key = String.valueOf(lc_col);
                   if (!numbers.containsKey(key)){
                           double[] lc_list = new double[size]; // ???
                           numbers.put(key,lc_list);
                   }
                       double[] lc_list = (double[]) numbers.get(key);           
                   lc_list[index-1] = in_value;
                }
            }
        }
        /**
         * 
         * @author Damien Viel
         * @param in_operation
         * @param in_data
         * @return
         * @throws JspException
         */
        protected String doMathOperation(String in_operation, double[] in_data, String in_mathPattern) throws JspException {
            if (in_data!=null && in_operation!=null && in_operation.length()>0){            
                double total = computeMathResult(in_operation, in_data);
                if (in_mathPattern!=null){
                    NumberFormat lc_format = new DecimalFormat(in_mathPattern);
                    return lc_format.format(total);                
                }
                return String.valueOf(total);
            }
            return null;
        }
        /**
         * 
         * @author JNRibette
         * @param in_operation
         * @param in_data
         * @return
         * @throws JspException
         */
        protected double computeMathResult(String in_operation, double[] in_data) throws JspException {
            if (mathClass==null) {
                throw new IllegalStateException("Math operation is not available, please put commons-math.jar in the classpath");
            }
            Method m;
            try {
                m = mathClass.getMethod(in_operation, new Class[]{double[].class});
            } catch (NoSuchMethodException e) {
                throw new IllegalArgumentException("Math operation " + in_operation + " is not supported");
            }
            Double result = null;
            try {
                result = (Double) m.invoke(null,new Object[]{in_data});
            } catch (InvocationTargetException e) {
                // TODO log
                throw new JspException("Math operation " + in_operation + " failed : " + e.getMessage());
            } catch (IllegalAccessException e) {
                // TODO log
                throw new JspException("Math operation " + in_operation + " failed : " + e.getMessage());
            }
            return result.doubleValue();
            //return new BigDecimal(result.doubleValue()).setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue();
        }
     
     
     
    /**
     * add an item.
     */
    protected void addItem(StringBuffer in_buffer, String in_item, String in_url, String in_target, String in_onclick) throws JspException {
        // Display the table cell.        
        if (in_url==null) {
            renderItem(in_buffer, in_item);
        } else {
            StringBuffer lc_buffer = new StringBuffer();
            String lc_item = in_item;
            if (sortType==SORT_JAVASCRIPT) {
                if (lc_item.startsWith("<!--")) {        
                    // if we are sorting the collection on the client, make sure the resulting item still begin with the comment 
                    // which may be used to sort the items.
                    int lc_index = lc_item.indexOf("-->");
                    lc_buffer.append(lc_item.substring(0, lc_index +3));
                    lc_item = lc_item.substring(lc_index+3);
                } else {
                    // same concern, in case there is no preliminar comment.
                    lc_buffer.append("<!-- ");
                    lc_buffer.append(in_item);
                    lc_buffer.append("-->");
                }
            }
     
            lc_buffer.append("<a href=\"");
            lc_buffer.append(((HttpServletResponse)pageContext.getResponse()).encodeURL(in_url));
            if (in_onclick!=null) {
                lc_buffer.append("\" onClick=\"");
                lc_buffer.append(Expression.evaluate(in_onclick, pageContext));        
            }
            if (in_target!=null) {
                lc_buffer.append("\" target=\"");
                lc_buffer.append(in_target);
            }
            String lc_styleClass = styleClass;
            if (tempStyleClass != null) lc_styleClass = tempStyleClass;
            if (lc_styleClass != null) {
                lc_buffer.append("\" class=\"");
                lc_buffer.append(lc_styleClass);
            }        
            lc_buffer.append("\">");
            lc_buffer.append(lc_item);
            lc_buffer.append("</a>");
            renderItem(in_buffer, lc_buffer.toString());
        }
    }
     
     
    protected void renderBlankCollection(StringBuffer in_buffer) throws JspException { 
        panel.doPrintEmptyCollection(in_buffer, LayoutUtils.getLabel(pageContext, getBundle(), emptyKey, null, false));
    }
        // render the end of the table
        protected void renderEnd(StringBuffer buffer) throws JspException {
            renderMathData(buffer);
            renderFooter(buffer);
            panel.doEndPanel(buffer);
            renderStaticCode(buffer);
        }
     
        /**
         * Render the result for the specified math operation
         * @param in_buffer
         * @throws JspException
         */
        protected void renderMathData(StringBuffer in_buffer) throws JspException {
            if (!(panel instanceof IMathCollectionRenderer)) {
                return;
            }
            IMathCollectionRenderer lc_renderer = (IMathCollectionRenderer) panel;
     
            // did we start generated footer ?
            boolean started = false;
            // number of null consecutive footer.
            int consecutiveNull = 0;
            String uniqueParam = mathOperationId;
            int lc_nbOfSpan = 0; 
            for (int i=0; i < headers.size(); i++) {
                ItemContext lc_header = (ItemContext) headers.get(i);
                String lc_operation = lc_header.getMathOperation();
                String lc_mathStyleClass = tempStyleClass!=null ? tempStyleClass : styleClass; 
                String lc_mathPattern = lc_header.getMathPattern();
                double[] data = (double[])numbers.get(String.valueOf(i));
                String lc_data = doMathOperation(lc_operation,data,lc_mathPattern);
                // Unique identifier for the result cell
                String resultId = CollectionInputTag.MATH_ID_PREFIX + "t" + uniqueParam + "r" + i;
     
                // If there is no math operation to do
                if (lc_operation==null) {
                    consecutiveNull++;
                } else {
                    if (!started){
                        // Start rendering result !
                        lc_renderer.startMathData(in_buffer);
                        started = true;
                    }
     
                    // Generate an empty td with colspan = number of consecutive null.
                    if (consecutiveNull>0) {
                        lc_renderer.renderMathData(in_buffer, "&nbsp;", consecutiveNull, null,lc_mathStyleClass);
                        lc_nbOfSpan = lc_nbOfSpan + consecutiveNull;
                    }
     
                    // Generate the result cell.
                    lc_renderer.renderMathData(in_buffer, lc_data, 1, resultId,lc_mathStyleClass);
                    consecutiveNull = 0;
                    lc_nbOfSpan = lc_nbOfSpan + 1;
                }
            }
            if (started) {
                if (headers.size()-lc_nbOfSpan>0){
                    lc_renderer.renderMathData(in_buffer, "&nbsp;", headers.size()-lc_nbOfSpan, null,styleClass);
                }
                // There were result, close.
                lc_renderer.endMathData(in_buffer);
            }
     
        }
     
        /**
         * Render the footer of the collection.
         */
        protected void renderFooter(StringBuffer in_buffer) throws JspException {
            // Get IFooterRenderer
            if (!(panel instanceof IFooterRenderer)) {
                return;
            }
            IFooterRenderer lc_renderer = (IFooterRenderer) panel;
     
            // did we start generated footer ?
            boolean started = false;
     
            // number of null consecutive footer.
            int consecutiveNull = 0;
     
            for (int i=0; i < headers.size(); i++) {
                ItemContext lc_header = (ItemContext) headers.get(i);
                String lc_footer = lc_header.getFooter();
                if (lc_footer==null) {
                    consecutiveNull++;
                } else {
                    if (!started){
                        // Start rendering footer !
                        lc_renderer.startFooter(in_buffer);
                        started = true;
                    }
     
                    // Generate an empty td with colspan = number of consecutive null.
                    if (consecutiveNull>0) {
                        lc_renderer.printFooterElement(in_buffer, "&nbsp;", consecutiveNull);
                    }
     
                    // Generate the footer.
                    Object[] lc_args = new Object[5];
                    lc_args[0] = Expression.evaluate(lc_header.getFooterArg0(), pageContext);
                    lc_args[1] = Expression.evaluate(lc_header.getFooterArg1(), pageContext);
                    String lc_label = LayoutUtils.getLabel(pageContext, getBundle(), lc_footer, lc_args, false);
                    lc_renderer.printFooterElement(in_buffer, lc_label, 1);
                    consecutiveNull = 0;
     
                }
            }
     
            if (started) {
                // There were footer, close.
                lc_renderer.endFooter(in_buffer);
            }
        }
     
     
    /**
     * Print a column title to the buffer.
     * (mono level header)
     */
    protected void renderHeader(StringBuffer buffer, ItemContext in_header) throws JspException {
     
        // Compute the title.
        String lc_key = in_header.getTitle();
        String lc_arg0 = Expression.evaluate(in_header.getArg0(), pageContext);
        String lc_arg1 = Expression.evaluate(in_header.getArg1(), pageContext); 
        Object[] lc_args = new Object[2];
        lc_args[0] = lc_arg0;
        lc_args[1] = lc_arg1;
        String lc_title = LayoutUtils.getLabel(pageContext, getBundle(), lc_key, lc_args, false);
     
        // Compute the sort url.
        String lc_sortUrl = computeSortUrl(in_header.getSortProperty());
     
        // Print the title.
        panel.doPrintHeader(buffer, lc_title, in_header.getWidth(), lc_sortUrl);
    }
     
        protected String computeSortUrl(String in_sortProperty) {
            String lc_sortUrl = null;
            if (in_sortProperty!=null) {
                StringBuffer lc_tempBuffer = new StringBuffer();    
                switch (sortType) {
                    case SORT_LAYOUT:
                        String lc_unEncodedUrl = SortUtil.getURLForCollection(in_sortProperty, (javax.servlet.http.HttpServletRequest) pageContext.getRequest());
                        lc_tempBuffer.append(((HttpServletResponse)pageContext.getResponse()).encodeURL(lc_unEncodedUrl));
                        break;
                    case SORT_CUSTOM:
                        // use user custom sort action.                                
                        if (! sortAction.toLowerCase().startsWith("javascript:")) {
                            // No js code : go to the server to sort.
                            lc_tempBuffer.append(sortAction);
                            if (sortAction.indexOf("?")!=-1) lc_tempBuffer.append("&"); else lc_tempBuffer.append("?");
                            lc_tempBuffer.append(sortParam);
                            lc_tempBuffer.append("=");
                            lc_tempBuffer.append(in_sortProperty);
                        } else {
                            // Js code : need to put the right parameters at their place.                    
                            String javascriptSortParamName = "sortParam";
                            if (sortParam != null && sortParam.trim().length() > 0) {
                                javascriptSortParamName = sortParam;
                            }
                            pageContext.setAttribute(javascriptSortParamName, in_sortProperty);                    
                            lc_tempBuffer.append(Expression.evaluate(sortAction, pageContext));
                            pageContext.removeAttribute(javascriptSortParamName);
                        }
                        break;                
                    case SORT_JAVASCRIPT:
                        // sorting on the client browser with javascript.
                        lc_tempBuffer.append("javascript:arraySort(");
                        lc_tempBuffer.append(sortParam);
                        lc_tempBuffer.append(",");
                    /*
                     * Patch to get the correct column index when using Multi-level headers
                     * @author OButterlin
                     */
    //                    lc_tempBuffer.append(column);
                        lc_tempBuffer.append(getColumnIndexForProperty(sortProperty));
                        lc_tempBuffer.append(",");
                        lc_tempBuffer.append(size);
                        lc_tempBuffer.append(",");
                        lc_tempBuffer.append(nbOfColumns);
                        lc_tempBuffer.append(")");
                        break;
                }
                lc_sortUrl = lc_tempBuffer.toString();
            }
            return lc_sortUrl;
        }
     
        /**
         * Retrieve column index for property name
         * @author OButterlin
         */
        private int getColumnIndexForProperty(String name)
        {
            int idx = 0;
            Iterator it = headers.iterator();
            while (it.hasNext())
            {
                BaseCollectionTag.Header header = (BaseCollectionTag.Header)it.next();
                if (header.getProperty() != null && header.getProperty().equals(name)) return idx;
                idx++;
            }
            return idx;
        }
     
        private MultiLevelHeader currentHeader;
     
        /**
         * Print a column title to the buffer. 
         * (multi level header)
         */
        protected void renderMultiLevelHeaders(StringBuffer in_buffer, List in_multiLevelHeaders, int in_level) throws JspException {
            if (in_multiLevelHeaders!=null) {
                List lc_nestedLevels = null;
                Iterator lc_it = in_multiLevelHeaders.iterator();
                IMultiLevelHeaderRenderer lc_panel = (IMultiLevelHeaderRenderer) panel;            
                column = 0;            
     
                // Did we start a header row ?
                boolean lc_started = false;
     
                while (lc_it.hasNext()) {                
                    MultiLevelHeader lc_header = (MultiLevelHeader) lc_it.next();
                    List lc_headerChildren = lc_header.getChildHeaders();
                    int lc_rowSpan = lc_headerChildren!=null ? 1 : in_level+1 - lc_header.getLevel();
     
                    Object[] lc_args = new Object[2];
                    lc_args[0] = Expression.evaluate(lc_header.getArg0(), pageContext);
                    lc_args[1] = Expression.evaluate(lc_header.getArg1(), pageContext);
                    String lc_title = LayoutUtils.getLabel(pageContext, getBundle(), lc_header.getTitle(), lc_args, false);
                    String lc_sortUrl = computeSortUrl(lc_header.getSortProperty());
                    String lc_styleClass = lc_header.getStyleClass()==null ? getStyleClass() : lc_header.getStyleClass();
                    String lc_tooltip = LayoutUtils.getLabel(pageContext, getBundle(), lc_header.getTooltip(), null, false);
                    currentHeader = lc_header;
     
                    if (lc_title!=null) {
                        // Title is not null, render it.
     
                        if (!lc_started) {
                            // First time we render a title, start a title row.
                            lc_panel.startMultiLevelHeaderRow(in_buffer);
                            lc_started = true;
                        }
     
                        // Render the title.
                        lc_panel.renderMultiLevelHeader(in_buffer, lc_title, lc_sortUrl, lc_styleClass, lc_header.getColSpan(), lc_rowSpan, lc_header.getWidth());
                    }
                    currentHeader = null;
                    if (lc_headerChildren!=null) {
                        if (lc_nestedLevels==null) {
                            lc_nestedLevels = new ArrayList();
                        }
                        lc_nestedLevels.addAll(lc_headerChildren);
                    }
                    column++;
                }            
                if(lc_started) {
                    lc_panel.endMultiLevelHeaderRow(in_buffer);
                }
                renderMultiLevelHeaders(in_buffer, lc_nestedLevels, in_level-1);
            }
        }
     
        public MultiLevelHeader getCurrentHeader() {
            return currentHeader;
        }
     
    protected void renderItem(StringBuffer buffer, String in_item) throws JspException {
     
        String lc_item = in_item;
     
        // if the line of the table are selectable and this is the first column, add a checkbox or a radio button.
        if (needSelect && !selectHidden) {
            StringBuffer lc_tempBuffer = new StringBuffer();
            if (sortType==SORT_JAVASCRIPT && lc_item.startsWith("<!--")) {
                // if we are sorting the collection on the client, make sure the resulting item still begin with the comment 
                // which may be used to sort the items.
                int lc_index = lc_item.indexOf("-->");
                lc_tempBuffer.append(lc_item.substring(0, lc_index +3));
                lc_item = lc_item.substring(lc_index+3);
            }
            renderSelection(lc_tempBuffer);
            needSelect = false;
            lc_tempBuffer.append(lc_item);
            lc_item = lc_tempBuffer.toString();
        }
     
     
        String[] lc_styleClasses = new String[1 + tempStyles.size()];
        lc_styleClasses[0] = tempStyleClass!=null ? tempStyleClass : styleClass;
        for (int i=0; i <  tempStyles.size(); i++) {
            lc_styleClasses[i+1] = (String) tempStyles.get(i);
        }
     
        panel.doPrintItem(buffer, lc_item, lc_styleClasses, sortType==SORT_JAVASCRIPT ? "t" + sortParam + "l" + index + "c" + column : null);
    }
     
        protected void renderSelection(StringBuffer lc_tempBuffer) throws JspException {
            lc_tempBuffer.append("<input type=\"");
            if ("checkbox".equalsIgnoreCase(selectType)) {
                lc_tempBuffer.append("checkbox");    
            } else {
                lc_tempBuffer.append("radio");    
            }
            lc_tempBuffer.append("\" name=\"");
            if (selectName!=null) {
                lc_tempBuffer.append(selectName);
            } else {
                lc_tempBuffer.append(selectProperty);    
            }    
            if ("checkbox".equalsIgnoreCase(selectType)) {
                if (selectId!=null) {
                    lc_tempBuffer.append("(");
                    lc_tempBuffer.append(LayoutUtils.getProperty(bean, selectId));
                    lc_tempBuffer.append(")");
                } else {
                    lc_tempBuffer.append("[");
                    lc_tempBuffer.append(index-1);
                    lc_tempBuffer.append("]");
                    if (selectIndex!=null) {
                        lc_tempBuffer.append(".");
                        lc_tempBuffer.append(selectIndex);
                    }
                }                            
            }
     
            if (onClick!=null) {
                lc_tempBuffer.append("\" onclick=\"");
                lc_tempBuffer.append(onClick);    
            }
     
            lc_tempBuffer.append("\" value=\"");
            Object lc_value = LayoutUtils.getProperty(bean, selectProperty);
            lc_tempBuffer.append(lc_value);
            lc_tempBuffer.append("\"");
     
            // check if the value is selected.
            if (isCurrentBeanSelected()) {
                lc_tempBuffer.append(" checked");
            }
     
            lc_tempBuffer.append(">");
    }
     
        protected void renderStart(StringBuffer out_buffer) throws JspException {
            // Display the title.
            // we do not use the possibility of the PanelTag to do that.
            Object[] lc_args = new Object[5];
            Object lc_arg0 = null;
            if (arg0Name!=null) {
                lc_arg0 = LayoutUtils.getBeanFromPageContext(pageContext, arg0Name, null);
            }
            lc_args[0] = lc_arg0;
            panel.doPrintTitle(out_buffer, LayoutUtils.getLabel(pageContext, getBundle(), title, lc_args, false));
     
            panel.doStartPanel(out_buffer, align,width);                
        }
     
     
        /**
         * Returns true if the bean at the current index is selected. Results only valid 
         * when called once iteration is under way.
         * @return boolean
         * @throws JspException
         * @author LeeFreyberg
         */
        public boolean isCurrentBeanSelected() throws JspException{
            if (selectName!=null) {
                Object lc_selectedValue = null;
                if ("checkbox".equalsIgnoreCase(selectType)) {
                    if (selectId==null) {
                        lc_selectedValue = LayoutUtils.getBeanFromPageContext(pageContext, Constants.BEAN_KEY, selectName + "[" + (index-1) +"]");
                    } else {
                        lc_selectedValue = LayoutUtils.getBeanFromPageContext(pageContext, Constants.BEAN_KEY, selectName + "(" + LayoutUtils.getProperty(bean, selectId) +")");
                    }
                } else {
                    lc_selectedValue = LayoutUtils.getBeanFromPageContext(pageContext, Constants.BEAN_KEY, selectName);
                }
                if (lc_selectedValue!=null && lc_selectedValue.equals(LayoutUtils.getProperty(bean, selectProperty))) {
                    return true;
                }
            }
            return false;
        }
        public Object processStaticCodeIncludeEvent(StaticCodeIncludeLayoutEvent in_event) throws JspException {
            String lc_codeToPrint = (String) in_event.sendToParent(this);
            staticCode += lc_codeToPrint;
            return "";
        }
        protected void renderStaticCode(StringBuffer out_buffer) {
            if (staticCode.length()>0) {
                out_buffer.append(staticCode);
                staticCode = "";
            }
        }
    }
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  2. #22
    Membre éprouvé

    Inscrit en
    Juin 2005
    Messages
    1 155
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 1 155
    Par défaut
    juste après ton commentaire
    patch to get the correct...
    Tu utilises une variable sortPoperty que tu ne défini nul part.
    J'ai vu le change log de la version 1.4 et ça ne vaut (pour moi) pas le coup de passer en 1.4

  3. #23
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Je regarderai ce soir calmement... Je te tiens au courant...
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  4. #24
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Finalement, ce n'était pas grand chose...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
     
    package fr.improve.struts.taglib.layout.collection;
     
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
     
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.jsp.JspException;
     
    import org.apache.struts.taglib.html.Constants;
    import org.apache.struts.util.RequestUtils;
     
    import fr.improve.struts.taglib.layout.collection.header.MultiLevelHeader;
    import fr.improve.struts.taglib.layout.el.Expression;
    import fr.improve.struts.taglib.layout.event.StaticCodeIncludeLayoutEvent;
    import fr.improve.struts.taglib.layout.event.StaticCodeIncludeListener;
    import fr.improve.struts.taglib.layout.sort.SortUtil;
    import fr.improve.struts.taglib.layout.util.IFooterRenderer;
    import fr.improve.struts.taglib.layout.util.IMathCollectionRenderer;
    import fr.improve.struts.taglib.layout.util.IMultiLevelHeaderRenderer;
    import fr.improve.struts.taglib.layout.util.LayoutUtils;
     
    /**
     * This class is responsible for displaying the collection.<br />
     * Actually, the rendering is done by another class implementing the
     * CollectionInterface. This class just computes differents parameters (headers
     * and items).
     * 
     * @author: Jean-Noel Ribette
     **/
    public class CollectionTag extends BaseCollectionTag implements
            StaticCodeIncludeListener {
        /**
         * Math class
         */
        static Class mathClass;
     
        static {
            try {
                mathClass = RequestUtils
                        .applicationClass("org.apache.commons.math.stat.StatUtils");
            } catch (ClassNotFoundException e) {
                // Math class is not available.
            }
        }
     
        /**
         * String of the static code to generate.
         */
        private String staticCode = "";
     
        /**
         * Map of the numbers for operation
         */
        protected Map numbers = new HashMap();
     
        /*
         * (non-Javadoc)
         * 
         * @see fr.improve.struts.taglib.layout.BodyLayoutTagSupport#reset()
         */
        protected void reset() {
            numbers.clear();
            super.reset();
        }
     
        /**
         * Store in a List the value of the cells for selected column in a map
         * 
         * @author Damien Viel
         * @version 1.0
         * @throws JspException
         * 
         */
        protected void storeMathData(double in_value) throws JspException {
            if (!isFirst()) {
                int lc_ligne = getIndex();
                int lc_col = getColumn();
                Object bean = getBean();
                String property = ((ItemContext) headers.get(lc_col)).getProperty();
                String mathOp = ((ItemContext) headers.get(lc_col))
                        .getMathOperation();
                if (mathOp != null) {
                    String key = String.valueOf(lc_col);
                    if (!numbers.containsKey(key)) {
                        double[] lc_list = new double[size]; // ???
                        numbers.put(key, lc_list);
                    }
                    double[] lc_list = (double[]) numbers.get(key);
                    lc_list[index - 1] = in_value;
                }
            }
        }
     
        /**
         * 
         * @author Damien Viel
         * @param in_operation
         * @param in_data
         * @return
         * @throws JspException
         */
        protected String doMathOperation(String in_operation, double[] in_data,
                String in_mathPattern) throws JspException {
            if (in_data != null && in_operation != null
                    && in_operation.length() > 0) {
                double total = computeMathResult(in_operation, in_data);
                if (in_mathPattern != null) {
                    NumberFormat lc_format = new DecimalFormat(in_mathPattern);
                    return lc_format.format(total);
                }
                return String.valueOf(total);
            }
            return null;
        }
     
        /**
         * 
         * @author JNRibette
         * @param in_operation
         * @param in_data
         * @return
         * @throws JspException
         */
        protected double computeMathResult(String in_operation, double[] in_data)
                throws JspException {
            if (mathClass == null) {
                throw new IllegalStateException(
                        "Math operation is not available, please put commons-math.jar in the classpath");
            }
            Method m;
            try {
                m = mathClass.getMethod(in_operation,
                        new Class[] { double[].class });
            } catch (NoSuchMethodException e) {
                throw new IllegalArgumentException("Math operation " + in_operation
                        + " is not supported");
            }
            Double result = null;
            try {
                result = (Double) m.invoke(null, new Object[] { in_data });
            } catch (InvocationTargetException e) {
                // TODO log
                throw new JspException("Math operation " + in_operation
                        + " failed : " + e.getMessage());
            } catch (IllegalAccessException e) {
                // TODO log
                throw new JspException("Math operation " + in_operation
                        + " failed : " + e.getMessage());
            }
            return result.doubleValue();
            // return new
            // BigDecimal(result.doubleValue()).setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue();
        }
     
        /**
         * add an item.
         */
        protected void addItem(StringBuffer in_buffer, String in_item,
                String in_url, String in_target, String in_onclick)
                throws JspException {
            // Display the table cell.
            if (in_url == null) {
                renderItem(in_buffer, in_item);
            } else {
                StringBuffer lc_buffer = new StringBuffer();
                String lc_item = in_item;
                if (sortType == SORT_JAVASCRIPT) {
                    if (lc_item.startsWith("<!--")) {
                        // if we are sorting the collection on the client, make sure
                        // the resulting item still begin with the comment
                        // which may be used to sort the items.
                        int lc_index = lc_item.indexOf("-->");
                        lc_buffer.append(lc_item.substring(0, lc_index + 3));
                        lc_item = lc_item.substring(lc_index + 3);
                    } else {
                        // same concern, in case there is no preliminar comment.
                        lc_buffer.append("<!-- ");
                        lc_buffer.append(in_item);
                        lc_buffer.append("-->");
                    }
                }
     
                lc_buffer.append("<a href=\"");
                lc_buffer.append(((HttpServletResponse) pageContext.getResponse())
                        .encodeURL(in_url));
                if (in_onclick != null) {
                    lc_buffer.append("\" onClick=\"");
                    lc_buffer.append(Expression.evaluate(in_onclick, pageContext));
                }
                if (in_target != null) {
                    lc_buffer.append("\" target=\"");
                    lc_buffer.append(in_target);
                }
                String lc_styleClass = styleClass;
                if (tempStyleClass != null)
                    lc_styleClass = tempStyleClass;
                if (lc_styleClass != null) {
                    lc_buffer.append("\" class=\"");
                    lc_buffer.append(lc_styleClass);
                }
                lc_buffer.append("\">");
                lc_buffer.append(lc_item);
                lc_buffer.append("</a>");
                renderItem(in_buffer, lc_buffer.toString());
            }
        }
     
        protected void renderBlankCollection(StringBuffer in_buffer)
                throws JspException {
            panel.doPrintEmptyCollection(in_buffer, LayoutUtils.getLabel(
                    pageContext, getBundle(), emptyKey, null, false));
        }
     
        // render the end of the table
        protected void renderEnd(StringBuffer buffer) throws JspException {
            renderMathData(buffer);
            renderFooter(buffer);
            panel.doEndPanel(buffer);
            renderStaticCode(buffer);
        }
     
        /**
         * Render the result for the specified math operation
         * 
         * @param in_buffer
         * @throws JspException
         */
        protected void renderMathData(StringBuffer in_buffer) throws JspException {
            if (!(panel instanceof IMathCollectionRenderer)) {
                return;
            }
            IMathCollectionRenderer lc_renderer = (IMathCollectionRenderer) panel;
     
            // did we start generated footer ?
            boolean started = false;
            // number of null consecutive footer.
            int consecutiveNull = 0;
            String uniqueParam = mathOperationId;
            int lc_nbOfSpan = 0;
            for (int i = 0; i < headers.size(); i++) {
                ItemContext lc_header = (ItemContext) headers.get(i);
                String lc_operation = lc_header.getMathOperation();
                String lc_mathStyleClass = tempStyleClass != null ? tempStyleClass
                        : styleClass;
                String lc_mathPattern = lc_header.getMathPattern();
                double[] data = (double[]) numbers.get(String.valueOf(i));
                String lc_data = doMathOperation(lc_operation, data, lc_mathPattern);
                // Unique identifier for the result cell
                String resultId = CollectionInputTag.MATH_ID_PREFIX + "t"
                        + uniqueParam + "r" + i;
     
                // If there is no math operation to do
                if (lc_operation == null) {
                    consecutiveNull++;
                } else {
                    if (!started) {
                        // Start rendering result !
                        lc_renderer.startMathData(in_buffer);
                        started = true;
                    }
     
                    // Generate an empty td with colspan = number of consecutive
                    // null.
                    if (consecutiveNull > 0) {
                        lc_renderer.renderMathData(in_buffer, "&nbsp;",
                                consecutiveNull, null, lc_mathStyleClass);
                        lc_nbOfSpan = lc_nbOfSpan + consecutiveNull;
                    }
     
                    // Generate the result cell.
                    lc_renderer.renderMathData(in_buffer, lc_data, 1, resultId,
                            lc_mathStyleClass);
                    consecutiveNull = 0;
                    lc_nbOfSpan = lc_nbOfSpan + 1;
                }
            }
            if (started) {
                if (headers.size() - lc_nbOfSpan > 0) {
                    lc_renderer.renderMathData(in_buffer, "&nbsp;", headers.size()
                            - lc_nbOfSpan, null, styleClass);
                }
                // There were result, close.
                lc_renderer.endMathData(in_buffer);
            }
     
        }
     
        /**
         * Render the footer of the collection.
         */
        protected void renderFooter(StringBuffer in_buffer) throws JspException {
            // Get IFooterRenderer
            if (!(panel instanceof IFooterRenderer)) {
                return;
            }
            IFooterRenderer lc_renderer = (IFooterRenderer) panel;
     
            // did we start generated footer ?
            boolean started = false;
     
            // number of null consecutive footer.
            int consecutiveNull = 0;
     
            for (int i = 0; i < headers.size(); i++) {
                ItemContext lc_header = (ItemContext) headers.get(i);
                String lc_footer = lc_header.getFooter();
                if (lc_footer == null) {
                    consecutiveNull++;
                } else {
                    if (!started) {
                        // Start rendering footer !
                        lc_renderer.startFooter(in_buffer);
                        started = true;
                    }
     
                    // Generate an empty td with colspan = number of consecutive
                    // null.
                    if (consecutiveNull > 0) {
                        lc_renderer.printFooterElement(in_buffer, "&nbsp;",
                                consecutiveNull);
                    }
     
                    // Generate the footer.
                    Object[] lc_args = new Object[5];
                    lc_args[0] = Expression.evaluate(lc_header.getFooterArg0(),
                            pageContext);
                    lc_args[1] = Expression.evaluate(lc_header.getFooterArg1(),
                            pageContext);
                    String lc_label = LayoutUtils.getLabel(pageContext,
                            getBundle(), lc_footer, lc_args, false);
                    lc_renderer.printFooterElement(in_buffer, lc_label, 1);
                    consecutiveNull = 0;
     
                }
            }
     
            if (started) {
                // There were footer, close.
                lc_renderer.endFooter(in_buffer);
            }
        }
     
        /**
         * Print a column title to the buffer. (mono level header)
         */
        protected void renderHeader(StringBuffer buffer, ItemContext in_header)
                throws JspException {
     
            // Compute the title.
            String lc_key = in_header.getTitle();
            String lc_arg0 = Expression.evaluate(in_header.getArg0(), pageContext);
            String lc_arg1 = Expression.evaluate(in_header.getArg1(), pageContext);
            Object[] lc_args = new Object[2];
            lc_args[0] = lc_arg0;
            lc_args[1] = lc_arg1;
            String lc_title = LayoutUtils.getLabel(pageContext, getBundle(),
                    lc_key, lc_args, false);
     
            // Compute the sort url.
            String lc_sortUrl = computeSortUrl(in_header.getSortProperty());
     
            // Print the title.
            panel.doPrintHeader(buffer, lc_title, in_header.getWidth(), lc_sortUrl);
        }
     
        protected String computeSortUrl(String in_sortProperty) {
            String lc_sortUrl = null;
            if (in_sortProperty != null) {
                StringBuffer lc_tempBuffer = new StringBuffer();
                switch (sortType) {
                case SORT_LAYOUT:
                    String lc_unEncodedUrl = SortUtil.getURLForCollection(
                            in_sortProperty,
                            (javax.servlet.http.HttpServletRequest) pageContext
                                    .getRequest());
                    lc_tempBuffer.append(((HttpServletResponse) pageContext
                            .getResponse()).encodeURL(lc_unEncodedUrl));
                    break;
                case SORT_CUSTOM:
                    // use user custom sort action.
                    if (!sortAction.toLowerCase().startsWith("javascript:")) {
                        // No js code : go to the server to sort.
                        lc_tempBuffer.append(sortAction);
                        if (sortAction.indexOf("?") != -1)
                            lc_tempBuffer.append("&");
                        else
                            lc_tempBuffer.append("?");
                        lc_tempBuffer.append(sortParam);
                        lc_tempBuffer.append("=");
                        lc_tempBuffer.append(in_sortProperty);
                    } else {
                        // Js code : need to put the right parameters at their
                        // place.
                        String javascriptSortParamName = "sortParam";
                        if (sortParam != null && sortParam.trim().length() > 0) {
                            javascriptSortParamName = sortParam;
                        }
                        pageContext.setAttribute(javascriptSortParamName,
                                in_sortProperty);
                        lc_tempBuffer.append(Expression.evaluate(sortAction,
                                pageContext));
                        pageContext.removeAttribute(javascriptSortParamName);
                    }
                    break;
                case SORT_JAVASCRIPT:
                    // sorting on the client browser with javascript.
                    lc_tempBuffer.append("javascript:arraySort(");
                    lc_tempBuffer.append(sortParam);
                    lc_tempBuffer.append(",");
                    /*
                     * Patch to get the correct column index when using Multi-level headers
                     * @author OButterlin
                     */
                    lc_tempBuffer.append(getColumnIndexForProperty(in_sortProperty));
                    // lc_tempBuffer.append(column);
                    lc_tempBuffer.append(",");
                    lc_tempBuffer.append(size);
                    lc_tempBuffer.append(",");
                    lc_tempBuffer.append(nbOfColumns);
                    lc_tempBuffer.append(")");
                    break;
                }
                lc_sortUrl = lc_tempBuffer.toString();
            }
            return lc_sortUrl;
        }
     
        /**
         * Retrieve column index for property name
         * @author OButterlin
         */
        private int getColumnIndexForProperty(String name) {
            int idx = 0;
            Iterator it = headers.iterator();
            while (it.hasNext()) {
                BaseCollectionTag.Header header = (BaseCollectionTag.Header) it
                        .next();
                if (header.getProperty() != null
                        && header.getProperty().equals(name))
                    return idx;
                idx++;
            }
            return idx;
        }
     
        private MultiLevelHeader currentHeader;
     
        /**
         * Print a column title to the buffer. (multi level header)
         */
        protected void renderMultiLevelHeaders(StringBuffer in_buffer,
                List in_multiLevelHeaders, int in_level) throws JspException {
            if (in_multiLevelHeaders != null) {
                List lc_nestedLevels = null;
                Iterator lc_it = in_multiLevelHeaders.iterator();
                IMultiLevelHeaderRenderer lc_panel = (IMultiLevelHeaderRenderer) panel;
                column = 0;
     
                // Did we start a header row ?
                boolean lc_started = false;
     
                while (lc_it.hasNext()) {
                    MultiLevelHeader lc_header = (MultiLevelHeader) lc_it.next();
                    List lc_headerChildren = lc_header.getChildHeaders();
                    int lc_rowSpan = lc_headerChildren != null ? 1 : in_level + 1
                            - lc_header.getLevel();
     
                    Object[] lc_args = new Object[2];
                    lc_args[0] = Expression.evaluate(lc_header.getArg0(),
                            pageContext);
                    lc_args[1] = Expression.evaluate(lc_header.getArg1(),
                            pageContext);
                    String lc_title = LayoutUtils.getLabel(pageContext,
                            getBundle(), lc_header.getTitle(), lc_args, false);
                    String lc_sortUrl = computeSortUrl(lc_header.getSortProperty());
                    String lc_styleClass = lc_header.getStyleClass() == null ? getStyleClass()
                            : lc_header.getStyleClass();
                    String lc_tooltip = LayoutUtils.getLabel(pageContext,
                            getBundle(), lc_header.getTooltip(), null, false);
                    currentHeader = lc_header;
     
                    if (lc_title != null) {
                        // Title is not null, render it.
     
                        if (!lc_started) {
                            // First time we render a title, start a title row.
                            lc_panel.startMultiLevelHeaderRow(in_buffer);
                            lc_started = true;
                        }
     
                        // Render the title.
                        lc_panel.renderMultiLevelHeader(in_buffer, lc_title,
                                lc_sortUrl, lc_styleClass, lc_header.getColSpan(),
                                lc_rowSpan, lc_header.getWidth());
                    }
                    currentHeader = null;
                    if (lc_headerChildren != null) {
                        if (lc_nestedLevels == null) {
                            lc_nestedLevels = new ArrayList();
                        }
                        lc_nestedLevels.addAll(lc_headerChildren);
                    }
                    column++;
                }
                if (lc_started) {
                    lc_panel.endMultiLevelHeaderRow(in_buffer);
                }
                renderMultiLevelHeaders(in_buffer, lc_nestedLevels, in_level - 1);
            }
        }
     
        public MultiLevelHeader getCurrentHeader() {
            return currentHeader;
        }
     
        protected void renderItem(StringBuffer buffer, String in_item)
                throws JspException {
     
            String lc_item = in_item;
     
            // if the line of the table are selectable and this is the first column,
            // add a checkbox or a radio button.
            if (needSelect && !selectHidden) {
                StringBuffer lc_tempBuffer = new StringBuffer();
                if (sortType == SORT_JAVASCRIPT && lc_item.startsWith("<!--")) {
                    // if we are sorting the collection on the client, make sure the
                    // resulting item still begin with the comment
                    // which may be used to sort the items.
                    int lc_index = lc_item.indexOf("-->");
                    lc_tempBuffer.append(lc_item.substring(0, lc_index + 3));
                    lc_item = lc_item.substring(lc_index + 3);
                }
                renderSelection(lc_tempBuffer);
                needSelect = false;
                lc_tempBuffer.append(lc_item);
                lc_item = lc_tempBuffer.toString();
            }
     
            String[] lc_styleClasses = new String[1 + tempStyles.size()];
            lc_styleClasses[0] = tempStyleClass != null ? tempStyleClass
                    : styleClass;
            for (int i = 0; i < tempStyles.size(); i++) {
                lc_styleClasses[i + 1] = (String) tempStyles.get(i);
            }
     
            panel.doPrintItem(buffer, lc_item, lc_styleClasses,
                    sortType == SORT_JAVASCRIPT ? "t" + sortParam + "l" + index
                            + "c" + column : null);
        }
     
        protected void renderSelection(StringBuffer lc_tempBuffer)
                throws JspException {
            lc_tempBuffer.append("<input type=\"");
            if ("checkbox".equalsIgnoreCase(selectType)) {
                lc_tempBuffer.append("checkbox");
            } else {
                lc_tempBuffer.append("radio");
            }
            lc_tempBuffer.append("\" name=\"");
            if (selectName != null) {
                lc_tempBuffer.append(selectName);
            } else {
                lc_tempBuffer.append(selectProperty);
            }
            if ("checkbox".equalsIgnoreCase(selectType)) {
                if (selectId != null) {
                    lc_tempBuffer.append("(");
                    lc_tempBuffer.append(LayoutUtils.getProperty(bean, selectId));
                    lc_tempBuffer.append(")");
                } else {
                    lc_tempBuffer.append("[");
                    lc_tempBuffer.append(index - 1);
                    lc_tempBuffer.append("]");
                    if (selectIndex != null) {
                        lc_tempBuffer.append(".");
                        lc_tempBuffer.append(selectIndex);
                    }
                }
            }
     
            if (onClick != null) {
                lc_tempBuffer.append("\" onclick=\"");
                lc_tempBuffer.append(onClick);
            }
     
            lc_tempBuffer.append("\" value=\"");
            Object lc_value = LayoutUtils.getProperty(bean, selectProperty);
            lc_tempBuffer.append(lc_value);
            lc_tempBuffer.append("\"");
     
            // check if the value is selected.
            if (isCurrentBeanSelected()) {
                lc_tempBuffer.append(" checked");
            }
     
            lc_tempBuffer.append(">");
        }
     
        protected void renderStart(StringBuffer out_buffer) throws JspException {
            // Display the title.
            // we do not use the possibility of the PanelTag to do that.
            Object[] lc_args = new Object[5];
            Object lc_arg0 = null;
            if (arg0Name != null) {
                lc_arg0 = LayoutUtils.getBeanFromPageContext(pageContext, arg0Name,
                        null);
            }
            lc_args[0] = lc_arg0;
            panel.doPrintTitle(out_buffer, LayoutUtils.getLabel(pageContext,
                    getBundle(), title, lc_args, false));
     
            panel.doStartPanel(out_buffer, align, width);
        }
     
        /**
         * Returns true if the bean at the current index is selected. Results only
         * valid when called once iteration is under way.
         * 
         * @return boolean
         * @throws JspException
         * @author LeeFreyberg
         */
        public boolean isCurrentBeanSelected() throws JspException {
            if (selectName != null) {
                Object lc_selectedValue = null;
                if ("checkbox".equalsIgnoreCase(selectType)) {
                    if (selectId == null) {
                        lc_selectedValue = LayoutUtils.getBeanFromPageContext(
                                pageContext, Constants.BEAN_KEY, selectName + "["
                                        + (index - 1) + "]");
                    } else {
                        lc_selectedValue = LayoutUtils.getBeanFromPageContext(
                                pageContext, Constants.BEAN_KEY, selectName + "("
                                        + LayoutUtils.getProperty(bean, selectId)
                                        + ")");
                    }
                } else {
                    lc_selectedValue = LayoutUtils.getBeanFromPageContext(
                            pageContext, Constants.BEAN_KEY, selectName);
                }
                if (lc_selectedValue != null
                        && lc_selectedValue.equals(LayoutUtils.getProperty(bean,
                                selectProperty))) {
                    return true;
                }
            }
            return false;
        }
     
        public Object processStaticCodeIncludeEvent(
                StaticCodeIncludeLayoutEvent in_event) throws JspException {
            String lc_codeToPrint = (String) in_event.sendToParent(this);
            staticCode += lc_codeToPrint;
            return "";
        }
     
        protected void renderStaticCode(StringBuffer out_buffer) {
            if (staticCode.length() > 0) {
                out_buffer.append(staticCode);
                staticCode = "";
            }
        }
    }
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  5. #25
    Membre éprouvé

    Inscrit en
    Juin 2005
    Messages
    1 155
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 1 155
    Par défaut
    Visiblement nous n'avons pas le même souci, mon problème est toujours d'actualité, sachant que je n'utilise pas de <collection:title> ni de pager.

  6. #26
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Quand tu survoles l'icône de tri, qu'est ce qui s'affiche dans la zone status de la fenêtre ?
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  7. #27
    Membre éprouvé

    Inscrit en
    Juin 2005
    Messages
    1 155
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 1 155

  8. #28
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Mais avec quels paramètres ?
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  9. #29
    Membre éprouvé

    Inscrit en
    Juin 2005
    Messages
    1 155
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 1 155
    Par défaut
    Quatre paramètres:
    Le premier est toujours à 1.
    Le seconde est le numéro de la colonne en commençant par 0.
    Le troisième j'ai l'impression que c'est le nombre total de lignes contenues dans ma collection.
    Le quatrième est toujours à 10.
    Ce qui nous fais:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    javascript:arraySort(1,0,100,10)
    pour le tri de la première colonne d'une collection contenant 100 beans, que ce soit pour un tri ascendant ou descendant.

  10. #30
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Et l'indice de la colonne correspond bien à ta demande ?

    Si oui, quel navigateur utilises-tu et quelle version de struts-layout précisément ?
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  11. #31
    Membre éprouvé

    Inscrit en
    Juin 2005
    Messages
    1 155
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 1 155
    Par défaut
    Et l'indice de la colonne correspond bien à ta demande ?
    Oui.
    quel navigateur utilises-tu
    IE 8 et FF 3.5.8 et le résultat est similaire.
    Pour la version struts-layout c'est une 1.3 je ne saurais être plus précis.

  12. #32
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Peux-tu joindre le source de la page sur le navigateur ?
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  13. #33
    Membre éprouvé

    Inscrit en
    Juin 2005
    Messages
    1 155
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 1 155
    Par défaut
    Bien sur.
    source.txt
    Je n'ai aucune erreur javascript.

  14. #34
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Ça semble correcte à première vue, bizarre

    Tu as déjà récupéré la dernière version de struts-layout 1.3 sur leur site ?
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  15. #35
    Membre éprouvé

    Inscrit en
    Juin 2005
    Messages
    1 155
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 1 155
    Par défaut
    J'ai le souvenir d'avoir récupéré une version stable.

  16. #36
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Peux-tu vérifier ?
    En passant, peux-tu également montrer le fichier struts-layout.properties ?
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

Discussions similaires

  1. [Struts-Layout] Trop de colonnes lors d'un "add" sur un datagrid
    Par worldchampion57 dans le forum Struts 1
    Réponses: 12
    Dernier message: 07/04/2009, 14h25
  2. Réponses: 8
    Dernier message: 24/09/2007, 15h39
  3. [Struts-Layout] utilisation du tag date
    Par osman.amine dans le forum Struts 1
    Réponses: 3
    Dernier message: 25/05/2007, 15h59
  4. [XSLT] Tri de date par mois : comment faire ?
    Par sdkddk dans le forum XSL/XSLT/XPATH
    Réponses: 5
    Dernier message: 04/08/2006, 21h37
  5. Ajout date pendant importation
    Par uloaccess dans le forum Access
    Réponses: 11
    Dernier message: 09/01/2006, 16h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo