You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Hohlen, John" <JH...@erac.com> on 2002/09/27 20:53:59 UTC

HELP!: Pre-populating A DynaValidatorForm in Struts 1.1 B2

Does anyone know how to instantiate a "DynaValidatorForm" declared in the
"validation.xml" file within Java code?

  <formset>   
    <form name="employeeForm">
      <field property="emailAddress"
             depends="required,email">
        <arg0 key="general.emailAddress"/>       
      </field>
      <field property="anniversaryDate"
             depends="required,date">
        <arg0 key="general.anniversaryDate"/>
        <var>
          <var-name>datePatternStrict</var-name>
          <var-value>MM/dd/yyyy</var-value>
        </var>
      </field>
   </form>            
 </formset>   

More specifically, I want this form, used by my JSP, to contain
pre-populated data from the database.  Therefore, it is desired to have my
action to instantiate the form bean and pre-populate it -- versus letting
the Struts framework create one with default values.  In Struts 1.0, I just
did the following in my action:

 EmployeeForm employeeForm = new EmployeeForm();

But this won't work using dyna forms in Struts 1.1 since there is no
"EmployeeForm" Java class.

Thanks!


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: HELP!: Pre-populating A DynaValidatorForm in Struts 1.1 B2

Posted by Eddie Bush <ek...@swbell.net>.
John,

What you need to do is pre-face the page with a "populate" action.  This 
action (see comment below) casts the form to a DynaValidatorForm and 
then calls form.set("property", value) for each property you need to 
set.  Once this is done, you just forward to the JSP.  This works :-) 
 If it doesn't work for you, it's a mistake or a bug.  Let us know if 
you're unable to get it working still ...

Hohlen, John wrote:

>Does anyone know how to instantiate a "DynaValidatorForm" declared in the
>"validation.xml" file within Java code?
>
>  <formset>   
>    <form name="employeeForm">
>      <field property="emailAddress"
>             depends="required,email">
>        <arg0 key="general.emailAddress"/>       
>      </field>
>      <field property="anniversaryDate"
>             depends="required,date">
>        <arg0 key="general.anniversaryDate"/>
>        <var>
>          <var-name>datePatternStrict</var-name>
>          <var-value>MM/dd/yyyy</var-value>
>        </var>
>      </field>
>   </form>            
> </formset>   
>
>More specifically, I want this form, used by my JSP, to contain
>pre-populated data from the database.  Therefore, it is desired to have my
>action to instantiate the form bean and pre-populate it -- versus letting
>the Struts framework create one with default values.
>
No, no.  Actions/Forms have a contract -- the form *will* be created. 
 You should not take this upon yourself.  Expect it to be there -- if it 
is not NPE and fail-fast (and submit a bug report!).

>In Struts 1.0, I just
>did the following in my action:
>
> EmployeeForm employeeForm = new EmployeeForm();
>
>But this won't work using dyna forms in Struts 1.1 since there is no
>"EmployeeForm" Java class.
>
>Thanks!
>

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>