Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Struts Validation not working  - Getting exception thrown

Posted on 2006-06-18
4
482 Views
Last Modified: 2013-12-10
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
Comment
Question by:piampri
4 Comments
 
LVL 3

Accepted Solution

by:
anumalas earned 500 total points
ID: 17057551
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
 

Author Comment

by:piampri
ID: 17132040
Thanks Anumalas,

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

-Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question