Issue Details (XML | Word | Printable)

Key: STR-1728
Type: Improvement Improvement
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
Reporter: Quande Ren
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Struts 1

ActionMessages.getSortedProperties() needed

Created: 04/Sep/03 03:22 AM   Updated: 26/Nov/06 06:16 AM
Return to search
Component/s: Core, Tag Libraries
Affects Version/s: 1.1.0
Fix Version/s: None

Environment:
Operating System: other
Platform: Other

Bugzilla Id: 22912


 Description  « Hide
The <html:errors/> tag will output the standard error information, the error
order is defined by the order of properties in the validation.xml.

However, the <html:errors/> is not smart enough. I want to have my own error
output tag like <mytag:errors/>. I still want to keep the same order for the
properties. but the ActionMessages.properties() returns unsorted properties.
there's no way to get the sorted properties.

I suggest that we add another method called ActionMessages.getSortedProperties
(), the code can be like this:

  public Iterator getSortedProperties()
  {
    if(this.messages.isEmpty())
        return Collections.EMPTY_LIST.iterator();
      ArrayList keys = new ArrayList();

      for(Iterator i = this.messages.keySet().iterator(); i.hasNext(); ){
        keys.add(i.next());
      }

      Collections.sort(keys,new Comparator() {

        public int compare(Object o1, Object o2) {
          ActionMessageItem v1=(ActionMessageItem)messages.get(o1);
          ActionMessageItem v2=(ActionMessageItem)messages.get(o2);
          return v1.getOrder()-v2.getOrder();
        }

      });


      return keys.iterator();
  }

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
David Graham added a comment - 22/Sep/03 08:06 AM
I don't think adding this method to ActionMessages is appropriate. Users of
ActionMessages (ie. <html:errors/>) should probably do the sorting instead.

Quande Ren added a comment - 22/Sep/03 08:38 PM
<html:errors/> only provide standard behaviour, I want to have a customized
error message to generate html like this:

============================================================
Validation Error:
<ul>
   <li> <a href="#section_1">Section 1</a>, Last Name is needed.</li>
</ul>
============================================================
If the content in one web page is very large, this kinds of error message
displaying enables user to be able to click the error message, and go to
appropriate section of the page.

I'm sure some other people want to have their own customized error message
displaying. then the ActionMessages.getSortedProperties() will be very
important.