You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ji...@uniqema.com on 2005/04/01 23:50:22 UTC

Issue with fields not validating properly

I am having an issue with two form fields not validating properly.

Basically, I have a form that is being used to add documents to a
repository...

The form allows the user to enter information about the document and upload
the document to the repository.

Here is the form html:

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<h4>Add a Document &gt; Step 2</h4>
<span class="required"><html:errors/></span>
<html:form action="/AddDoc" enctype="multipart/form-data">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><fieldset>
        <legend>Document Info</legend>
        <table width="100%" border="0" cellspacing="0" cellpadding="5">
          <tr valign="top">
            <td width="20%"><strong>Document Title<span
class="required">*</span></strong></td>
            <td width="29%">
              <div align="left">
                <html:text property="doc_title" />
              </div>
            </td>
            <td width="18%"><strong>Author</strong></td>
            <td width="33%">
              <div align="left">
                <html:text property="author" />
              </div>
            </td>
          </tr>
          <tr valign="top">
            <td><strong>Date Created<span
class="required">*</span></strong></td>
            <td>
              <div align="left">
                <html:text property="date_created" />
              </div>
            </td>
            <td><strong>Review Period<span
class="required">*</span></strong></td>
            <td>
              <div align="left">
                <html:select property="review_period">
                              <html:option value="1">1</html:option>
                </html:select>
              </div>
            </td>
          </tr>
          <tr valign="top">
            <td><strong>Short Description<span
class="required">*</span></strong></td>
            <td>
              <div align="left">
                <html:textarea property="short_desc"></html:textarea>
              </div>
            </td>
            <td><strong>File to Upload<span
class="required">*</span></strong></td>
            <td>
              <div align="left">
                <html:file property="file" />
              </div>
            </td>
          </tr>
        </table>
        </fieldset>
        <p>&nbsp;</p>
        <fieldset>
        <legend>Additional Info</legend>
        <table width="100%" border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td width="20%"><strong>Category<span
class="required">*</span></strong></td>
            <td width="29%">
              <div align="left">
                <html:select property="category_id">
                              <html:option value="1">1</html:option>
                </html:select>
              </div>
            </td>
            <td width="18%"><strong>Sub-Category</strong></td>
            <td width="33%">
              <div align="left">
                <html:select property="sub_cat_id">
                              <html:option value="1">1</html:option>
                </html:select>
              </div>
            </td>
          </tr>
          <tr>
            <td><strong>Region</strong></td>
            <td>
              <div align="left">
                <html:select property="region_id">
                              <html:option value="1">1</html:option>
                </html:select>
              </div>
            </td>
            <td>&nbsp;</td>
            <td><div align="left"></div>
            </td>
          </tr>
        </table>
        </fieldset>
        <div align="left">
          <p>
            <html:submit value="Add Document" />
          </p>
        </div>
      </td>
    </tr>
  </table>
</html:form>

and here is my validation.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 name="DocumentFormBean">
                  <field property="doc_title"
                         depends="required">
                        <arg0 key="addDoc.title"/>
                  </field>
                  <field property="date_created"
                           depends="required,date">
                        <arg0 key="addDoc.dateCreated"/>
                        <var>
                              <var-name>datePatternStrict</var-name>
                              <var-value>MM/dd/yyyy</var-value>
                        </var>
                  </field>
                  <field property="review_period"
                           depends="required,integer">
                        <arg0 key="addDoc.reviewPeriod"/>
                  </field>
                  <field property="short_desc"
depends="required,maxlength">
                  <arg0 key="addDoc.shortDesc"/>
                  <arg1 name="maxlength" key="${var:maxlength}"
resource="false"/>

<var><var-name>maxlength</var-name><var-value>255</var-value></var>
                  </field>
                  <field property="category_id"
                        depends="required,integer">
                        <arg0 key="addDoc.category"/>
                  </field>
                  <field property="file"
                           depends="required">
                        <arg0 key="addDoc.file"/>
                  </field>

            </form>

      </formset>

</form-validation>

Basically, I am having no problems with the Title and Date Created fields
validating...those are working fine...however, the Short Description field
will validate as required, but it will not respect the maxLength check and
seems to go by unnoticed. Also, if Title, Date and Description are filled
in, but the file field isnt and it is submitted...it goes through...but if
only the Title and Date fields are filled in, it will say both the short
desc and file fields are required...

any ideas on this??? thanks in advance



__
IMPORTANT NOTICE:
This email may be confidential, may be legally privileged, and is for the intended recipient only.
Unauthorised access, disclosure, copying, distribution, or reliance on any of it by anyone else is prohibited and may be a criminal offence.�
Please delete if obtained in error and email confirmation to the sender.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org