Details

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

      Description

      ====
      imported from sf tracker
      id 1014368
      submitted by Joost den Boer - joostdenboer
      http://sourceforge.net/support/tracker.php?aid=1014368
      ====

       Hi,

      For a project I added functionality to the Displaytag
      version 1.0-rc2 to support the title-attribute of the TH-
      tag. I renamed the current 'title' attribute of the
      ColumnTag to 'name' and added a new title attribute. I
      made sure that if no name was given, the title is used
      for backwards compatibility.

      I attached the sources I modified. Maybe you want to
      include this in the next release.

      Changes made :
      -ColumnTag: renamed title to name and added a new
      title attribute with get\set methodes

      -HeaderCell : added name property

      -TableTag and BaseExportView : use getName() in stead
      of getTitle for the tagcontent.

      -displaytag-12.tld and displaytag-el-12.tld : added
      name property from ColumnTag

      Regards,
      Joost

        Activity

        Hide
        fabrizio giustina added a comment -
        Date: 2004-08-23 18:36
        Sender: mraible
        user_id=226669

        I'm confused - why should we rename "title" to "name"? You
        give no reasons to make this change.



        Date: 2004-08-23 19:22
        Sender: joostdenboer
        user_id=714989

        I renamed "title" to "name" because it makes more sense (to
        me) for the title to be used for the title attribute of the
        TH-tag then for the content of the TH-tag.
        Show
        fabrizio giustina added a comment - Date: 2004-08-23 18:36 Sender: mraible user_id=226669 I'm confused - why should we rename "title" to "name"? You give no reasons to make this change. Date: 2004-08-23 19:22 Sender: joostdenboer user_id=714989 I renamed "title" to "name" because it makes more sense (to me) for the title to be used for the title attribute of the TH-tag then for the content of the TH-tag.
        Hide
        fabrizio giustina added a comment -
        Zip containing modified source files
        Show
        fabrizio giustina added a comment - Zip containing modified source files
        Hide
        Mike Calmus added a comment -
        The title attribute as a part of the header is an important accessibility issue for our project. Besides simply being able to put a (more or less) static attribute into the header from a jsp, we actually need to have the title show something like "sort by Column in ascending order" which would obviously change dynamically based upon the current (if it exists) and default sort orders of a column.

        The suggested fix will work fine for the first step, but because it's effectively impossible to subclass HeaderCell (it's created in a private method of ColumnTag), there is no way to do anything truly dynamic with this patch. DISPL-456 has been created as a subtask of this issue to address this need.
        Show
        Mike Calmus added a comment - The title attribute as a part of the header is an important accessibility issue for our project. Besides simply being able to put a (more or less) static attribute into the header from a jsp, we actually need to have the title show something like "sort by Column in ascending order" which would obviously change dynamically based upon the current (if it exists) and default sort orders of a column. The suggested fix will work fine for the first step, but because it's effectively impossible to subclass HeaderCell (it's created in a private method of ColumnTag), there is no way to do anything truly dynamic with this patch. DISPL-456 has been created as a subtask of this issue to address this need.
        Hide
        Tim Stavenger added a comment -
        I have also found a need for setting the title HTML attribute on the TH tag. For example, <th title="Click to sort column in ascending order">My Column</th>. Using the title attributes gives screen readers the ability to know what clicking the column does. Without it, the link alone doesn't tell you what it does and the background image doesn't have a way to set an alternative text. However, I think a better solution may be to set the title attribute of the anchor tag for the link itself?

        In the meantime (until this issue is resolved), I've written a workaround that uses a custom table decorator that iterates over all of the header cells and sets the title attribute if it is sortable:

        /**
         * Add the HTML title attribute on the header cells to indicate sorting options.
         */
        public class SortTitleTableDecorator extends TableDecorator {
            private static final String RESOURCE_BUNDLE = "resources";
            private static final String TITLE_ATTRIBUTE = "title";

            private static final String ASCENDING_SORT = "table.sort.ascending";
            private static final String DESCENDING_SORT = "table.sort.descending";

            /**
             * Initialize the TableTecorator instance.
             *
             * @param pageContext PageContext
             * @param decorated decorated object (usually a list)
             * @param tableModel table model
             *
             * @see org.displaytag.decorator.Decorator#init(javax.servlet.jsp.PageContext, java.lang.Object,
             * org.displaytag.model.TableModel)
             */
            @Override
            public void init(PageContext pageContext, Object decorated, TableModel tableModel) {
                setHeaderSortTitles(tableModel, pageContext.getRequest().getLocale());

                super.init(pageContext, decorated, tableModel);
            }

            /**
             * Set the HTML title attribute on the header cells to indicate sorting options.
             *
             * @param tableModel TableModel with header cells
             * @param locale Locale to localize HTML title attribute
             */
            private void setHeaderSortTitles(TableModel tableModel, Locale locale) {
                List<HeaderCell> headerCells = tableModel.getHeaderCellList();

                for (HeaderCell headerCell : headerCells) {
                    if (headerCell.getSortable()) {
                        if (headerCell.isAlreadySorted() && tableModel.isSortOrderAscending()) {
                            headerCell.getHeaderAttributes().put(TITLE_ATTRIBUTE, getLocalizedTitle(DESCENDING_SORT, locale));
                        }
                        else {
                            headerCell.getHeaderAttributes().put(TITLE_ATTRIBUTE, getLocalizedTitle(ASCENDING_SORT, locale));
                        }
                    }
                }
            }

            /**
             * Localize the given key for the given {@link Locale} using the {@link #RESOURCE_BUNDLE}.
             *
             * @param key String key
             * @param locale {@link Locale} to localize
             * @return localized value for given key
             */
            private String getLocalizedTitle(String key, Locale locale) {
                return ResourceBundleUtility.getResourceBundleValue(RESOURCE_BUNDLE, key, locale);
            }
        }

        This uses a custom resource bundle utility class -- the localization in there uses the standard ResourceBundle class via a properties file.
        Show
        Tim Stavenger added a comment - I have also found a need for setting the title HTML attribute on the TH tag. For example, <th title="Click to sort column in ascending order">My Column</th>. Using the title attributes gives screen readers the ability to know what clicking the column does. Without it, the link alone doesn't tell you what it does and the background image doesn't have a way to set an alternative text. However, I think a better solution may be to set the title attribute of the anchor tag for the link itself? In the meantime (until this issue is resolved), I've written a workaround that uses a custom table decorator that iterates over all of the header cells and sets the title attribute if it is sortable: /**  * Add the HTML title attribute on the header cells to indicate sorting options.  */ public class SortTitleTableDecorator extends TableDecorator {     private static final String RESOURCE_BUNDLE = "resources";     private static final String TITLE_ATTRIBUTE = "title";     private static final String ASCENDING_SORT = "table.sort.ascending";     private static final String DESCENDING_SORT = "table.sort.descending";     /**      * Initialize the TableTecorator instance.      *      * @param pageContext PageContext      * @param decorated decorated object (usually a list)      * @param tableModel table model      *      * @see org.displaytag.decorator.Decorator#init(javax.servlet.jsp.PageContext, java.lang.Object,      * org.displaytag.model.TableModel)      */     @Override     public void init(PageContext pageContext, Object decorated, TableModel tableModel) {         setHeaderSortTitles(tableModel, pageContext.getRequest().getLocale());         super.init(pageContext, decorated, tableModel);     }     /**      * Set the HTML title attribute on the header cells to indicate sorting options.      *      * @param tableModel TableModel with header cells      * @param locale Locale to localize HTML title attribute      */     private void setHeaderSortTitles(TableModel tableModel, Locale locale) {         List<HeaderCell> headerCells = tableModel.getHeaderCellList();         for (HeaderCell headerCell : headerCells) {             if (headerCell.getSortable()) {                 if (headerCell.isAlreadySorted() && tableModel.isSortOrderAscending()) {                     headerCell.getHeaderAttributes().put(TITLE_ATTRIBUTE, getLocalizedTitle(DESCENDING_SORT, locale));                 }                 else {                     headerCell.getHeaderAttributes().put(TITLE_ATTRIBUTE, getLocalizedTitle(ASCENDING_SORT, locale));                 }             }         }     }     /**      * Localize the given key for the given {@link Locale} using the {@link #RESOURCE_BUNDLE}.      *      * @param key String key      * @param locale {@link Locale} to localize      * @return localized value for given key      */     private String getLocalizedTitle(String key, Locale locale) {         return ResourceBundleUtility.getResourceBundleValue(RESOURCE_BUNDLE, key, locale);     } } This uses a custom resource bundle utility class -- the localization in there uses the standard ResourceBundle class via a properties file.

          People

          • Reporter:
            fabrizio giustina
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: