I have a jsp in my struts app that displays data from a table. I can edit any field in each record, but when I submit, none of the records are captured in the FormBean to be processed by the ActionBean. The data elements are nulls. How can I make all records from a jsp forward to the FormBean so it will validate and my action can update the database? I'd even settle for only record from the list being selected and forwarded for update action. I'm attaching my jsp and my Form code. Thanks in advance for any help on this.
////// THE JSP //////
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%-- JSTL tag libs --%>
<%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld" %>
<%-- Struts provided Taglibs --%>
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld" %>
<%@ taglib prefix="logic" uri="/WEB-INF/struts-logic.tld" %>
<%@ taglib prefix="bean" uri="/WEB-INF/struts-bean.tld" %>
<html>
<head>
<fmt:setBundle basename="ApplicationResources" />
<title><fmt:message key="adcnPartU.title"/></title>
</head>
<body>
<html:errors property="adcnPartU"/>
<html:form action="adcnPartU.do">
<logic:notPresent name = "allRcds">
<h2>Data source not in scope!</h2>
<html:submit>
<fmt:message key="adcnPartU.button.load"/>
</html:submit>
</logic:notPresent>
<logic:present name = "allRcds">
<logic:empty name = "allRcds">
<h2>Data source in scope, but no data found!</h2>
</logic:empty>
</logic:present>
<logic:present name = "allRcds">
<p><b> ADCN PART TABLE </b></p>
<html:submit>
<fmt:message key="adcnPartU.button.select"/>
</html:submit>
<table border="1">
<thead>
<tr>
<th>Doc_no_i</th>
<th>Part_no_i</th>
<th>Actn_c</th>
<th>Cls1_c</th>
<th>Ndx1_i</th>
<th>Std_part_i</th>
<th>Part_nomen_i</th>
<th>Cage_i</th>
<th>Part_q</th>
<!-- th>SELECT<th -->
</tr>
</thead>
<tbody>
<logic:iterate id="theRecords" name="allRcds">
<tr>
<td><input type="int" indexed="true" name="Doc<bean:write name='theRecords' property='record_no' />" property="doc_no_i" value="<bean:write name='theRecords' property='doc_no_i' />" /></td>
<td><input type="int" indexed="true" name="Part<bean:write name='theRecords' property='record_no' />" property="part_no_i" value="<bean:write name='theRecords' property='part_no_i' />" /></td>
<td><input type="text" indexed="true" name="Act<bean:write name='theRecords' property='record_no' />" property="actn_c" value="<bean:write name='theRecords' property='actn_c'/>" size="2" maxlength="2" /></td>
<td><input type="text" indexed="true" name="Cls<bean:write name='theRecords' property='record_no' />" property="cls1_c" value="<bean:write name='theRecords' property='cls1_c'/>" size="2" maxlength="2" /></td>
<td><input type="text" indexed="true" name="Ndx<bean:write name='theRecords' property='record_no' />" property="ndx1_i" value="<bean:write name='theRecords' property='ndx1_i'/>" size="5" maxlength="5" /></td>
<td><input type="text" indexed="true" name="Std<bean:write name='theRecords' property='record_no' />" property="std_part_i" value="<bean:write name='theRecords' property='std_part_i'/>" size="15" maxlength="15" /></td>
<td><input type="text" indexed="true" name="Pnom<bean:write name='theRecords' property='record_no' />" property="part_nomen_e" value="<bean:write name='theRecords' property='part_nomen_e'/>" size="15" maxlength="15" /></td>
<td><input type="text" indexed="true" name="cag<bean:write name='theRecords' property='record_no' />" property="cage_i" value="<bean:write name='theRecords' property='cage_i'/>" size="15" maxlength="15" /></td>
<td><input type="int" indexed="true" name="pq<bean:write name='theRecords' property='record_no' />" property="part_q" value="<bean:write name='theRecords' property='part_q'/>" /></td>
<!-- td colspan="1" align="center">
<html:submit>
<fmt:message key="adcnPartU.button.select"/>
</html:submit>
</td -->
</tr>
</logic:iterate>
</tbody>
</table>
</logic:present>
</html:form>
</body>
</html>
////// THE FORM /////
package adcn;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* @author Cary Buchanan
*/
public class AdcnPartForm extends ActionForm
{
private static final long serialVersionUID = 1L;
//private Vector vec=null;
private Integer record_no;
private Integer doc_no_i;
private Integer part_no_i;
private String actn_c;
private String cls1_c;
private String ndx1_i;
private String std_part_i;
private String part_nomen_e;
private String cage_i;
private Integer part_q;
/**
* Resets data fields to initial values on loginform
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request)
{
// Gotta be some rules. Like Can't reset DOC_NO_I and other fields?
actn_c = "";
std_part_i = "";
//vec=null;
// MAke this function go back to record number one from the bean.
}
/**
* Performs validation of data on loginform
* @param mapping
* @param request
* @return ActionErrors
*/
//Probably not needed here, since this is just a view.
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
// Put
System.out.println("Validating field data!");
ActionErrors errors = new ActionErrors();
// put in some code to check questionable data / nulls, etc.
HttpSession session = request.getSession();
Vector sData = (Vector)session.getAttribute("allRcds");
if (sData != null) {
System.out.println("Session vector captured!");
if( doc_no_i == null || (doc_no_i.intValue() == 0)){
System.out.println("doc_no_i is null!");
errors.add("doc_no_i", new ActionError("error.doc_no_i.required"));
}
return errors;
}
return errors;
}
/**
* @return String - Attribute Accessors
*/
public String getActn_c() {
return actn_c;
}
public void setActn_c(String actn_c) {
this.actn_c = actn_c;
}
public String getCage_i() {
return cage_i;
}
public void setCage_i(String cage_i) {
this.cage_i = cage_i;
}
public String getCls1_c() {
return cls1_c;
}
public void setCls1_c(String cls1_c) {
this.cls1_c = cls1_c;
}
public Integer getDoc_no_i() {
return doc_no_i;
}
public void setDoc_no_i(Integer doc_no_i) {
this.doc_no_i = doc_no_i;
}
public String getNdx1_i() {
return ndx1_i;
}
public void setNdx1_i(String ndx1_i) {
this.ndx1_i = ndx1_i;
}
public Integer getPart_no_i() {
return part_no_i;
}
public void setPart_no_i(Integer part_no_i) {
this.part_no_i = part_no_i;
}
public String getPart_nomen_e() {
return part_nomen_e;
}
public void setPart_nomen_e(String part_nomen_e) {
this.part_nomen_e = part_nomen_e;
}
public Integer getPart_q() {
return part_q;
}
public void setPart_q(Integer part_q) {
this.part_q = part_q;
}
public String getStd_part_i() {
return std_part_i;
}
public void setStd_part_i(String std_part_i) {
this.std_part_i = std_part_i;
}
public Integer getRecord_no() {
return record_no;
}
public void setRecord_no(Integer record_no) {
this.record_no = record_no;
}
public String toString() {
return doc_no_i.toString() + part_no_i.toString() + actn_c + cls1_c + ndx1_i + std_part_i + part_nomen_e+ cage_i+part_q.toString();
}
//public Vector getVec() {
// return vec;
//}
//public void setVec(Vector vec) {
// this.vec = vec;
//}
}
Please try using <html:text> tag to replace <input> tag.