Hi, Thanks for your feedback, but according to the struts source code below it seems the items are sorted in their initial order. I tested the code (in its scriptlet format) and it seemed to be working OK, that is the order as defined in the validations.xml Can you please show me where the problem is (if you have the time)? i.e. ActionMessages.java ... public Iterator properties() { if (messages.isEmpty()) { return Collections.EMPTY_LIST.iterator(); } ArrayList results = new ArrayList(); ArrayList actionItems = new ArrayList(); for (Iterator i = messages.values().iterator(); i.hasNext();) { actionItems.add(i.next()); } // Sort ActionMessageItems based on the initial order the // property/key was added to ActionMessages. Collections.sort(actionItems, actionItemComparator); for (Iterator i = actionItems.iterator(); i.hasNext();) { ActionMessageItem ami = (ActionMessageItem) i.next(); results.add(ami.getProperty()); } return results.iterator(); }
________________________________ From: Angelo zerr [mailto:[EMAIL PROTECTED] Sent: Tue 12/09/2006 5:43 PM To: Struts Users Mailing List Subject: Re: FW: focus on first error Hello, I was need to manage focus on the first field with error. With your solution, the problem is errors collection is sorted, so your focus will not go to the first field with error in your JSP. So I extends doErrorExist of TextTag to manage it, like this : protected boolean doErrorsExist() throws JspException { boolean errorExist = super.doErrorsExist(); ServletRequest request = pageContext.getRequest(); if (errorExist && request.getAttribute("FIRST_FIELD_WITH_ERROR" ) == null) { request.setAttribute("FIRST_FIELD_WITH_ERROR" , super.getPropertyExpr()); } return errorExist; } So if field has error, request will be updated. After at end of your JSP, you write call function Javascript, like this <c:if test="${requestScope.FIRST_FIELD_WITH_ERROR != null}" > setFocusToField('<c:out value="${requestScope.FIRST_FIELD_WITH_ERROR}" />'); <c:if> Here jaavscript function : function setFocusToField(fieldName, fieldIndex) { if (fieldIndex == null || fieldIndex.length < 1) fieldIndex = 0; var listElementHTML = document.getElementsByName(fieldName); if (listElementHTML != null && listElementHTML.length > 0) { var elementHTML = listElementHTML[fieldIndex]; if (elementHTML.disabled == false) { /*if (elementHTML.type == "text") elementHTML.select(); else */ elementHTML.focus(); } } } Regards Angelo 2006/9/12, Strachan, Paul <[EMAIL PROTECTED]>: > > > maybe we could do something like this in the JSP - the idea is taken > from the TextTag.java which knows to use the errorStyleClass when theres > an error. > > ... > <%@ page import="java.util.Iterator" %> > <%@ page import="org.apache.struts.Globals" %> > <%@ page import="org.apache.struts.taglib.TagUtils" %> > <%@ page import="org.apache.struts.action.ActionMessages" %> > > <% > String errorKey = Globals.ERROR_KEY; > ActionMessages errors = TagUtils.getInstance() > .getActionMessages(pageContext, errorKey); > > Iterator iter = errors.properties(); > String focusProperty = "some_default_property"; > > if (iter.hasNext()) { > focusProperty = (String) iter.next(); // default to first property > } %> > > <html:form focus="<%= focusProperty %>" action="/someAction.do" > method="post"> ... > </html:form> > > > Notes: > > 1. The default_property is the field you would normally focus on if > there is no error. > > 2. It would be best to put this code in a tag library. > > 3. The javascript generated by the struts "focus" attribute may need to > be improved (e.g. in a try...catch) just in case a property doesnt > exist. > > > Please let me know how this approach looks as I am also considering this > for my app. > > Thanks, > > Paul > ********************************************************************** > This message is intended for the addressee named and may contain > privileged information or confidential information or both. If you > are not the intended recipient please delete it and notify the sender. > ********************************************************************** > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > ********************************************************************** This message is intended for the addressee named and may contain privileged information or confidential information or both. If you are not the intended recipient please delete it and notify the sender. ********************************************************************** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]