struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aftab Vhora <aftab.vh...@oracle.com>
Subject Re: Dynamically Generated html:Text
Date Tue, 19 Sep 2006 05:52:16 GMT
Hi,

Somehow I was able to generate text boxes dynamically here is wht i did

==============struts-config.xml===============
<struts-config>
  <form-beans>
    <form-bean name="myForm" 
type="org.apache.struts.action.DynaActionForm" size="4">
      <form-property name="lines" type="com.biz.myMapForm[]" />
    </form-bean>
  </form-beans>
  <action-mappings>
    <action path="/process" type="com.biz.myAction" name="myForm"  
scope="request">
      <forward name="success" path="/test.jsp" />
    </action>
  </action-mappings>
  <message-resources parameter="nwprj.ApplicationResources"/>
</struts-config>

============Action Form myMapForm.java================
public class myMapForm extends ActionForm
{
  private String name="";
  private String phone="";
 
  public void setName(String nm)    { this.name=nm; }
  public void setPhone(String ph)    { this.phone=ph; }
 
  public String getName()    { return this.name; }
  public String getPhone()    { return this.phone; }
 
}

===========My JSP(test.jsp)====================

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; 
charset=windows-1252"/>
    <title></title>
  </head>
  <body><html:form action="process" >
      <c:forEach var="lines" items="${myForm.map.lines}">
        Name <html:text property="name" indexed="true" name="lines" /> 
Phone <html:text property="phone" indexed="true" name="lines" /> <br>
      </c:forEach>
      <html:submit value="Submit" />
    </html:form></body>
</html>

===========================================================
But the  problem is, it is generating only 4+4=8 texboxes as specified 
in my struts-config.xml file size="4" ,  But I want it to be generated 
dynamically, Say, user wants to enter 6 entry of name and phone then it 
should generate 6+6 text boxes.

Is there any solution exist ??

Thanks & Regards,
Aftab Vhora




Puneet Lakhina wrote:

> On 9/18/06, Aftab Vhora <aftab.vhora@oracle.com> wrote:
>
>>
>> Hi,
>>
>> I m dynamically generating the html:text , i have made correct entry in
>> the struts config.xml and also implemented the Action Form and Action
>> class.
>>
>> But I m getting below error, request you to kindly provide me the
>> solution.
>>
>> ===========ERROR============
>>
>> javax.servlet.jsp.JspException: No getter method for property txt1 of
>> bean org.apache.struts.taglib.html.BEAN
>> at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:968)
>> at
>> org.apache.struts.taglib.html.BaseFieldTag.doStartTag(BaseFieldTag.java
>> :176)
>> at _test._jspService(_test.java:63)
>> [/test.jsp]
>> .................
>>
>> =====action form=========
>> public class myMapForm extends ActionForm
>> {
>>   private final Map values = new HashMap();
>>
>>       public void setTxt(String key, Object value) {
>>           values.put(key, value);
>>       }
>>
>>       public String getTxt(String key) {
>>           return (String)values.get(key);
>>       }
>>
>> }
>>
>> ========JSP file(test.jsp)=============
>>
>> <html>
>>   <head>
>>     <meta http-equiv="Content-Type" content="text/html;
>> charset=windows-1252"/>
>>     <title>Google Client</title>
>>   </head>
>>   <body>
>>   <html:form action="process">
>>      <%
>>      for(i=0;i<1;i++)
>>      %>
>>      <html:text property='<%="txt" + i %>' />
>
>
>
> The above line is incorrect. It should be <html:text 
> property='<%="txt(" + i
> +")"%>' /> .
>
>  </html:form>
>
>>     </body>
>> </html>
>>
>>
>> -- 
>> Thanks & Regards,
>> Aftab Vhora
>> Oracle India Pvt Ltd,
>> Cell-9880 311 391
>>
>>
>>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message