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

Similar Messages

  • 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

  • Validate integer with a comma thousands seperator using struts Validator

    Using struts validator.
    have to validate the user entered value.
    The value entered should be a positive integer with a comma thousands seperator. the number need not be in thousands.
    I have as below to check for positive integer without comma seperator. but not sure how to validate if the user entered value with a comma seperator?
    i.e value like 25,349 // how to validate this?
    <field property="hrs" depends="integer,validwhen">
    <msg name="integer" key="errors.notvalid"/>
    <msg name="validwhen" key="errors.notvalid"/>
    <var>
    <var-name>test</var-name>
    <var-value>(*this* >= 0)</var-value>
    </var>
    </field>
    how to validate the user entered value with a comma seperator? Thanks.

    Found this in Struts' Building View Components section: Note: If your required form property is one of the Java object representations of primitive types (ie. java.lang.Integer), you must set the ActionServlet's convertNull init. parameter to true. Failing to do this will result in the required validation not being performed on that field because it will default to 0. This seems to be part of my problem. With it turned on, Validator picks up that the value is required. Now to figure out the issue with putting in a double value instead of an Integer.

  • Struts with BC4J on JDeveloper903

    We are developing a project using Struts with BC4J on JDeveloper903.
    I understand every JSP Page needs a related Action class & Form bean. It makes sense to create a Form bean if you are doing any transactions like Add or Update b'cos you want to retain the state but for browse i don't have to retain the state. So i am planning only Action class for each JSP Page.
    Does this approach have any disadvantage(s) ?
    In other words,
    Do i need to Create a Form bean for simple browse pages, we have so many browse pages ?
    Thanks in advance.

    A form bean represents the logical notion of an input form (which may extend across several web pages and server requests). If you don't have to worry about receiving user input from a form, you don't need a form bean. It's perfectly fine to have action mappings and action classes that never involve a form bean.

  • Problem with struts validator on WLS 8.1

    I am having a strange problem, when I run my app in eclipse using weblogic plugin it works fine and I get no exception. As soon as I run it externally in a standalone server I get an ServletException which seem be be because of struts validator classes. I have checked the classpath and it seems to be identical in eclipse and startweblogic.cmd
              By the way, this code works fine on WLS 6.0
              Root cause of ServletException.
              javax.servlet.jsp.JspException: ServletException in '/common/sea-layout.jsp': ServletException in '/secure/sea
              -basicBOL-body.jsp': org/apache/commons/validator/Validator
              at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:921)
              at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
              at jsp_servlet._secure.__basicbol._jspService(__basicbol.java:368)
              at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
              at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
              at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
              at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:463)
              at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
              at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:322)
              at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
              at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:261)
              at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:388)
              at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:316)
              at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
              at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
              at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
              at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
              at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
              at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.jav
              a:6718)
              at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
              at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
              at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764)
              at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
              at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
              Any pointer to fix this situation will be greatly appreciated.
              -Sankate

    Got the solution.
              It was an classloader issue and I fixed by modifying the way EAR was getting packaged.
              I was including all commons-validation.jar and other commons jars in WEB-INF/lib dir. Some how it worked on WLS 6.0 but was not able to load the jars in WLS 8.1
              Move the jars out of lib dir and copy them to app/lib dir and add them to ejb manifest file because ejb jar is loaded before WAR by the classloader. This way when WAR is loaded, all the required jars are already loaded.
              I was getting servletexception and was not able to get to the root of exception (i.e. its a NullPointerexception or NoClassDefFoundException etc) so I added a scriplet in the root jsp and caught Throwable, that was I came to know the root of the problem.
              -Sankate

  • 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

  • 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 :)

  • 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

  • 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 { ... }

  • 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

  • Integrate struts validator framework

    (JHeadstart 9.0.4: Toplink/JSP/Struts)
    I am trying to integrate the struts validator framework . I'm encountering the following
    problem. When a validation rule(defined in the struts validation.xml) is violated I would expect
    that the JSP include named jhsInfo.jsp would show the errormessage because I assumed that it also
    reads from the same Error Bean (ActionErrors object ) struts normally uses.
    When I include a jsp of my own, containing the following:
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <html:errors/>
    then messages raised by the struts validation framework are shown and everything seems to work.
    I have the following questions:
    - Is it possible to show struts validation error messages using the jhsInfo.jsp ?
    I investigated the <jhs:ifContainsError> in the JHeadstart Taglibrary
    and noticed how it checks for the JHS_USER_INFO session attribute; apparently, when the validate()
    method in JhsDynaActionForm finds ActionErrors through the Struts Validator framework, this session attribute is not set.
    However, even if we add this attribute explicitly to sessionData in validate(), we do not get the Struts Validator Action Errors.
    - If not possible, how could we adapt the code to make it work? Should we instantiate JHeadstart UserExceptions
    for all ActionErrors or does JHeadstart have built-in functionality to deal with these ActionErrors in the proper way?
    Are we running into a bug, is it intentional to keep Struts Validator Error separate from JHeadstart Exception Errors
    or is JHeadstart currently not equipped with the logic to deal with the ActionErrors?
    Thanks in advance,
    Rob Brands (Amis)

    Rob,
    JHeadstart transforms UserExceptions (controller-independent) to Struts specific ActionErrors and ActionMessages in JhsRequestprocessor.convertUserExceptions.
    So, with JHeadstart you can either use ACtionErrors/ActionMessages directly, or indirectly by thrwoing UserExceptions.
    In jhsInfo we use html:messages to loop over both messages and errors (The boolean attribute message determines whether ActionErrors or ActionMessages are iterated). We do not use html:errors because that does not provide you with control over the layout of individual messages.
    You are right that our custom tags ifContainsError and ifContainsInformation should also directly check for existence of ActionErrors and ActionMessages. We will fix that for the upcoming release.
    With that fix in place, you should be able to use jhsInfo.jsp to display validator messages.
    You mentioned you tried to put a "dummy" JHS_USER_INFO exception on the session in the validate() method. This approach should work, however, to display ActionErrors (as is the case with the validator framework), you should use JHS_USER_ERROR as the key, noy JHS_USER_INFO.
    For now, you could choose to modify jhsInfo.jsp and use your own ifContains tags, until we have fixed this.
    Steven Davelaar.

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

  • How to do validation with a class that extends DispatchAction?

    I'm trying to mess around with some validation with struts for a .jsp form and I've read a tutorial that says I need to extend ValidatorForm instead of ActionForm...however, I'm using DispatchAction instead of ActionForm. What is the best way to do validation if I'm using a DispatchAction?
    Thanks a lot.

    Hey evnafets,
    I do have the struts validator configured in the struts config file, and I do get the following message:
    Jun 21, 2005 10:06:55 AM org.apache.struts.validator.ValidatorPlugIn initResources
    INFO: Loading validation rules file from '/WEB-INF/validator-rules.xml'
    Jun 21, 2005 10:06:55 AM org.apache.struts.validator.ValidatorPlugIn initResources
    INFO: Loading validation rules file from '/WEB-INF/validation.xml'
    I added the <form-set> tags but am still getting nothing, I'm now wondering if it may have something to do with the following, which I just noticed...
    In my .jsp file, I have something like this:
    <html:form action="/modifyBook">
    <html:errors />
    <b>Name: </b><html:text property="fname" value="${entry.fname}"/> <html:text property="lname" value="${entry.lname}" /><br/>
    <html:hidden property="method" value="edit"/>
    <html:submit property="submitValue">Edit</html:submit>
    <html:cancel property="cancelValue">Cancel</html:cancel>And in the "edit" method of the ModifyBookAction class, I cast the form into a DynaValidatorForm and just have my code to perform the edit. Now, what I'm wondering is, is the form getting properly associated with a "ModifyBookForm" which is what the rules are written for? The only tie I see is in the struts config where there is this:
          <action        
             name="ModifyBookForm"
             parameter="method"
             path="/modifyBook"
             scope="request"
             type="com.yourcompany.struts.action.ModifyBookAction"
             validate="true">
             <forward
                  name="failure"
                  path="/form/error.jsp"
                  redirect="true"/>
             <forward
                name="success"
                path="/loadBook.do"
                redirect="true" />
          </action>Is this enough? I'm thinking that the validation may be set up correctly, I'm just not implementing it in the right way?
    Thanks again

  • Jakarta Struts Validation MASK

    Can anyone tell me if it is possible to use the Struts validation defeinitions in validation.xml to validate a user input to only allow either numeric values or the following strings 'NA' or 'na' to be submitted via an input field.
    I assume I would have to use some validation mask to acheive this?
    Thanks.

    Anyone help with this?
    I'm currently using the following:
    ^[0-9.NA]*$
    However, that allows AN to be entered or 989NA etc where the input must be restricted to integer or double values or the exact phase 'NA'. Can this be achieved using the struts validator framework or will I have to write some custom valiudation?
    Thanks.

  • Struts Validations

    hi,
    I've written a Struts application which uses Struts Validations, and used <html:javascript>
    tag to have client side validations.
    the problem is , when I start the application, the form is displayed along with the Scripting code of the validator frame work ...
    please help me ....

    Kumar:
    You said you read "Struts In Action", the solution to your problem(at least similar) is right in there on page 397 under "Interrelated Fields" but I was having some trouble implementing that code. As I did not have time to research the problem any further, I just added a "validate" method to my ActionForm eventhough it is not needed because I'm extending ValidatorActionForm which in theory does not need a validate method as it has its own at least according to the book. But anyway, what I did is this to compare two password fields...
    In my ActionForm...
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
    ActionErrors errors = super.validate(mapping,request);
    if (errors == null)
    errors = new ActionErrors();
    if (!password.equals(passwordconfirm))
    errors.add("Passwords Do Not Match",new ActionError("newuser.passwordconfirm.invalid"));
    if (errors == null)
    return null;
    return errors;
    Hope this helps with the part of your question about Amount fields.

Maybe you are looking for

  • Wifi, after suspend not working

    Hi everyone, Im not totally sure on what is happening, but whenever I close my notebook when I got to sleep for example. The next morning I need to reboot it. It comes out of suspend nicely but the thing is that I cannot connect to the Wifi network a

  • Context-sensitive help - where is the CS topic folder in the output files?

    I have created a FlashHelpPro help file in RoboHelp 7 HTML. In the project setup pane, I have Map ID'd my context-sensitive topics and linked them to their respective pages. I generated the project, but there is no folder containing the context-sensi

  • Logger ConsoleHandler strangeness on System.out

    Hi all, I have been scratching my head all day trying to work out what is going wrong with the following code. It's the minimal test case I could come up with to replicate something we're seeing in our codebase. I'd be greatly obliged if somebody cou

  • ICal: an unexpected network error (code 60)

    Hi Can somebody explain how to solve this? I have this for over a week now, and all the previous advice I followed, but did not work. Your help is much appreciated. Kr. Eva

  • How to tune the interval time of keyRepeated

    Hi, I use keyRepeated to deal some keyboard events. But I want to adjust the frequency of keyRepeated event to be higher/the interval time to be smaller(the default is 100ms), how can I ? Thx