commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Graham <grahamdavid1...@yahoo.com>
Subject Re: Validator Exception
Date Tue, 11 Nov 2003 17:02:18 GMT
Comment out all of your validation code except for the call to
super.validate().  If the exception is not thrown the error is in your
code.  If it's still throwing the exception, comment out all of your xml
rules for the form and test one of them at a time until you find the rule
that is throwing the exception.

David

--- Srinivas Gunturu <sxg1127@bjc.org> wrote:
> Here is the validate code.  I am not event seeing "Validate 1" in my
> console output as is the first line in my validate method.  Makes me
> think, my validation rules xml might be throwing this exception.  I have
> enclosed my validation rules too.
> 
>     public ActionErrors validate(ActionMapping mapping,
>                                  HttpServletRequest request) {
> 
> 
> //		if (Constants.CLEAR.equals(request.getParameter("submitField")))
> return new ActionErrors();
> 		
> 		System.out.println("Validate 1");
> 		HttpSession session = request.getSession();
> 		SafetyEvent safetyEvent = ((SafetyEvent)
> session.getAttribute(Constants.EVENT_BEAN_KEY));
> 		
> 		
>         // Perform validator framework validations
>         ActionErrors errors = super.validate(mapping, request);
> 		System.out.println("Validate 1.1");
> 
> 		if ( safetyEvent == null || 
> 				safetyEvent.getSafetyEventID() == null ||
> 				safetyEvent.getSafetyEventID().intValue() <= 0 ) {
> 			if ( getEventDetailBean().getSourceCode() != null &&
> 					("141".equals(getEventDetailBean().getSourceCode().toString()) ||
> 					 "1337".equals(getEventDetailBean().getSourceCode().toString())) )
> {
> 				errors.add(ActionErrors.GLOBAL_ERROR, new
> ActionError("error.eventdetail.invalidSource"));				
> 			}
> 		}
> 		System.out.println("Validate 2");
> 		//Determine if eventDateTime is greater than reportedDateTime.
> 		String eventDateTime = null;
> 		if (eventDetailBean.getEventDate() != null)
> 		{
> 			eventDateTime = eventDetailBean.getEventDate();
> 			if (GenericValidator.isBlankOrNull(eventDetailBean.getHour()))
> 			{
> 				eventDateTime += " 00";
> 			} else {
> 				eventDateTime += " " + eventDetailBean.getHour();
> 			}
> 			if (GenericValidator.isBlankOrNull(eventDetailBean.getMin()))
> 			{
> 				eventDateTime += ":00";
> 			}
> 			else
> 			{
> 				eventDateTime += ":" + eventDetailBean.getMin();
> 			}
> 		}
> 
> 		System.out.println("Validate 3");
> 		if (! GenericValidator.isBlankOrNull(eventDateTime) &&
> GenericValidator.isDate(eventDateTime,"MM/dd/yyyy HH:mm",true))
> 		{
> 			String inputFormat = "MM/dd/yyyy HH:mm";
> 			SimpleDateFormat inputDateFormat = new SimpleDateFormat(inputFormat);
> 			try {
> 				Date eventDate = inputDateFormat.parse(eventDateTime);
> 				Date currentDate = new Date();
> 
> 				if ((eventDetailBean.getReportedDateTime() == null &&
> eventDate.after(currentDate)) ||
> 					 (eventDetailBean.getReportedDateTime() != null &&
> eventDate.after(eventDetailBean.getReportedDateTime()))) {
> 						errors.add(ActionErrors.GLOBAL_ERROR, new
> ActionError("error.eventdetail.eventDateLaterThanReportedDate", "Event
> Date"));
> 				}
> 			} catch (ParseException e) {
> 			}
> 			
> 		System.out.println("Validate 4");
> 			
> 		}
> 		
> 	    return errors;
>     }
> 
> 
> Validation.xml
> 
> 		<form name="eventDetailForm">
> 			<field property="eventDetailBean.facility" depends="required">
> 				<arg0 key="prompt.facility" />
> 			</field>
> 			<field property="eventDetailBean.eventLoc" depends="required">
> 				<arg0 key="prompt.eventLocation" />
> 			</field>
> 			<field property="eventDetailBean.eventType" depends="required">
> 				<arg0 key="prompt.eventType" />
> 			</field>
> 			<field property="eventDetailBean.eventDate" depends="required,date">
> 				<arg0 key="prompt.eventDate" />
> 				<var>
> 					<var-name>datePatternStrict</var-name>
> 					<var-value>MM/dd/yyyy</var-value>
> 				</var>
> 			</field>
> 			<field property="eventDetailBean.hour" depends="required,integer">
> 				<arg0 key="prompt.eventTimeHour" />
> 			</field>
> 			<field property="eventDetailBean.min" depends="required,integer">
> 				<arg0 key="prompt.eventTimeMinute" />
> 			</field>
> 			<field property="eventDetailBean.harmEventOccurrence"
> depends="required">
> 				<arg0 key="prompt.describeEvent" />
> 			</field>
> 		</form>
> 
> 
> >>> grahamdavid1980@yahoo.com 11/11/03 10:34AM >>>
> 
> --- Srinivas Gunturu <sxg1127@bjc.org> wrote:
> > Thanks for the response.  I was trying to avoid explain what I was
> > doing.  I will try to be short.
> > 
> > We are migrating a legacy system to an intranet website in a phased
> out
> > manner.  While some users use the legacy system to enter data, some
> will
> > be using online system.  Legacy system is very lenient as far as data
> > validation goes.  We have a nightly batch process that transfers data
> > from legacy system to the new intranet system.  
> > 
> > The data is entered using a wizard flow and consists of 6-10 screens. 
> > At the end user has a summary/review screen before data is persisted. 
> > We have reviewers reviewing data coming from legacy system and fix it.
> 
> > When a reviewer opens legacy data on the intranet, we take them
> directly
> > to summary page.  On summary page, we would like to validate all
> legacy
> > data and display visual indicators for each form that fails
> validation.
> > 
> > Instead of re-writig the validation, I am trying to invoke validator
> > with in my action class by passing one form at a time to validate.  I
> am
> > only at the begining and have 15+forms to go.
> > 
> > Now to answer your question, No, my validate method does not throw an
> > exception.
> > 
> > I can include my validate code if needed.
> 
> Please send the validate method that causes the exception.  Try putting
> a
> try...catch (Exception e) block around all of the code in your
> validation
> method and print out any exception that occurs.  Your method may be
> throwing a RuntimeException that you're not seeing.
> 
> David
> 
> > 
> > >>> grahamdavid1980@yahoo.com 11/11/03 10:18AM >>>
> > 
> > --- Srinivas Gunturu <sxg1127@bjc.org> wrote:
> > > Hi All,
> > > 
> > > I am using commons validator and struts.  The validation works fine
> > > within struts.  However, I have a business need to re-use validation
> > > outside struts.  I am trying to invoke validator with following
> code. 
> > > However, I am getting an exception.  Any idea what might be the
> > reason?
> > > 
> > 
> > The stack trace indicates you're running this from Struts but you say
> > that
> > it works fine from Struts?  InvocationTargetException is thrown when a
> > dynamically called method throws an exception.  Does your validation
> > method throw an exception?
> > 
> > David
> > 
> > > Thanks in advance.
> > > 
> > > Srinivas
> > > 
> > > Here is my code
> > > ------------------------------------------------------------
> > > ValidatorResources resources = new ValidatorResources();
> > > 			
> > > InputStream rules =
> > >
> >
>
getServlet().getServletContext().getResourceAsStream("/WEB-INF/validator-rules.xml");
> > > 			
> > > ValidatorResourcesInitializer.initialize(resources, rules);
> > > 			
> > > InputStream forms =
> > >
> >
>
getServlet().getServletContext().getResourceAsStream("/WEB-INF/validation.xml");
> 
=== message truncated ===


__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message