• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 510
  • Last Modified:

Struts Validation not working - Getting exception thrown

Hi Experts,

Currently I'm working on a Struts Project which requires that I enter two dates : "fromdate" and "todate" values into text boxes in an html:form tag. The Action Form looks like this :

package com.telus.insight.agent.forms;

import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.validator.ValidatorActionForm;
import org.apache.struts.action.ActionMapping;

public class DatePPOFilterForm extends ValidatorActionForm {

      
      private String period = null;
      private String fromdate = null;
      private String todate = null;
      private String defaultFromDate = null;
      private String defaultToDate = null;
      
      
      public void setPeriod(String period){
            this.period = period;
      }
      
      public String getPeriod(){
            return period;
      }
      
      public void setFromdate(String from){
            this.fromdate = from;
      }
      
      public String getFromdate(){
            return fromdate;
      }
      
      public void setTodate(String to){
            this.todate = to;
      }
      
      public String getTodate(){
            return todate;
      }
      
      public void setDefaultFromDate(String date){
            this.defaultFromDate = date;
      }
      
      public String getDefaultFromDate(){
            return defaultFromDate;
      }
      
      public void setDefaultToDate(String date){
            this.defaultToDate = date;
      }
      
      public String getDefaultToDate(){
            return defaultToDate;
      }
}

I've defined validation for the specific action using this validation in the validation.xml file. This is what it looks like :

form-validation>
 <global/>
       <formset>
             <constant>
                   <constant-name>dateFormat</constant-name>
                   <constant-value>yyyy-MM-dd</constant-value>
            </constant>
              <form name="/agentdatefilter">
               <field property="fromdate" depends="date">
                      <var>
                       <var-name>datePatternStrict</var-name>
                       <var-value>${dateFormat}</var-value>
                      </var>
               </field>
               <field property="todate" depends="date" >
                      <var>
                       <var-name>datePatternStrict</var-name>
                       <var-value>${dateFormat}</var-value>
                      </var>
               </field>
              </form>
      </formset>
</form-validation>

The jsp which using this validation for some reason won't output the error messages. When I click the submit button, I'm getting an exception which makes sense because when I put in an invalid date, the next Action shouldnt be called in the first place. The Validation error should be outputted to the screen. This is not happening. On submitting the form, it appears that Struts is attempting to send the invalid info onwards. What am I doing wrong ?

NB. I've included the plugin in the Struts-config.xml file.

Your help would be appreciated !!!

Pia

0
piampri
Asked:
piampri
1 Solution
 
anumalasCommented:
Hi

In your jsp file include the following lines at approprite places and try once again

<%@ taglib uri="/tags/struts-html" prefix="html" %>


<html:form action="/YourValiditonAction" method="post" onsubmit="return validatorActionForm(this);">


<html:javascript formName="ValidatorActionForm"/>

In your struts-config.xml this particular mapping will look like bellow:

<action
     path="/YourValidationAction"
     type="com.telus.insight.agent.actions.YourValidationAction"
     name="ValidatorActionForm"
     scope="request"
     validate="true"
     input="/jsp/yourjsp.jsp">
     <forward name="success" path="/jsp/success.jsp"/>
     <forward name-"failure" path="/jsp/yourjsp.jsp"/>
</action>

The main porblem is while mapping your jsp  with action your doing small mistake to invoke validator frame work.

For further reference please go thru URL @   http://www.roseindia.net/struts/address_struts_validator.shtml   its a nice one

Hope this will help :)
0
 
piampriAuthor Commented:
Thanks Anumalas,

Your suggestion worked. I guess I was skipping a few steps.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now