Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 54176 invoked from network); 1 May 2004 01:26:49 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 1 May 2004 01:26:49 -0000 Received: (qmail 51295 invoked by uid 500); 1 May 2004 01:26:14 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 51281 invoked by uid 500); 1 May 2004 01:26:14 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 51265 invoked from network); 1 May 2004 01:26:14 -0000 Received: from unknown (HELO web12506.mail.yahoo.com) (216.136.173.198) by daedalus.apache.org with SMTP; 1 May 2004 01:26:14 -0000 Message-ID: <20040501012623.97391.qmail@web12506.mail.yahoo.com> Received: from [64.32.67.172] by web12506.mail.yahoo.com via HTTP; Fri, 30 Apr 2004 20:26:23 CDT Date: Fri, 30 Apr 2004 20:26:23 -0500 (CDT) From: "=?iso-8859-1?q?Domingo=20A.=20Rodriguez=20S.?=" Subject: Re: Array (or List, or Map) Validation To: Struts Users Mailing List In-Reply-To: <00b701c42f0d$36566b10$c1a92b52@DELL1800> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N my problem.. I have a list-backed actionform... That list can have more than one locationObject javabean... The locationObject javabean has some fields, including an errorFormat field.. That errorFormat field can be set using a mutator method from the javabean called setErrorFormat("BACKGROUND:#000000;COLOR:#FFFFFF;").. I am not using the validate method of the actionForm.. my solution.. from inside an Action I do the following.. LocationObjectForm lof= (LocationObjectForm)form; LDHelper ldh= LDHelper(); LocationObject lob= new LocationObject(); List locations= lof.getLocations(); Iterator cnt= locations.iterator(); boolean isDirty= false; while(cnt.hasNext()){ lob= (LocationObject)cnt.next(); if(!ldh.validateRecord(lob.getCompareField1, lob.getCompareField2)){ // if the record is not correct, // then i set the errorformat css style lob.setErrorFormat("BACKGROUND:#000000;COLOR:#FFFFFF;"); isDirty= true; }else{ // i dont want any error format for good records.. lob.setErrorFormat(""); } // put the checked list back to the session req.getSession().setAttribute("locations", locations); if(isDirty){ // forwarded to the same page or tile definition.. // just to refresh and show the error style where needed.. return map.findForward("refreshThisDefinition"); } // if there is no problem then jump to the next definition or page.. return map.findForward("nextDefinition"); } then.. in the page where i display the records.. <% List locations= locationform.getLocations(); LocationObject lob= locations.get( cnt.intValue() ); String estilo= lob.getErrorFormat(); %>
Using this I accomplished one of my latest tasks.. :) I highlight the incorrect records, so the users will see their errors easier. Atte. Domingo A. Rodriguez S. --- Niall Pemberton escribi�: > To make this kind of feature useful there needs to be some way of > indicating > which occurance of the "indexed" property is in error. So, for example, > if > you had a bunch of "order" beans and were validating the order value I > would > want to be able to output a message along the lines of... > > "Order value for order number 12345 is invalid" > or > "Order value on line 5 is invalid" > > ... where order number or line number are other properties from the bean > being validated. Otherwise if you had 20 errors on order value then you > just > get 20 indetical messages along the lines of "Order value is invalid" - > which isn't very useful. > > I looked at trying to do this in the current validator but can't see how > to - have a missed something or am I right and its not possible? > > This is an issue for me with the existing functionality where it stops > on > the first indexed field in error - we got round it by outputing a > message > which doesn't indicate which indexed occurance is in error, but by > highlighting the field in error, which works reasonably well. > > That also would be another type of solution, validate all the indexed > properties, only show one generic message but highlight all the fields > in > error. > > I'd be happy if someone would either put me right on this, or say how > they > dealt with this scenario. > > Niall > > > ----- Original Message ----- > From: "Robert Leland" > To: "Struts Users Mailing List" > Sent: Friday, April 30, 2004 1:12 AM > Subject: Re: Array Validation > > > > > -----Original Message Slightly rearranged ----- > > > From: Glenn, Scott [mailto:Scott.Glenn@umusic.com] > > > > > > If there are any Struts developers listening can you explain this .. > is > it a > > > bug or by design? > > > > Doesn't matter. What matters is that it's not the behavior you need > right > ? > > If someone would like to develop and test a patch that adds an option > to: > > A) The XML element in the struts-config.xml > > This would change the default behavior to not stop validating on > an > > error for a given module. > > or > > B) The Validator.xml itself, which would require a change to the > > validator.dtd, either to: > > B1) The form definition, so the behavior could be changed on a > > per form basis. > > The Option (whenInvalid ? ) would probably have four possible > > values. [stop, inherit, all]. > > stop = This is the current default behavior > > go = This is the behavior you want, where it doesn't > stop > > at the first error but attempts to validate all > data. > > inherit = This would inherit the behavior from the parent > form. > > This assumes using Validator 1.2 which has a > > validator form inheritance. > > module = Defers to what the modules default behavior is, > > assuming that option A) is also implemented. > > or > > B2) The validator definition itself so it could be changed on a > > per type basis. > > > > > > Of these A) Is the simplest and hence the fastest to develop and hence > test. > > Because it?s the fastest it?s more likely to be in the > > 1.2.1 release because. > > > > > > Long term Option B1) probably makes the most sense, but since it > > requires a change to the commons Validator DTD, it won't make it > into > > Struts 1.2.1 since that will be using validator 1.1.3 which will be > > released this weekend. > > > > The patch should include a unit test showing that the default > behaviour > > in the same as in Struts 1.1, along with tests for each option. > > > > > > > > > Thanks, > > > > > > Scott. > > > > > > > > > > > > > > > FYI: Looks like this is a bug/feature of Struts validation. If you > have > a > > > List of indexed properties, it stops validating them once it has > discovered > > > the first error. > > > > > > The code below is from the Validator class - it loops around all > indexed > > > fields (indexedList), calling the appropriate validate rule > > > (validateFieldForRule()). However if this validate rule return > false > into > > > the "good" variable, then the method exits without completing the > loop. > > > > > > for (int pos = 0; pos < indexedList.length; pos++) > > > { > > > ValidatorResults results = new ValidatorResults(); > > > StringTokenizer st = new StringTokenizer(field.getDepends(), > ","); > > > while (st.hasMoreTokens()) { > > > String depend = st.nextToken().trim(); > > > ValidatorAction action = (ValidatorAction) > actions.get(depend); > > > if (action == null) { > > > log.error("No ValidatorAction called " > > > + depend > > > + " found for field " > > > + field.getProperty()); > > > return; > > > } > > > > > > boolean good = validateFieldForRule(field, action, results, > actions, > > > pos); > > > allResults.merge(results); > > > if (!good) > > > { > > > return; > > > } > > > } > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > > For additional commands, e-mail: user-help@struts.apache.org > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > For additional commands, e-mail: user-help@struts.apache.org > _________________________________________________________ Do You Yahoo!? Informaci�n de Estados Unidos y Am�rica Latina, en Yahoo! Noticias. Vis�tanos en http://noticias.espanol.yahoo.com --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org