Related to struts validation form

Hi all,
When entering validations on a form in validation.xml, If you have a
fieldA with "depends=required,maxlength" and FieldB with "depends=required,email".
If when i give fieldA with 40characters but its permitted length is 20 and FieldB is empty. Now when i click submit button it shows the error only for fieldB.
When i give a correct email id in fieldB then FieldA error for max length is triggered..
Is there a way for both to appear at the same time when the
Submit button is first clicked?

You may have more luck if you ask this in a forum devoted to Struts. There's one at their own homepage over there at apache.org.

Similar Messages

  • Struts Validator Form

    Hi,
    I have an application J2EE Struts that receives data via a http call and url parameters from another system.
    Example url calling my system is:
    http://<server ip>:<server port>/application/actionName.do?custName=LADY%20TESTINA%20TEST&custNo=01512865900&custAdd=45%20Test%20Street%20Testville%20%20%20%20%20%20&notes=this%20is%20a%20'test'%20ok%20try%20& quot;this& quot;%20as%20well
    I've having problems when the url contains encoded charachters such as & quot; at the point the form bean is created for the above I've printed out the bean contents for the "notes" value and I'm getting: this is a 'test' ok try
    Which means that anything after the & quot; isn't being added to the bean value, I guess this is because of the & characheter when the url is parsed it's splitting the values thinking that there's another parameter?
    Note the & quot; above shouldn't have a space in it.
    What is the best way to handle this?
    Thanks.
    Edited by: user618008 on 22-Feb-2011 03:59
    Edited by: user618008 on 22-Feb-2011 04:00

    public void parseSwfURL(String testURL) {
                   String subURL = null;
                   if(testURL!=null){
                        String[] splitedURL = testURL.split("\\?");
                        if(splitedURL.length >=2){
                        parameterBean.setObjectName(splitedURL[0]);
                        subURL = splitedURL[1];
                   populateParameterBean(subURL, parameterBean);
    private void populateParameterBean(String subURL1) {
              if(subURL1!=null) {
                   String[] subURL = subURL1.split("\\&");
                   String item = null;
                   String[] itemPair = null;
                   String itemValue = null;
                   for (int i = 0; i < subURL.length; i++) {
                        item = subURL;
                        itemPair = item.split("\\=");
                        if(itemPair.length == 2){
                             itemValue = itemPair[1];
                        else{
                             itemValue = "";
                        String type = itemPair[0];
                        if(type.equalsIgnoreCase("<<your parameters>>")){
    //set your action bean here

  • How to use the validation.xml in struts validation?

    Can any one please help me, how to use the validation.xml in struts validation? possible please give me simple example.
    Edited by: SathishkumarAyyavoo on Jan 31, 2009 12:03 PM

    These 2 are the good articles for the beginners to do validation things in Struts. you can follow any one of them.
    1. [http://viralpatel.net/blogs/2009/01/struts-validation-framework-tutorial-example-validator-struts-validation-form-validation.html]
    2. [http://www.vaannila.com/struts/struts-example/struts-custom-validation-example-1.html]
    All the best.

  • Inconsistent Form Behavior on Failed Struts Validation

    So I'm working on a strange bug regarding an Edit User form for an application, where some fields revert to their default and some fields do not.
    We have a form for editing users in our system, with most of the usual information inputted in text boxes (login, first name, last name, password, password confirmation). We also have three possible levels of 'admin' - none, admin, and superadmin. These are chosen via radio buttons. There are also a couple of checkboxes (like 'user is active'). Overall, it's a fairly simple form.
    When the form is submitted, we do struts validation. We've set up the validation via comment annotation in our Java code, like so:
         * @struts.validator type="minlength"
         *                   arg1value="${var:minlength}"
         * @struts.validator-var name="minlength" value="8"
         * @struts.validator type="maxlength"
         *                   arg2value="${var:maxlength}"
         * @struts.validator-var name="maxlength" value="50"
        public void setPassword1(String string) {
            password1 = string;
        }All of the fields in our form are set from user properties, so they're initialized by the values in the user object. For example, if we had user John Smith, an admin, with login 'jsmith,' we'd have the first name and last name fields initialized to John and Smith, and the radio buttons for Admin set to 'admin.' For reference, here's the EditUser.jsp code for the radio buttons, based off of the selectedAdminRole property:
    <div class="InputElement">
            <label for="selectedAdminRole"><bean:message key="userForm.adminType"/></label>
              <html:radio styleId="selectedAdminRole" property="selectedAdminRole" value="None"
                          disabled="${userForm.loggedInUser.admin and userForm.userId == userForm.loggedInUser.id}">None</html:radio>
              <html:radio property="selectedAdminRole" value="Admin"
                          disabled="${userForm.loggedInUser.admin and userForm.userId == userForm.loggedInUser.id}">Admin</html:radio>
              <c:if test="${userForm.loggedInUser.superAdmin}">
                  <html:radio property="selectedAdminRole" value="SuperAdmin">Super</html:radio>
              </c:if>
         </div>As you can see above, the struts validator requires passwords to be at least 8 characters long. So if the user tries to change their password to something with less than that, they'll fail validation and they'll end up back on the form with the validation errors in red at the top of the page. However, the form data that they've edited will be preserved. So if John had tried to change his first name to 'Fred,' he'd still see 'Fred' in the First Name text field, even though it wouldn't actually get saved to the user object until he submitted the form with no errors. This works with radio buttons too - if John had tried to set his admin status down to 'none' from 'admin,' the radio button 'none' would still be checked. Basically, it preserves all your progress on the form until you navigate away.
    Unfortunately, it does NOT do this when you create a new user. Creating a new user uses the same form, and since there's no user object to get the fields from, they all get initialized to blank - except for one of the checkboxes ('user is active') and the radio buttons for admin (starts with 'none' checked). Now, if the user fills out the form and hits submit, but fails the struts validation, it preserves all the form data in the text fields, but reverts the checkboxes and the radio buttons to their default state.
    This leads to the following problem: say I'm trying to create a new admin, Jane Smith. I fill out the whole form, check the 'admin' button, and then enter a four-letter password. I submit, and the form fails struts validation and throws me back to the page with an error message informing me that passwords need to be at least 8 characters. I look over the form again - the login field is still 'janesmith,' the first name field is still 'Jane,' the last name field is still 'Smith,' everything looks fine except I screwed up the password. I enter an 8 letter password and resubmit. Jane then logs in and complains that she's not an admin, because I didn't notice that the 'admin' button had reset itself to the default of 'none' when I failed validation.
    My question is, why does it reset the radio buttons and checkboxes - but not the text fields - on failed validation when a new user is being created, but resets nothing at all when an existing user is being edited? I'd like it to reset none of the information when a new user is being created, but I cannot figure out the reason for this inconsistent behavior.
    If anyone can help me figure out how to get this working so that nothing gets reset - or at least explain to me the reason for this inconsistent behavior - I would be very grateful. I will also try to provide any additional information I can if this isn't enough.

    So what you are saying is that radio and checkboxes don't retain their state when validation fails?
    Checkboxes are always troublesome because of their design. If not selected, they don't submit any value - so you have to specifically unset them.
    My first instinct would be to look at the formbean which you are populating from, and see what (if anything) modifies its values.
    - for originally loading the new user page is it an action or JSP? Does it apply any default values to the form?
    - check the "input" page you redirect to when validation fails. Is it an action or a JSP?
    - is the same form being uses on the newUser jsp and whatever action you are submitting it to?
    - is there a form reset() method?
    My theory is that the "input" page you are redirecting to when validation fails is an action, and it sets some values on the form prior to loading.
    But thats just a guess at this point. Its hard to debug this without a working example. Its been a while since I worked with struts, and never with annotations providing the validation.
    Suggestion for debugging: dump the contents of the form bean at strategic points in the process to see that the values are what you think they should be.
    - running the save action
    - just after validation
    - on the jsp page.
    Hope this helps some,
    evnafets

  • Validating forms in struts

    Hi
    I'm developing an application using struts and my web server is tomcat 4. i have a add page with different fields. How do i validtate these fields in struts. The following are my entries
    struts-config.xml:
    <action path="/AddOpportunitiesAction"
    type="com.wipro.opportunity.ui.AddOpportunitiesAction"
    name="AddOpportunitiesForm"
    scope="request"
    parameter="action"
         validate="true"
    input="AddOpportunitiesAction">
    <forward name="addOpportunity" path="/addOpportunity.jsp"/>
    <forward name="DisplayOpportunitiesAction" path="/DisplayOpportunitiesAction.do"/>
    <forward name="DisplayAccountAction" path="/DisplayAccountAction.do"/>
    </action>
    i have extended addopportunityForm as ValidatorForm. i have given the rules in vaidator.xml as
    <form name="AddOpportunitiesForm">
    <field property="opportunityName"
    depends="required">
    <arg0 key="addopportunity.name"/>
         </field>
    </form>
    The following entry show the getter setter method in addopportunityForm
    public final class AddOpportunitiesForm extends ValidatorForm{
    private String opportunity_name;
    public void setOpportunityName(String name) {
    this.opportunity_name = name;
    public String getOpportunityName() {
    return this.opportunity_name;
    Note: IN addopportunity.jsp the property of my name field is opporutniyName and not opportunity_name
    addopportunity.jsp
    <td>
                   Opp. Name <font color="red"> * </font>
              </td>
              <td>
                   <html:text name="AddOpportunitiesForm" property="opportunityName"/>
    RESULT: I'm not able to validate the field
    Pls help me out.
    mail me at [email protected]
    Regards
    Rafiq

    Here is my code below.
    my serverside validation is working fine but my client side validation doesnt work.
    Struts config:
    <form-bean name="courseCriteriaForm" type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name="paperId" type="java.lang.Integer"/>
    <form-property name="passingMarks" type="java.lang.Integer"/>
    <form-property name="totalMarks" type="java.lang.Integer"/>
    <form-property name="StudentListmarks" type="org.aptech.lms.common.StudentListMarks[]"/>
    </form-bean>
    <action
    path="/displayCourseDetail"
    name ="courseCriteriaForm"
    scope = "session"
    type="org.aptech.lms.admin.action.DisplayCourseMarksDetailAction"
    validate="false"
    input="/pages/admin/CourseMarksDetail.jsp">
    <forward name="success" path="/pages/admin/CourseMarksDetail.jsp" />
    <forward name="error" path="/pages/admin/CourseMarksDetail.jsp" />
    </action>
    <action
    path="/updateCourseMarks"
    scope = "session"
    name ="courseCriteriaForm"
    type="org.aptech.lms.admin.action.UpdateCourseMarksAction"
    validate="true"
    input="/pages/admin/CourseMarksDetail.jsp">
    <forward name="success" path="/pages/admin/CourseMarksUpdateSuccess.jsp"/>
    <forward name="cancel" path="/showUserRoles.do"/>
    <forward name="error" path="/pages/admin/CourseMarksDetail.jsp"/>
    <forward name="noerror" path="/pages/admin/MarksFail.jsp"/>
    </action>
    MY JSP
    <html:form action="/updateCourseMarks" onsubmit="return validateCourseCriteriaForm(this);" >
    <html:javascript formName="courseCriteriaForm"/>
    <table class="tableborder">
    <tr class="subtablerow2"><td class="boldtext">Total Marks : <bean:write name="courseCriteriaForm" property="totalMarks"/> </td>
    <td class="boldtext">Passing Marks : <bean:write name="courseCriteriaForm"property="passingMarks"/></td>
    </tr>
    </table>
    <table class="tableborder">
    <html:hidden name="courseCriteriaForm" property="totalMarks" />
    <logic:iterate id="StudentListmarks" name="courseCriteriaForm" property="StudentListmarks" >
    <tr>
    <td>
    <bean:write name="StudentListmarks" property="userinfo_id"/>
    </td>
    <td>
    <bean:write name="StudentListmarks" property="firstname"/>
    </td>
    <td>
    <bean:write name="StudentListmarks" property="lastname"/>
    </td>
    <td>
    <c:if test="${StudentListmarks.marks == '-99'}">
    <html:text name="StudentListmarks" property="marks" indexed="true" value="NA" />
    </c:if>
    <c:if test="${StudentListmarks.marks != '-99'}">
    <html:text name="StudentListmarks" property="marks" indexed="true" />
    </c:if>
    </td>
    <td>
    <html:text name="StudentListmarks" property="remarks" indexed="true"/>
    </td>
    </tr>
    </logic:iterate>
    </table>
    <logic:present name="display" scope="session">
    <div align="center"><html:submit styleClass="button"/><html:cancel styleClass="button" /></div>
    </logic:present>
    </html:form>
    MY VALIDATION.XML
    <form name="courseCriteriaForm">
    <field property="marks" indexedListProperty="StudentListmarks" depends="required,mask">
    <arg0 key="errors.marks.required11"/>
    <arg1 key="errors.marks.mask"/>
    <!-- <arg2 key="CourseCriteriaForm.totalMarks" name="totalMarks"/>-->
    <!--<arg3 key="errors.validatemarks" name="validatemarks"/>-->
    <var><var-name>mask</var-name>
    <var-value>^[NA0-9]{2}[a-zA-Z0-9_ ]*$</var-value>
    </var>
    <!--<var>
    <var-name>secondMark</var-name>
    <var-value>totalMarks</var-value>
    </var>-->
    </field>
    <!--<field property="totalMarks" depends="validatemarks"/>-->
    </form>
    could u please tell me why my client side validation doest happen

  • Problem with Struts Validation and apache dtd definition.

    Jakarta Struts
    Java Version 1.5
    We have one web application that is being a little problematic, on startup two errors are thrown relating to the same problem (errors below).
    We get 401 returned for http://jakarta.apache.org/commons/dtds/validator_1_0.dtd
    both the validation.xml and validation-rules.xml have the same doc type set as below:
    <!DOCTYPE form-validation PUBLIC
    "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
    "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
    We have the same configuration set for several other web application deployed succesfuly on the same tomcat application server without any problems. I'm not sure why this one application is causing a problem, I don't see any difference between the validation.xml and validation-rules.xml files in this application to any of the others that have been succesfully deployed, infact the validation-rules.xml is identical for all the web applications hosted on this server.
    Any ideas appreciated
    Error
    2006-03-30 15:04:50,968 ERROR [HttpRequestHandler-169] validator.ValidatorPlugIn (ValidatorPlugIn.java:224) - Server returned HTTP response code: 401 for URL: http://jakarta.apache.org/commons/dtds/validator_1_0.dtd
    java.io.IOException: Server returned HTTP response code: 401 for URL: http://jakarta.apache.org/commons/dtds/validator_1_0.dtd
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:791)
         at java.net.URL.openStream(URL.java)
         at oracle.xml.parser.v2.XMLReader.openURL(XMLReader.java:2292)
         at oracle.xml.parser.v2.XMLReader.pushXMLReader(XMLReader.java:265)
         at oracle.xml.parser.v2.NonValidatingParser.pushExternalDTD(NonValidatingParser.java:540)
         at oracle.xml.parser.v2.NonValidatingParser.parseDoctypeDecl(NonValidatingParser.java:465)
         at oracle.xml.parser.v2.NonValidatingParser.parseProlog(NonValidatingParser.java:298)
         at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:277)
         at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:184)
         at org.apache.commons.digester.Digester.parse(Digester.java:1515)
         at org.apache.commons.validator.ValidatorResourcesInitializer.initialize(Unknown Source)
         at org.apache.struts.validator.ValidatorPlugIn.initResources(ValidatorPlugIn.java:222)
         at org.apache.struts.validator.ValidatorPlugIn.init(ValidatorPlugIn.java:161)
         at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:1158)
         at org.apache.struts.action.ActionServlet.init(ActionServlet.java:473)
         at javax.servlet.GenericServlet.init(GenericServlet.java:259)
         at com.evermind.server.http.HttpApplication.loadServlet(HttpApplication.java:2141)
         at com.evermind.server.http.HttpApplication.findServlet(HttpApplication.java:4582)
         at com.evermind.server.http.HttpApplication.initPreloadServlets(HttpApplication.java:4676)
         at com.evermind.server.http.HttpApplication.initDynamic(HttpApplication.java:820)
         at com.evermind.server.http.HttpApplication.<init>(HttpApplication.java:542)
         at com.evermind.server.Application.getHttpApplication(Application.java:889)
         at com.evermind.server.http.HttpServer.getHttpApplication(HttpServer.java:690)
         at com.evermind.server.http.HttpSite.getApplication(HttpSite.java:420)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:422)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
         at java.lang.Thread.run(Thread.java:534)
    2006-03-30 15:04:50,968 INFO [HttpRequestHandler-169] validator.ValidatorPlugIn (ValidatorPlugIn.java:209) - Loading validation rules file from '/WEB-INF/validation.xml'
    2006-03-30 15:04:50,984 ERROR [HttpRequestHandler-169] validator.ValidatorPlugIn (ValidatorPlugIn.java:224) - Server returned HTTP response code: 401 for URL: http://jakarta.apache.org/commons/dtds/validator_1_0.dtd
    java.io.IOException: Server returned HTTP response code: 401 for URL: http://jakarta.apache.org/commons/dtds/validator_1_0.dtd
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:791)
         at java.net.URL.openStream(URL.java)
         at oracle.xml.parser.v2.XMLReader.openURL(XMLReader.java:2292)
         at oracle.xml.parser.v2.XMLReader.pushXMLReader(XMLReader.java:265)
         at oracle.xml.parser.v2.NonValidatingParser.pushExternalDTD(NonValidatingParser.java:540)
         at oracle.xml.parser.v2.NonValidatingParser.parseDoctypeDecl(NonValidatingParser.java:465)
         at oracle.xml.parser.v2.NonValidatingParser.parseProlog(NonValidatingParser.java:298)
         at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:277)
         at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:184)
         at org.apache.commons.digester.Digester.parse(Digester.java:1515)
         at org.apache.commons.validator.ValidatorResourcesInitializer.initialize(Unknown Source)
         at org.apache.struts.validator.ValidatorPlugIn.initResources(ValidatorPlugIn.java:222)
         at org.apache.struts.validator.ValidatorPlugIn.init(ValidatorPlugIn.java:161)
         at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:1158)
         at org.apache.struts.action.ActionServlet.init(ActionServlet.java:473)
         at javax.servlet.GenericServlet.init(GenericServlet.java:259)
         at com.evermind.server.http.HttpApplication.loadServlet(HttpApplication.java:2141)
         at com.evermind.server.http.HttpApplication.findServlet(HttpApplication.java:4582)
         at com.evermind.server.http.HttpApplication.initPreloadServlets(HttpApplication.java:4676)
         at com.evermind.server.http.HttpApplication.initDynamic(HttpApplication.java:820)
         at com.evermind.server.http.HttpApplication.<init>(HttpApplication.java:542)
         at com.evermind.server.Application.getHttpApplication(Application.java:889)
         at com.evermind.server.http.HttpServer.getHttpApplication(HttpServer.java:690)
         at com.evermind.server.http.HttpSite.getApplication(HttpSite.java:420)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:422)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
         at java.lang.Thread.run(Thread.java:534)
    -----------------------------------------------------------------------

    hi,
    I am also facing the same issue. Could you tell me which are those jar files you were missing & from where you got those?
    regards
    prasanth

  • Can't get Struts validator to work with ADF 10.1.3.36.73 in Jdev 10.1.3.0.4

    I am attempting to use the "How to Use the Struts Validator Plug-in with JDeveloper 10g" written by Duncan in a JDeveloper 10.1.3.0.4 application with standard model/ViewController projects. I am using JSP/Struts/ADF technologies.
    I have performed the below:
    Struts Config:
    <form-bean name="surveyDataForm" type="oracle.adf.controller.v2.struts.forms.BindingContainerValidationForm" className="oracle.adf.controller.struts.forms.BindingContainerValidationFormConfig"/>
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
    </plug-in>
    In the validation.xml:
    <!DOCTYPE form-validation
    PUBLIC "-//Apache Software Foundation//
    DTD Commons Validator Rules
    Configuration 1.0//EN"
    "http://jakarta.apache.org/
    commons/dtds/validator_1_0.dtd">
    <form-validations>
    <formset>
    <form name="surveyDataForm">
    <field property="EmpName" depends="required">
    <arg0 key="survey.name"/>
    </field>
    <field property="DateOfService" depends="required">
    <arg0 key="survey.service.date"/>
    </field>
    <field property="ReloContractor" depends="required">
    <arg0 key="survey.relo.contract"/>
    </field>
    </form>
    </formset>
    </form-validations>
    And in my JSP, I have:
    <script type="text/javascript">
    <html:javascript formName="surveyDataForm"/>
    </script>
    <html:form action="/survey.do" onsubmit="return validateSurveyDataForm(this)">
    (The validation-rules.xml was copied from the JDev install jakarta-struts folder).
    I can now see the Javascript showing up in my JSP page, but I don't have a method generated for validateSurveyDataForm or any form like this. I didn't think I had to create this. Also, even without the Javascript, the validator is not called because the JBO errors for required are still showing up. The only thing I have not done is included the modelReference in the Form Bean definition in the struts-config.xml. I'm not sure this will work, or even what to populate this with, as the UIModel.xml is replaced by PageDef.xml and DataBindings.cpx changes.
    Anyone have any ideas?
    Shay

    Only have one network; wireless. On it's own, the MacBook can use wifi to surf the net and Apple TV can watch movie previews from Apple via wifi.
    It did work about two months ago. I haven't used it since then for home sharing but have used the Apple TV on its own.
    I read the Troubleshooting page on Apple Support. It involves turning various things on and off, which I did

  • Struts validation not working properly

    Hi,
    I'm using the struts validator to validate my form.. I've followed all the steps required.. I've checked it quite a few times :)
    Currently I want to verify if my form fields have any value, so am verifying the required property.. but when I submit an empty form, it doesn't show an error.. but the log shows the following;
    Any suggestions what could be missing?
    2005-08-11 16:20:08,804 [http-8080-Processor25] ERROR org.apache.struts.validator.ValidatorForm - org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionMessages, org.apache.commons.validator.Validator, javax.servlet.http.HttpServletRequest)
    org.apache.commons.validator.ValidatorException: org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionMessages, org.apache.commons.validator.Validator, javax.servlet.http.HttpServletRequest)
         at org.apache.commons.validator.ValidatorAction.loadValidationMethod(ValidatorAction.java:627)
         at org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorAction.java:557)
         at org.apache.commons.validator.Field.validateForRule(Field.java:827)
         at org.apache.commons.validator.Field.validate(Field.java:906)
         at org.apache.commons.validator.Form.validate(Form.java:174)
         at org.apache.commons.validator.Validator.validate(Validator.java:367)
         at org.apache.struts.validator.ValidatorForm.validate(ValidatorForm.java:152)
         at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:942)
         at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1480)
         at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:524)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

    I had a similar problem upgrading from struts 1.1 to 1.2.7. The method signatures in FieldChecks changed to include a Validator object:
    1.1
    validateRequired(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, ActionErrors errors, javax.servlet.http.HttpServletRequest request)
    1.2.7
    validateRequired(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, ActionMessages errors, org.apache.commons.validator.Validator validator, javax.servlet.http.HttpServletRequest request)
    After I added org.apache.commons.validator.Validator to the methodParams attribute of validator in validator-rules.xml I no longer got the error (which was a NoSuchMethodException... I had to look at the ValidatorAction code to find that out, for some reason it wasn't in the stack trace).

  • Struts Validation not working

    As far as I can tell I can't see anything wrong with my validation on struts, but if I put nothing into a required field it doesn't report an error. Any ideas? Below is the offending code:
    First Validation.xml
    <form-validation>
        <formset>
            <form name="User">
                <field property="email"
                        depends="required,email">
                    <arg0 key="user.email"/>
                </field>
            </form>
        </formset>
    </form-validation>Next my struts-config.xml:
    <form-bean name="User" type="org.apache.struts.validator.DynaValidatorForm">
             <form-property name="userName" type="java.lang.String"/>
             <form-property name="password" type="java.lang.String"/>
             <form-property name="firstName" type="java.lang.String"/>
             <form-property name="lastName" type="java.lang.String"/>
             <form-property name="email" type="java.lang.String"/>
    </form-bean>next the jsp code:
    <html:form action="/profile?action=save">
    <html:errors/><BR><BR>
    <tr>
         <td align="left" valign="top"><font face="Arial, Helvetica" size="2">Email:</font></td>
         <td></td>
         <td align="left"><html:text property="email" size="35" maxlength="255" /><br><font size="1"><i>(Your name @ your company web site address)</i></font></td>
    </tr>
    </form>And my Action code:
              else if (action.equals("save")){
                   errors = form.validate(mapping, request);
                   if ((errors == null) || (errors.isEmpty())){
                        //Save Item goes here
                        return (mapping.findForward("Profile"));
                   else {
                        saveErrors(request, errors);
                        return (mapping.findForward("show"));
              }And my validator-rules.xml (it is the default one that comes with struts, but I included it just in case)
    <form-validation>
       <global>
          <validator name="required"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateRequired"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                      msg="errors.required">
             <javascript><![CDATA[
                function validateRequired(form) {
                    var isValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oRequired = new required();
                    for (x in oRequired) {
                         var field = form[oRequired[x][0]];
                        if (field.type == 'text' ||
                            field.type == 'textarea' ||
                            field.type == 'file' ||
                            field.type == 'select-one' ||
                            field.type == 'radio' ||
                            field.type == 'password') {
                            var value = '';
                                  // get field's value
                                  if (field.type == "select-one") {
                                       var si = field.selectedIndex;
                                       if (si >= 0) {
                                            value = field.options[si].value;
                                  } else {
                                       value = field.value;
                            if (trim(value).length == 0) {
                                 if (i == 0) {
                                     focusField = field;
                                 fields[i++] = oRequired[x][1];
                                 isValid = false;
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    return isValid;
                // Trim whitespace from left and right sides of s.
                function trim(s) {
                    return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
                ]]>
             </javascript>
          </validator>
          <validator name="requiredif"
                     classname="org.apache.struts.validator.FieldChecks"
                     method="validateRequiredIf"
                     methodParams="java.lang.Object,
                                   org.apache.commons.validator.ValidatorAction,
                                   org.apache.commons.validator.Field,
                                   org.apache.struts.action.ActionErrors,
                                   org.apache.commons.validator.Validator,
                                   javax.servlet.http.HttpServletRequest"
                     msg="errors.required">
          </validator>
          <validator name="minlength"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateMinLength"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.minlength">
             <javascript><![CDATA[
                function validateMinLength(form) {
                    var isValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oMinLength = new minlength();
                    for (x in oMinLength) {
                        var field = form[oMinLength[x][0]];
                        if (field.type == 'text' ||
                            field.type == 'textarea') {
                            var iMin = parseInt(oMinLength[x][2]("minlength"));
                            if ((trim(field.value).length > 0) && (field.value.length < iMin)) {
                                if (i == 0) {
                                    focusField = field;
                                fields[i++] = oMinLength[x][1];
                                isValid = false;
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    return isValid;
                }]]>
             </javascript>
          </validator>
          <validator name="maxlength"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateMaxLength"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.maxlength">
             <javascript><![CDATA[
                function validateMaxLength(form) {
                    var isValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oMaxLength = new maxlength();
                    for (x in oMaxLength) {
                        var field = form[oMaxLength[x][0]];
                        if (field.type == 'text' ||
                            field.type == 'textarea') {
                            var iMax = parseInt(oMaxLength[x][2]("maxlength"));
                            if (field.value.length > iMax) {
                                if (i == 0) {
                                    focusField = field;
                                fields[i++] = oMaxLength[x][1];
                                isValid = false;
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    return isValid;
                }]]>
             </javascript>
          </validator>
          <validator name="mask"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateMask"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.invalid">
             <javascript><![CDATA[
                function validateMask(form) {
                    var isValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oMasked = new mask();
                    for (x in oMasked) {
                        var field = form[oMasked[x][0]];
                        if ((field.type == 'text' ||
                             field.type == 'textarea') &&
                             (field.value.length > 0)) {
                            if (!matchPattern(field.value, oMasked[x][2]("mask"))) {
                                if (i == 0) {
                                    focusField = field;
                                fields[i++] = oMasked[x][1];
                                isValid = false;
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    return isValid;
                function matchPattern(value, mask) {
                   return mask.exec(value);
                }]]>
             </javascript>
          </validator>
          <validator name="byte"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateByte"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.byte"
           jsFunctionName="ByteValidations">
             <javascript><![CDATA[
                function validateByte(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oByte = new ByteValidations();
                    for (x in oByte) {
                         var field = form[oByte[x][0]];
                        if (field.type == 'text' ||
                            field.type == 'textarea' ||
                            field.type == 'select-one' ||
                                  field.type == 'radio') {
                                  var value = '';
                                  // get field's value
                                  if (field.type == "select-one") {
                                       var si = field.selectedIndex;
                                       if (si >= 0) {
                                            value = field.options[si].value;
                                  } else {
                                       value = field.value;
                            if (value.length > 0) {
                                if (!isAllDigits(value)) {
                                    bValid = false;
                                    if (i == 0) {
                                        focusField = field;
                                    fields[i++] = oByte[x][1];
                                } else {
                                     var iValue = parseInt(value);
                                     if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) {
                                         if (i == 0) {
                                             focusField = field;
                                         fields[i++] = oByte[x][1];
                                         bValid = false;
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    return bValid;
                }]]>
             </javascript>
          </validator>
          <validator name="short"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateShort"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.short"
           jsFunctionName="ShortValidations">
             <javascript><![CDATA[
                function validateShort(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oShort = new ShortValidations();
                    for (x in oShort) {
                         var field = form[oShort[x][0]];
                        if (field.type == 'text' ||
                            field.type == 'textarea' ||
                            field.type == 'select-one' ||
                            field.type == 'radio') {
                            var value = '';
                                  // get field's value
                                  if (field.type == "select-one") {
                                       var si = field.selectedIndex;
                                       if (si >= 0) {
                                            value = field.options[si].value;
                                  } else {
                                       value = field.value;
                            if (value.length > 0) {
                                if (!isAllDigits(value)) {
                                    bValid = false;
                                    if (i == 0) {
                                        focusField = field;
                                    fields[i++] = oShort[x][1];
                                } else {
                                     var iValue = parseInt(value);
                                     if (isNaN(iValue) || !(iValue >= -32768 && iValue <= 32767)) {
                                         if (i == 0) {
                                             focusField = field;
                                         fields[i++] = oShort[x][1];
                                         bValid = false;
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    return bValid;
                }]]>
             </javascript>
          </validator>
          <validator name="integer"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateInteger"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.integer"
           jsFunctionName="IntegerValidations">
             <javascript><![CDATA[
                function validateInteger(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oInteger = new IntegerValidations();
                    for (x in oInteger) {
                         var field = form[oInteger[x][0]];
                        if (field.type == 'text' ||
                            field.type == 'textarea' ||
                            field.type == 'select-one' ||
                            field.type == 'radio') {
                            var value = '';
                                  // get field's value
                                  if (field.type == "select-one") {
                                       var si = field.selectedIndex;
                                      if (si >= 0) {
                                           value = field.options[si].value;
                                  } else {
                                       value = field.value;
                            if (value.length > 0) {
                                if (!isAllDigits(value)) {
                                    bValid = false;
                                    if (i == 0) {
                                         focusField = field;
                                          fields[i++] = oInteger[x][1];
                                } else {
                                     var iValue = parseInt(value);
                                     if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
                                         if (i == 0) {
                                             focusField = field;
                                         fields[i++] = oInteger[x][1];
                                         bValid = false;
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    return bValid;
                function isAllDigits(argvalue) {
                    argvalue = argvalue.toString();
                    var validChars = "0123456789";
                    var startFrom = 0;
                    if (argvalue.substring(0, 2) == "0x") {
                       validChars = "0123456789abcdefABCDEF";
                       startFrom = 2;
                    } else if (argvalue.charAt(0) == "0") {
                       validChars = "01234567";
                       startFrom = 1;
                    } else if (argvalue.charAt(0) == "-") {
                        startFrom = 1;
                    for (var n = startFrom; n < argvalue.length; n++) {
                        if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
                    return true;
                }]]>
             </javascript>
          </validator>
          <validator name="long"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateLong"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.long"/>
          <validator name="float"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateFloat"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.float"
           jsFunctionName="FloatValidations">
             <javascript><![CDATA[
                function validateFloat(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oFloat = new FloatValidations();
                    for (x in oFloat) {
                         var field = form[oFloat[x][0]];
                        if (field.type == 'text' ||
                            field.type == 'textarea' ||
                            field.type == 'select-one' ||
                            field.type == 'radio') {
                             var value = '';
                                  // get field's value
                                  if (field.type == "select-one") {
                                       var si = field.selectedIndex;
                                       if (si >= 0) {
                                           value = field.options[si].value;
                                  } else {
                                       value = field.value;
                            if (value.length > 0) {
                                // remove '.' before checking digits
                                var tempArray = value.split('.');
                                var joinedString= tempArray.join('');
                                if (!isAllDigits(joinedString)) {
                                    bValid = false;
                                    if (i == 0) {
                                        focusField = field;
                                    fields[i++] = oFloat[x][1];
                                } else {
                                     var iValue = parseFloat(value);
                                     if (isNaN(iValue)) {
                                         if (i == 0) {
                                             focusField = field;
                                         fields[i++] = oFloat[x][1];
                                         bValid = false;
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    return bValid;
                }]]>
             </javascript>
          </validator>
          <validator name="double"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateDouble"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.double"/>
          <validator name="date"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateDate"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.date"
           jsFunctionName="DateValidations">
             <javascript><![CDATA[
                function validateDate(form) {
                   var bValid = true;
                   var focusField = null;
                   var i = 0;
                   var fields = new Array();
                   oDate = new DateValidations();
                   for (x in oDate) {
                       var value = form[oDate[x][0]].value;
                       var datePattern = oDate[x][2]("datePatternStrict");
                       if ((form[oDate[x][0]].type == 'text' ||
                            form[oDate[x][0]].type == 'textarea') &&
                           (value.length > 0) &&
                           (datePattern.length > 0)) {
                         var MONTH = "MM";
                         var DAY = "dd";
                         var YEAR = "yyyy";
                         var orderMonth = datePattern.indexOf(MONTH);
                         var orderDay = datePattern.indexOf(DAY);
                         var orderYear = datePattern.indexOf(YEAR);
                         if ((orderDay < orderYear && orderDay > orderMonth)) {
                             var iDelim1 = orderMonth + MONTH.length;
                             var iDelim2 = orderDay + DAY.length;
                             var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                             var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                             if (iDelim1 == orderDay && iDelim2 == orderYear) {
                                dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
                             } else if (iDelim1 == orderDay) {
                                dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
                             } else if (iDelim2 == orderYear) {
                                dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
                             } else {
                                dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
                             var matched = dateRegexp.exec(value);
                             if(matched != null) {
                                if (!isValidDate(matched[2], matched[1], matched[3])) {
                                   if (i == 0) {
                                       focusField = form[oDate[x][0]];
                                   fields[i++] = oDate[x][1];
                                   bValid =  false;
                             } else {
                                if (i == 0) {
                                    focusField = form[oDate[x][0]];
                                fields[i++] = oDate[x][1];
                                bValid =  false;
                         } else if ((orderMonth < orderYear && orderMonth > orderDay)) {
                             var iDelim1 = orderDay + DAY.length;
                             var iDelim2 = orderMonth + MONTH.length;
                             var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                             var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                             if (iDelim1 == orderMonth && iDelim2 == orderYear) {
                                 dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
                             } else if (iDelim1 == orderMonth) {
                                 dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
                             } else if (iDelim2 == orderYear) {
                                 dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
                             } else {
                                 dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
                             var matched = dateRegexp.exec(value);
                             if(matched != null) {
                                 if (!isValidDate(matched[1], matched[2], matched[3])) {
                                     if (i == 0) {
                                         focusField = form[oDate[x][0]];
                                     fields[i++] = oDate[x][1];
                                     bValid =  false;
                             } else {
                                 if (i == 0) {
                                     focusField = form[oDate[x][0]];
                                 fields[i++] = oDate[x][1];
                                 bValid =  false;
                         } else if ((orderMonth > orderYear && orderMonth < orderDay)) {
                             var iDelim1 = orderYear + YEAR.length;
                             var iDelim2 = orderMonth + MONTH.length;
                             var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                             var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                             if (iDelim1 == orderMonth && iDelim2 == orderDay) {
                                 dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$");
                             } else if (iDelim1 == orderMonth) {
                                 dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$");
                             } else if (iDelim2 == orderDay) {
                                 dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$");
                             } else {
                                 dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$");
                             var matched = dateRegexp.exec(value);
                             if(matched != null) {
                                 if (!isValidDate(matched[3], matched[2], matched[1])) {
                                     if (i == 0) {
                                         focusField = form[oDate[x][0]];
                                      fields[i++] = oDate[x][1];
                                      bValid =  false;
                              } else {
                                  if (i == 0) {
                                      focusField = form[oDate[x][0]];
                                  fields[i++] = oDate[x][1];
                                  bValid =  false;
                         } else {
                             if (i == 0) {
                                 focusField = form[oDate[x][0]];
                             fields[i++] = oDate[x][1];
                             bValid =  false;
                   if (fields.length > 0) {
                      focusField.focus();
                      alert(fields.join('\n'));
                   return bValid;
             function isValidDate(day, month, year) {
                 if (month < 1 || month > 12) {
                        return false;
                    if (day < 1 || day > 31) {
                        return false;
                    if ((month == 4 || month == 6 || month == 9 || month == 11) &&
                        (day == 31)) {
                        return false;
                    if (month == 2) {
                        var leap = (year % 4 == 0 &&
                                   (year % 100 != 0 || year % 400 == 0));
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

    Next my struts-config.xml:That's all? What about an <action-mappings> section
    which specifies the action URIs and whether or not
    validation is turned on for specific ones?Whoops, sorry I forgot to put my action, although you just made me figure out the answer. I forgot I have 2 versions of the bean, one called Profile and one Called User, and I was trying to test the validation on the Profile bean while I was specifying the User bean :)

  • Can I use Struts Validator Plugin's html:javascript tag?

    Hi:
    Is it possible to incorporate the client-side validation using Struts Validator
    Plugin's tag <html:javascript>?
    i.e.
    1) Insert the following tag to A.jsp and define a taglib:
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <html:javascript formName="aForm" staticJavascript="true"/>
    2) Define validation.xml as follows:
    <form-validation>
    <formset>
    <form name="aForm">
    <field property="aField"
    depends="required">
    <msg name="required" key="FieldMissingError"/>
    </field>
    </form>
    </formset>
    </form-validation>
    3) Insert the onSubmit event in aForm:
    <netui:form action="SubmitAForm" style="border-width:1px;" onSubmit="validateAForm(this)">

    Instead of writing something like this -
    <p class="logos">Logo1<a href="...></a></p>
    <p class="logos">Logo2<a href="...></a></p>
    <p class="logos">Logo3<a href="...></a></p>
    <p class="logos">Logo4<a href="...></a></p>
    <p class="logos">Logo5<a href="...></a></p>
    <p class="logos">Logo6<a href="...></a></p>
    Why not have something like this -
    <div id="logodiv">
    <p>Logo1<a href="...></a></p>
    <p>Logo2<a href="...></a></p>
    <p>Logo3<a href="...></a></p>
    <p>Logo4<a href="...></a></p>
    <p>Logo5<a href="...></a></p>
    <p>Logo6<a href="...></a></p>
    </div>
    with CSS like this -
    #logodiv p { ... }

  • Problem in struts validator

    hai
    I have a problem while using the struts validator in my program.
    It gives the error as:
    HTTP Status 404 - Servlet action is not available
    type Status report
    message Servlet action is not available
    description The requested resource (Servlet action is not available) is not available.
    The program is given below
    File : one.jsp
    <html:form action="/test" method="post">
    <table width="309">
    <tr>
    <td width="149"><div align="right">User Name: </div></td>
    <td width="148"><html:text property="username" value=""/></td>
    </tr>
    <tr>
    <td><div align="right">PassWord: </div></td>
    <td><html:password property="password" value="" /> </td>
    </tr>
         <tr>
    <td><div align="right">Number: </div></td>
    <td><html:password property="number" value="" /> </td>
    </tr>
    <tr>
    <td><div align="right"></div></td>
    <td><html:submit /> </td>
    </tr>
    </table>
    </html:form>
    web.xml file is ordineary file which contains the tag which is necessary for the struts.
    File : struts-config.xml
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
    "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
    <global-forwards>
    <forward name="database" path="/database"/>
    </global-forwards>
    <form-beans>
    <form-bean name="form1" type="struts1.bean1">
    </form-bean>      
    </form-beans>
    <action-mappings>
    <action path="/test" name="form1" type="struts1.one" input="one.jsp" validate="true" scope="request" >
         <forward name="success" path="/two.jsp"/>
    </action>
    </action-mappings>
    <message-resources parameter="ApplicationResources" />
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
         <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
    </plug-in>
    </struts-config>
    File validator.xml
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE form-validation PUBLIC
    "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
    "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
    <form-validation>
    <formset>
    <!-- Form for Validation example -->
    <form name="form1">
    <field property="username" depends="required">
    <arg0 key="test.string"/>
    </field>
    <field property="password" depends="required">
    <arg0 key="test.password"/>
    </field>
    <field property="number" depends="required">
    <arg0 key="test.number"/>
    </field>
    </form>
    </formset>
    </form-validation>
    File validator-rules.xml
    The validator-rules.xml file is default validator-rules.xml file.
    Iam using the two java file for ActionForm and Action
    ActionForm file
    package struts1;
    import org.apache.struts.validator.ValidatorForm;
    public class bean1 extends ValidatorForm
    private String username=null;
    private String password=null;
    private int number=0;
    public void setUsername(String username)
    this.username=username;
    public String getUsername()
    return username;
    public void setPassword(String password)
    this.password=password;
    public String getPassword()
    return password;
    public void setNumber(int number)
    this.number=number;
    public int getNumber()
    return number;
    Action class:
    package struts1;
    import struts1.bean1;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.DynaActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.validator.ValidatorActionForm;
    import org.apache.struts.validator.ValidatorForm;
    import java.io.IOException;
    import javax.servlet.ServletException;
    public class one extends Action
    public ActionForward execute(ActionMapping mapping,ActionForm form1,HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
    String uname=null;
    String pword=null;
    String target=new String("success");
    int num=0;
    HttpSession session=request.getSession(true);
    try
    if(form1 !=null)
    bean1 form=(bean1) form1;
    uname=form.getUsername();
    pword=form.getPassword();
    num=form.getNumber();
    session.setAttribute("uname",uname);
    session.setAttribute("word",pword);
    session.setAttribute("num",""+num);
    catch(Exception e)
    return mapping.findForward(target);
    In two.jsp file Iam just getting the session value and displaying the result.
    The Action and ActionForm are used inside the struts1 file which is placed inside the classes folder.
    The Two file is also compiled successful.
    When executing the one.jsp file is displayed but when clicking the submit button it giving the error as servlet action is not available.
    So Iam try to change some coding in the Action Class
    In the execute method I changed ValidatorForm instead of ActionForm.
    but it giving the same error.
    The same error is displayed when Iam trying the DynaValidatorForm
    instead of struts bean class i.e ActionForm.
    If any one knows what is the problem in the program please give some instrutction to correct the error or give some simple example program for practice.
    Regards
    A.K. Raj

    Add the Validator as the 6th argument and it should work fine.
    Amy
    <validator name="required"
    classname="org.apache.struts.validator.FieldChecks"
    method="validateRequired"
    methodParams="java.lang.Object,
    org.apache.commons.validator.ValidatorAction,
    org.apache.commons.validator.Field,
    org.apache.struts.action.ActionMessages,
    org.apache.commons.validator.Validator,
    javax.servlet.http.HttpServletRequest"
    msg="errors.required"/>

  • Struts validation

    Hi
    i have a question and was looking forward for your help...
    during struts validation we use depends="int"
    so our purpose is to accept values which are pure integers and remaing should be rejected by validator.....but then if we put some text say "abc" it simply gets converted to 0 and validator accepts it and shows no error
    So how can validator classes help us to get around this....that is when ever user inserts something that's not a proper number validator should alarm with an error

    I've found a solution that works for me:
    1. In the form in each jsp of the multi-page form, add:
    <netui:hidden dataSource="{actionForm.page}"/>
    2. Add a page="<pageno>" attribute to each field element in the validations xml
    file, where validation is performed when <pageno> is <= to the current page number.
    3. In each action method add:
    form.setPage(<pageno>)
    where <pageno> is appropriate to the page that this action will forward to. You
    will need to initialise page to 1 in the begin() method.
    Andy
    >
    Hi all
    I'm using Struts validation in WLP 8.1 with a multi-page form that has
    a single
    ValidatorForm form bean. How do I ensure that only the fields for a page
    represented
    by an action are validated?
    thanks, Andy

  • Struts validation with BC4J

    We're developing an ADF/Struts app.
    We started off with entity object level validation. However, we'd like nice formatable messages so decided to move towards Struts form beans and perform validation there.
    Firstly, was this the right thing to do or can we place and format entity object validation errors however we like?
    If we did make the right choice we aren't sure how ADF bindings and form beans interact and whether they should be used together.
    We ask because of the following:
    If we add a getFirstName field onto the form bean, and call the field in the JSP firstName (lower case 'f') then all is well and the form bean operates as expected with no errors.
    However, if the field on the JSP is called FirstName (capital 'F') then the getter method is not found:
    "No getter method for property FirstName of bean org.apache.struts.taglib.html.BEAN"
    ADF bindings give the JSP properties upper case first-letter names by default. We can of course go and rename all of the bindings - but that's time consuming and as nobody has complained of something similar in the forums, we get the impression that we're doing something wrong or that they are rarely used together.
    Any help appreciated.
    Ben

    The general rule with validation is never to rely on the UI generation layer to validate your data.
    It's reasonable to place validation there, but you should back it up with validation on the EO as well.
    If you want to mix Struts validators with ADF bindings then you're best using the Struts Validator framework and the oracle.adf.controller.v2.struts.forms.BindingContainerValidationForm as the type of the Form Bean for that page. That way you can use both ADF bindings and declaritive validations using the validator XML definitions

  • Problem in struts validation

    hi,
    i am doing a project using struts framework.
    i've configured strtus-config.xml , validation.xml
    but validation framework is not working for me.
    when i click submitt button without entering any values, it directly maps to the success page. but it should show the errors.
    i've attached all the files with this. plz give me the solution
    struts-config.xml
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <struts-config>
    <form-beans>
    <form-bean name="allotIssueFormBean" type="issues.AllotIssueFormBean"/>
    </form-beans>
    <action-mappings>
    <action path="/allotIssue"
    type="issues.AllotIssueAction"
    scope="request"
    name="allotIssueFormBean"
    validate="true"
    input="/allotIssue.jsp">
    <forward name="success"
    path="/results/success.jsp"/>
    </action>
    </action-mappings>
    <message-resources parameter="MessageResources" />
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validator/validation.xml" />
    <set-property property="stopOnFirstError" value="true" />
    </plug-in>
    </struts-config>
    -- validation.xml --
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE form-validation PUBLIC
    "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
    "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
    <form-validation>
    <!--
    This is a minimal Validator form file with a couple of examples.
    -->
    <global>
    <!-- An example global constant
    <constant>
    <constant-name>postalCode</constant-name>
    <constant-value>^\d{5}\d*$</constant-value>
    </constant>
    end example-->
    </global>
    <formset>
    <!-- An example form -->
    <form name="AllotIssueFormBean">
    <field
    property="issueID"
    depends="required" >
    <arg0 key="ddd" resource="false"/>
    </field>
    <field
    property="listName"
    depends="required">
    <arg0 key="ddd"/>
    </field>
    <field
    property="projectName"
    depends="required">
    <arg0 key="ddd"/>
    </field>
    <field
    property="selectAllotting"
    depends="required">
    <arg0 key="ddd"/>
    </field>
    <field
    property="selectDate"
    depends="required">
    <arg0 key="ddd"/>
    </field>
    <field
    property="selectMonth"
    depends="required">
    <arg0 key="ddd"/>
    </field>
    <field
    property="selectYear"
    depends="required">
    <arg0 key="ddd"/>
    </field>
    </form>
    </formset>
    </form-validation>
    allotIssue.jsp
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@ taglib uri="/tags/struts-bean" prefix="bean" %>
    <%@ taglib uri="/tags/struts-html" prefix="html" %>
    <%@ taglib uri="/tags/struts-logic" prefix="logic" %>
    <html:html>
    <head>
    <TITLE> ALLOTT ISSUE </TITLE>
    <html:javascript formName="allotIssueFormBean" staticJavascript="true" method="validateAllotIssueFormBean"/>
    <STYLE>
    body{
    font-family:verdana;
    background-color:#0111d3;
    color:white;
    font-size:8px;
    table
    font-size:10px;
    </STYLE>
    </head>
    <html:errors/>
    <html:form action="/allotIssue.do" >
    <TABLE border="1" align="center" bodercolor="silver" bgcolor='#4478f0' width="40%">
    <tr>
    <td colspan="2" style='border:0px' align="center">ALLOT ISSUE</td>
    </tr>
    <TR style='border:0px'>
    <TD>IssueID:</TD>
    <TD><html:text property="issueID"/></TD>
    </TR>
    <TR style='border:0px'>
    <TD>List Name:</TD>
    <TD><html:text property="listName"/></TD>
    </TR>
    <TR style='border:0px'>
    <TD>Project Name:</TD>
    <TD><html:text property="projectName"/></TD>
    </TR>
    <TR style='border:0px'>
    <TD>Allotted To:</TD>
    <TD><html:select property="selectAllotting" >
    <html:option value="associatename1">Name1</html:option>
    <html:option value="associateName2">Name2</html:option>
    <html:option value="associatename3">Name3</html:option>
    </html:select>
    </TD>
    </TR>
    <TR CLASS="tr">
    <TD CLASS="td" style='border:0px'>Projected-End-Date</td>
    <TD><html:select property="selectDate" >
    <html:option value="1">1</html:option>
    <html:option value="2">2</html:option>
    <html:option value="3">3</html:option>
    </html:select>
    <html:select property="selectMonth" >
    <html:option value="1" >Jan</html:option>
    <html:option value="2" >Feb</html:option>
    </html:select>
    <html:select property="selectYear">
    <html:option value="1990">1990</html:option>
    <html:option value="1991">1991</html:option>
    </html:select>
    </TD>
    </TR>
    <TR style='border:0px'>
    <TD colspan="2" align="center">
    <html:submit value="AllotIssue"/>
    <html:reset value="Reset"/>
    </TD>
    </TR>
    </TABLE>
    </html:form>
    </html:html>
    -- AllotIssueAction.java --
    * AllotIssueAction.java
    * Created on April 27, 2006, 4:49 PM
    * To change this template, choose Tools | Options and locate the template under
    * the Source Creation and Management node. Right-click the template and choose
    * Open. You can then make changes to the template in the Source Editor.
    package issues;
    import javax.servlet.http.*;
    import org.apache.struts.action.*;
    public class AllotIssueAction extends Action {
    public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws Exception {
    return(mapping.findForward("success"));
    -- AllotIssueFormBean --
    package issues;
    import javax.servlet.http.*;
    import org.apache.struts.action.*;
    import org.apache.struts.validator.*;
    public class AllotIssueFormBean extends ValidatorForm {
    private String issueID = "";
    private String listName = "";
    private String projectName = "";
    private String selectAllotting = "";
    private String selectDate="";
    private String selectMonth="";
    private String selectYear="";
    public String getIssueID() {
    return(issueID);
    public void setIssueID(String issueID) {
    this.issueID = issueID;
    public String getListName() {
    return(listName);
    public void setListName(String listName) {
    this.listName = listName;
    public String getProjectName() {
    return(projectName);
    public void setProjectName(String projectName) {
    this.projectName = projectName;
    public String getSelectAllotting() {
    return(selectAllotting);
    public void setSelectAllotting(String selectAllotting) {
    this.selectAllotting = selectAllotting;
    public String getSelectDate() {
    return(selectDate);
    public void setSelectDate(String selectDate) {
    this.selectDate = selectDate;
    public String getSelectMonth() {
    return(selectMonth);
    public void setSelectMonth(String selectMonth) {
    this.selectMonth = selectMonth;
    public void setSelectYear(String selectYear) {
    this.selectYear = selectYear;
    public String getSelectYear() {
    return(selectYear);
    }

    In the following code...
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <struts-config>
    <form-beans>
    <form-bean name="allotIssueFormBean" type="issues.AllotIssueFormBean"/>
    </form-beans>... should the <form-bean> type attribute be org.apache.struts.validator.DynaValidatorForm? I've only done validation in this way (though I'm still a novice myself). Then you wouldn't need your allotIssueFormBean, and instead you would define the properties in the struts-config using...
    <form-bean ...>
      <form-property name="issueID" type="java.lang.String" />
      <form-property name="listName" type="java.lang.String" />
    ... etc...
    </form-bean>

  • Struts validation framework

    Dear all,
    To use struts validator, I should make my action form to extend
    org.apache.struts.validator.action.ValidatorForm instead of org.apache.struts.action.ActionForm.
    However, I have to also make my action form to extend a third part action form which extends org.apache.struts.action.ActionForm.
    In this case, how can I continue to use Struts validator without changing the third part code?
    Pengyou

    You can use the java script for checking this.
    for (i=0;i<Form.elements.length;i++) {
    //alert("Elements Type: " + Form.elements.type);
    if (Form.elements[i].type == "checkbox") {
              checkBoxCounter++;
              if (Form.elements[i].checked) {
                   alert("Checked Name is .! " + Form.elements[i].name);
                   alert("Checked Id is .! " + Form.elements[i].id);
              }//End of if (Form.elements[i].checked)
    }// End of if (Form.elements[i].type == "checkbox"
    }// End of for (i=0;i<Form.elements.length;i++)

Maybe you are looking for