Discussions

General J2EE: array of classes in DynaValidatorForm

  1. array of classes in DynaValidatorForm (1 messages)

    Hi all,

    I have a DynaValidatorForm(dynaForm1) with two String properties and
    one array of classes(Khd1[]) from a <input name="q1"> in iterate.
    In app1.jsp first I get list of
    objects(qList) with "Khd1" type from 3 tables, it returns correct values,
    and In app1.java address1,address2 have correct values
    and array of class of form is not empty but each property of each object
     is null(like ((Khd1)q[0]).getQid())).
    I don't know is this way correct to bind dynaForm1 to properties in
    app1.jsp
    <logic:iterate id="q" name="qList" scope="request" type="general.Khd1" >
    , does anyone know why objects have no values.


    Thanks in advance.

    ____________struts-config___________
    <form-bean
        name="dynaForm1"
        type="org.apache.struts.validator.DynaValidatorForm">
        <form-property
            name="address1"
            type="java.lang.String" />

       <form-property
            name="address2"
            type="java.lang.String" />


       <form-property
            name="khd"
            type="general.Khd1[]" size="4" />
    </form-bean>


            <action
               path="/app1"
               type="general.App1"
               name="dynaForm1"
               scope="session"
               input="/pages/app1.jsp"
    parameter="method">
               <forward name="success2" path="/pages/app2.jsp" />
               <forward name="success1" path="/pages/app1.jsp" />
             </action>

    _______________app1.java______

     public ActionForward reCalculate(ActionMapping mapping,
              ActionForm form,
              HttpServletRequest request,
              HttpServletResponse response)
              throws IOException, ServletException {

    DynaValidatorForm dynaFrm= (DynaValidatorForm) form ;
            Khd1[] q = (Khd1[])dynaFrm.get("khd") ;


    if(q==null) // q is not null.
    System.out.println("q is null");

         System.out.println((String)dynaFrm.get("address2")) ;// it returns correct value.

     
    System.out.println((Long)(((Khd1)q[0]).getQid()));//print null

         
          return mapping.findForward("success1");
      }


    _______________app1.jsp________

    List qList = UserService.getInstance().getQList (username);
    request.setAttribute("qList", qList);




     <logic:iterate id="q" name="qList" scope="request" type="general.Khd1" >
    <tr>

    <html:hidden name="q" property="qid"/>

    <td><bean:write name="q" property="product_id" /></TD>
    <td><bean:write name="q" property="name" /></TD>
    <td>
    <input name="q1" value="<bean:write name="q" property="q"/>" size="20" ></TD>


    <td><bean:write name="q" property="price" /></TD>
    <td></TD>
    </tr>

    </logic:iterate>
    ...
    <TR>Address 1</TD><TD ><INPUT size=50 name=address1 value="<bean:write name="user" property="address_1" />" > </TD></TR>
    <TR>Address 2</TD><TD ><INPUT size=50 name=address2 value="<bean:write name="user" property="address_2" />" > </TD></TR>
    ...
  2. Hi all,

    also it makes no different with DaynaActionForm
    Please help if you know somthing useful.

    Thanks.