You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brian McSweeney <br...@aurium.net> on 2003/05/08 15:42:01 UTC

Validator and xdoclet anyone?

Hi all,

I'm using xdoclet to build my struts app.

I'm trying to get the validator package to work with it. 
I've written the simple ValidationForm below:


package com.mycom.web.struts.form;

import org.apache.struts.validator.ValidatorForm;
/**
 * @struts.form  name="validateForm"
 */
public class ValidateForm extends ValidatorForm
{
    private String _creditCard;
    /**
     * Sets the creditCard attribute of the SearchForm object
     *
     * @struts.validator type="required"
     * @struts.validator type="creditCard"
     */
    public void setCreditCard (String creditCard)
    {
        _creditCard = creditCard;
    }
    public String getCreditCard ()
    {
        return _creditCard;
    }
}


And a simple action too.


package com.mycom.web.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


import com.mycom.web.struts.form.ValidateForm;


/**
 * @struts.action
 *      name="validateForm"
 *      path="/validate"
 *      scope="request"
 *      validate="true"
 *
 * @struts.action-forward
 *      name="success"
 *      path="/validated.jsp"
 */
public class ValidateAction extends BaseAction
{
    /**
     * @see xpetstore.web.struts.action.BaseAction#doExecute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse)
     */
    protected ActionForward doExecute (
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws Exception
    {
        System.out.println("Starting validate action");
        ValidateForm  frm  = ( ValidateForm ) form;
        
        System.out.println("Validate form is: "+frm);
        System.out.println("forwarding");
        return mapping.findForward ( SUCCESS );
    }
}

I'm using the following webdoclet target in my build file:


 <target name="xdoclet" depends="init">
        <webdoclet 
         destdir="${gen.dir}/WEB-INF" 
         mergedir="${merge.dir}"
        >
         <fileset dir="${web.dir}" includes="**/*.java" />
                
         <deploymentdescriptor 
          servletspec="${servlet.spec.version}"
         >
          <taglib
                    uri="struts-bean"
                    location="/WEB-INF/struts-bean.tld"
                />
          <taglib
                    uri="struts-html"
                    location="/WEB-INF/struts-html.tld"
                />
          <taglib
                    uri="struts-logic"
                    location="/WEB-INF/struts-logic.tld"
                />
          <taglib
                    uri="struts-nested"
                    location="/WEB-INF/struts-nested.tld"
                />
            </deploymentdescriptor>
            
            <strutsconfigxml validatexml="true" version="1.1"/>
            <strutsvalidationxml />
        </webdoclet>
 </target> 



It builds my validation.xml file as follows:

<form-validation>
  <!--
    Define global validation config in validation-global.xml
  -->
  <formset>
      <form name="validateForm">
              <field property="creditCard"
                     depends="required,creditCard">

                  <arg0 key="validateForm.creditCard"/>
              </field>
      </form>
  </formset>
</form-validation>

but when I deploy, I get an error:

Cannot retrieve definition for form bean validateForm

All other forms and actions in my project work fine, but none 
of them user the validation package. The first difference I see 
is that no definition for my ValidateForm has been created in 
my struts-config.xml file, whereas for all the other forms, they 
have been generated.

Any tips?

I know this is a struts list and so if no-one is using xdoclet then 
I'll ask on the xdoclet list instead.
thanks very much,
Brian