commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Srinivas Gunturu" <sxg1...@bjc.org>
Subject Re: Validator Exception
Date Tue, 11 Nov 2003 16:44:16 GMT
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");
> > 			
> > ValidatorResourcesInitializer.initialize(resources, forms);
> > 			
> > InputStream formsTwo =
> >
>
getServlet().getServletContext().getResourceAsStream("/WEB-INF/validation-eventSelection.xml");
> > 			
> > ValidatorResourcesInitializer.initialize(resources, formsTwo);
> > 			
> > Validator validator = new Validator(resources, "eventDetailForm");
> > EventDetailForm form = new EventDetailForm();
> > form.setEventDetailBean(event.getSafetyEventDetailBean());
> > form.setAction(Constants.EDIT);
> > form.setFormName(Navigator.MED_EVENT_DETAIL);
> > validator.addResource(Validator.BEAN_KEY, form);
> > ValidatorResults results = validator.validate();
> > 
> > ---------------------------END OF CODE-------------------------------
> > 
> > Here is the exception 
> > 
> > ---------------------------------------------
> > Nov 11, 2003 9:59:11 AM org.apache.commons.validator.Validator
> > validateFieldForR
> > ule
> > SEVERE: reflection: null
> > java.lang.reflect.InvocationTargetException
> >         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >         at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
> > java:39)
> >         at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
> > sorImpl.java:25)
> >         at java.lang.reflect.Method.invoke(Method.java:324)
> >         at
> > org.apache.commons.validator.Validator.validateFieldForRule(Validator
> > .java:454)
> >         at
> > org.apache.commons.validator.Validator.validateField(Validator.java:5
> > 44)
> >         at
> > org.apache.commons.validator.Validator.validate(Validator.java:582)
> >         at org.bjc.ses.action.ShowEventAction.execute(Unknown Source)
> >         at
> > org.apache.struts.action.RequestProcessor.processActionPerform(Reques
> > tProcessor.java:484)
> >         at
> > org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
> > va:274)
> >         at
> > org.apache.struts.action.ActionServlet.process(ActionServlet.java:148
> > 2)
> >         at
> > org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
> >         at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
> >         at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> >         at
> > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
> > icationFilterChain.java:247)
> >         at
> > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
> > ilterChain.java:193)
> >         at
> > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
> > alve.java:260)
> >         at
> > org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
> > t.invokeNext(StandardPipeline.java:643)
> >         at
> > org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
> > a:480)
> >         at
> > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
> > 
> >         at
> > org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
> > alve.java:191)
> >         at
> > org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
> > t.invokeNext(StandardPipeline.java:643)
> >         at
> > org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
> > a:480)
> >         at
> > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
> > 
> >         at
> > org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
> > 2396)
> >         at
> > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
> > ava:180)
> >         at
> > org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
> > t.invokeNext(StandardPipeline.java:643)
> >         at
> > org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
> > rValve.java:170)
> >         at
> > org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
> > t.invokeNext(StandardPipeline.java:641)
> >         at
> > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
> > ava:172)
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org 
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org 
> > 
> 
> 
> __________________________________
> 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 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org 
> For additional commands, e-mail: commons-user-help@jakarta.apache.org 
> 


__________________________________
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 




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