I need help figuring out how to generate and use dynamic forms with Struts.

Is there already an eloquent MVC solution in Struts?

Is DynaActionForm the answer?

I can't see how extending the ActionForm behavior accomplishes this.  It
seems that to really implement a dynamic form, the form Bean would need to
be defined and instantiated at run-time, based on the HttpResponse generated
by the forms JSP.

For example:

Say the JSP for looks like the following:

<%-- myDynamic.jsp --%>
<html:form action="/work">

<logic:iterate id="y" name="a" property="b"/>
<html:text>
        property="x-"<bean:write name="y" property="z"/>
</html:text>
</logic:iterate>

</html:form>

This will not work since "property" is required in the <html:text> tag.
However, if it did work, then it seems there would need to be some Action
that gets the HttpResponse from "myDynamic.jsp" and generates the source
(Java) form definition, e.g.:

// MyDynamicAction.java
...

for(Iterator i = A.iterator(); i.hasNext;)
 a = i.next();
 buffer.append("public setX-" +  a.getB() + "(String s) { ");
 buffer.append("  x-" + a.getB() + " = s ;");

...

And, then compiles and instantiates it.

Does this make any sense, whatsoever?  If I'm completely lost, then someone
please try and help point me in the right direction.


I got the JSP, found below,  to work within my application for implementing
dynamic forms.  The HTML <select>'s are "named" dynamically with Struts
<bean:write>'s, all within <logic:iterate>.  The Action that handles this
form processes the HttpServletRequest, filtering for parameters names that
start with the constant values, e.g.  "withholdingAmount_".  Since the
"names" in each row of the iteration are suffixed with the same key, e.g.
countyNumber-caseNumber, the parameters can be associated and processed
accordingly in the Action.

While this works, I get the feeling I'm re-inventing the wheel.  Is there a
100% Struts technique that renders this type of dynamicism? Any thoughts are
greatly appreciated.

Thanks,

Michael Marrotte

 <logic:iterate id="payerCase" name="payer" property="payerCases">
    <app:row  oddColor="white" evenColor="#eeeeee"
styleClass="regtextdetails">
      <td align="left">
        <bean:write name="payerCase" property="countyName" filter="true"/>
      </td>
      <td align="left" nowrap>
        <bean:write name="payerCase" property="caseNumber" filter="true"/>
      </td>
      <td align="center">
        <bean:write name="payerCase" property="petitioner" filter="true"/>
      </td>
      <td align="center">
        <bean:write name="payerCase" property="respondent" filter="true"/>
      </td>
      <td nowrap>
        <select name="withholdingMonth_<bean:write name="payerCase"
property="countyNumber">-<bean:write name="payerCase"
property="caseNumber"/>">
          <option value="01">January</option>
          <option value="02">February</option>
...
        </select>/
        <select name="withholdingDay_<bean:write name="payerCase"
property="countyNumber">-<bean:write name="payerCase"
property="caseNumber"/>">
          <option value="01">1</option>
          <option value="02">2</option>
...
        </select>/
        <input type="text" name=
          "withholdingYear_<bean:write name="payerCase"
property="countyNumber" filter="true"/>-<bean:write name="payerCase"
property="caseNumber" filter="true"/>"
           size="4" maxlength="4">
      </td>
      <td align="right">
        $<input type="text" name=
"amount_<bean:write name="payerCase" property="countyNumber"/>-<bean:write
name="payerCase" property="caseNumber"/>"
        value=<bean:write name="payerCase" property="withholdingAmount"
filter="true"/> size="10" maxlength="10">
      </td>
    </app:row>
  </logic:iterate>

-----Original Message-----
From: veenak [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 15, 2002 10:41 PM
To: [EMAIL PROTECTED]
Subject: Require sample code for Dynamic Forms


Hi All,

I am developing an application which requires the generation of forms
dynamically.
My Form bean class is extending from "DynaActionForm " class.
Currently my application is not working and I am getting an exception
"javax.servlet.ServletException: Exception creating bean of class
FormBean{1}"

I need more information about the  implementing  "DynaActionForm "
class and
also about writing the Dynamic Form jsp file.

Can any one please help me  with set of sample code or the URL that has
example
for implementing the Dynamic forms.

Regards
Veena




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


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

Reply via email to