I think you want a mapped backed property.

Here is an example:

     <form-bean name="userRegistrationDynaForm"
type="org.apache.struts.validator.DynaValidatorForm">
         <form-property name="userName" type="java.lang.String" />
         <form-property name="email" type="java.lang.String" />
         <form-property name="password" type="java.lang.String" />
         <form-property name="passwordCheck" type="java.lang.String" />
         <form-property name="firstName" type="java.lang.String" />
         <form-property name="lastName" type="java.lang.String" />
         <form-property name="phone" type="java.lang.String" initial="(520)
" />
         <form-property name="fax" type="java.lang.String" />
         <form-property name="page" type="java.lang.Integer" />
         <form-property name="birthDate" type="java.lang.String" />
         <form-property name="zip" type="java.lang.String" />
         <form-property name="dynamicProps" type="java.util.HashMap" />
<---SEE THIS

      </form-bean>
See dynamicProps above.

You can access the dynamic field like so:

      <tr>
        <td>
          Dyna Prop Bar
        </td>
        <td>
          <html:text property="dynamicProps(bar)" />
        </td>
      </tr>
      <tr>
        <td>
          Dyna Prop Foo
        </td>
        <td>
          <html:text property="dynamicProps(foo)" />
        </td>
      </tr>



Here is the full JSP form for the above:

    <table>
    <html:form action="userRegistrationDyna" onsubmit="return validateUser
(this)">
      <tr>
        <td>
          <bean:message key="userRegistration.firstName" />*
        </td>
        <td>
          <html:text property="firstName" />
        </td>
      </tr>
        <td>
          <bean:message key="userRegistration.lastName" />*
        </td>
        <td>
          <html:text property="lastName" />
        </td>
      <tr>
        <td>
          <bean:message key="userRegistration.userName" />*
        </td>
        <td>
          <html:text property="userName" />
        </td>
      </tr>
      <tr>
        <td>
          <bean:message key="userRegistration.email" />*
        </td>
        <td>
          <html:text property="email" />
        </td>
      </tr>
      <tr>
        <td>
          <bean:message key="userRegistration.phone" />
        </td>
        <td>
          <html:text property="phone" />
        </td>
      </tr>
      <tr>
        <td>
          <bean:message key="userRegistration.fax" />
        </td>
        <td>
          <html:text property="fax" />
        </td>
      </tr>
      <tr>
        <td>
          <bean:message key="userRegistration.password" />*
        </td>
        <td>
          <html:password property="password" />
        </td>
      </tr>
      <tr>
        <td>
          <bean:message key="userRegistration.password" />*
        </td>
        <td>
          <html:password property="passwordCheck" />
        </td>
      </tr>

      <tr>
        <td>
          <bean:message key="userRegistration.birthDate" />*
        </td>
        <td>
          <html:text property="birthDate" />
        </td>
      </tr>
      <tr>
        <td>
          <bean:message key="userRegistration.zip" />*
        </td>
        <td>
          <html:text property="zip" />
        </td>
      </tr>
      <tr>
        <td>
          Dyna Prop Bar
        </td>
        <td>
          <html:text property="dynamicProps(bar)" />
        </td>
      </tr>
      <tr>
        <td>
          Dyna Prop Foo
        </td>
        <td>
          <html:text property="dynamicProps(foo)" />
        </td>
      </tr>

      <html:hidden property="page" value="2"/>

      <tr>
        <td>
          <html:submit />
        </td>
        <td>
          <html:cancel  onclick="bCancel=true"/>
        </td>
      </tr>




Rick Hightower
Developer

Struts/J2EE training -- http://www.arc-mind.com/strutsCourse.htm

Struts/J2EE consulting --
http://www.arc-mind.com/consulting.htm#StrutsMentoring

-----Original Message-----
From: Janice [mailto:[EMAIL PROTECTED]
Sent: Friday, January 16, 2004 10:03 AM
To: [EMAIL PROTECTED]
Subject: Issues when reusing a DynaValidatorForm


I have a simple DynaValidatorForm (just 3 items: name, description, action)
that is reused
for several forms.

The issue that I'm having is that the names of the form elements might be
different from one form to the next.  For example, on one page the 'name'
might be called 'Project Code' and on another page it might be 'widget Short
Name' and so on.  So far I'm writing out distinct .jsp pages for each form,
because I can't seem to get around having to do: <bean:message
key="projectCode.desc"/> and <bean:message key="widget.desc"/>.

Is there a way to pass in some variable to the bean tag so that I can define
the variable once such as:
<bean:message key="<%= control %>.desc"/>?  So far I haven't found anything
that works.

Also, when I am using validation on my form, is there anything I can do to
get the page-specific text to appear in my error messages?  I bet someone's
going to complain if I use a really generic description of name and
description.

Thanks in advance,
Janice


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to