[ 
http://jira.codehaus.org/browse/DISPL-34?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=138026#action_138026
 ] 

Tim Stavenger commented on DISPL-34:
------------------------------------

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 [EMAIL PROTECTED] Locale} using the 
[EMAIL PROTECTED] #RESOURCE_BUNDLE}.
     * 
     * @param key String key
     * @param locale [EMAIL PROTECTED] 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.

> title attribute in TH tag
> -------------------------
>
>                 Key: DISPL-34
>                 URL: http://jira.codehaus.org/browse/DISPL-34
>             Project: DisplayTag
>          Issue Type: New Feature
>          Components: Tag Library
>    Affects Versions: 1.0 RC1
>            Reporter: fabrizio giustina
>            Priority: Minor
>             Fix For: TBD
>
>         Attachments: changes-to-1.0rc2.zip
>
>
> ====
> 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

-- 
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

        

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
displaytag-devel mailing list
displaytag-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-devel

Reply via email to