Where The Streets Have No Name

multi row input form 본문

Developement/Java

multi row input form

highheat 2007. 9. 21. 19:04

First define a Bean called StudentGrades:

Package example;

public StudentGrades {
   private String name, biology, chemistry, physics, english, math;

   public String getName () { return this.name; }
   public String getBiology () { return this.biology; }
   public String getChemisty () { return this.chemistry; }
   public String getPhysics () { return this.physics; }
   public String getEnglish () { return this.english; }
   public String getMath () { return this.math; }

   public void setName (String name) { this.name = name; }
   public void setBiology (String grade) { this.biology = grade; }
   public void setChemisty (String grade) { this.chemistry = grade; }
   public void setPhysics (String grade) { this.physics = grade; }
   public void setEnglish (String grade) { this.english = grade; }
   public void setMath (String grade) { this.math = grade; }
}

In your struts-config.xml, define:

<form-bean  name="studentGradeForm"
            type="org.apache.struts.validator.DynaValidatorForm">
   <form-property name="grades" type="example.StudentGrades[]" size="50">
</form-bean>

Then, presuming that your Action populates the StudentGrades array with
the student names, in your JSP, you'd say:

<html:form action="/some/action">
<TABLE>
 <TR>
  <TD>Name</TD>
  <TD>Biology</TD>
  <TD>Chemistry</TD>
  <TD>Physics</TD>
  <TD>English</TD>
  <TD>Math</TD>
 </TR>
 <logic:iterate id="student" name="studentGradeForm" property="grades" type="example.StudentGrades">
 <logic:notEmpty name="student" property="name">
 <TR>
  <TD><bean:write name="student" property="name" indexed="true"/></TD>
  <TD><html:text name="student" property="biology" indexed="true"/></TD>
  <TD><html:text name="student" property="chimstry" indexed="true"/></TD>
  <TD><html:text name="student" property="physics" indexed="true"/></TD>
  <TD><html:text name="student" property="english" indexed="true"/></TD>
  <TD><html:text name="student" property="math" indexed="true"/></TD>
 </TR>
 </logic:notEmpty>
 </logic:iterate>
</TABLE>


http://www.oracle.com/technology/products/jdev/tips/mills/JSP_Multi_Row_Edits.html