Iterating List object in a JSP whose value coming from ViewAction class which is displaying proper.
Below is the jps code.
<s:iterator value="beanList" status="stat">
<tr>
<td>
<input type="checkbox" name="subCheckBox" />
</td>
<td>
<s:textfield name="beanList[%{#stat.index}].rollnumber"
value="%{rollnumber}" theme="simple"/>
</td>
<td>
<s:textfield name="beanList[%{#stat.index}].name"
value="%{name}" theme="simple"/>
</td>
<td>
<s:textfield name="beanList[%{#stat.index}].location"
value="%{location}" theme="simple"/>
</td>
</tr>
</s:iterator>
ViewAction.java and Bean class code is as follows
In the action class list object name is beanList
public class ViewCheckboxAction extends ActionSupport {
HttpServletRequest request = ServletActionContext.getRequest();
String viewData = "select * from student order by rollno";
List<Bean> beanList;
public List<Bean> getBeanList() {
return beanList;
}
public void setBeanList(ArrayList<Bean> beanList) {
this.beanList = beanList;
}
public String execute() {
beanList = new ArrayList<Bean>();
DbConnection db = new DbConnection();
int counter = 0;
try {
Statement st = db.getConnection().createStatement();
ResultSet res = st.executeQuery(viewData);
while(res.next()) {
counter++;
Bean bean = new Bean(res.getInt(1),
res.getString(2),
res.getString(3));
rollNumber.add(res.getString("rollno"));
beanList.add(bean);
}
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
db.removeConnection();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(counter>0)
return SUCCESS;
else
return ERROR;
}
}
Bean:
public class Bean {
int rollnumber;
String name;
String location;
public Bean(int x, String y, String z) {
rollnumber = x;
name = y;
location = z;
}
getters and setters...
I need the multiple/single updated form field value from jsp to action class in order to do the updated operation. But the list(beanList) value is nullified in the action class. Since it is nullified i can not do the update operation. 1)In the new action class(EditAction.java) how to initialise the list object(beanList) ? It is the same way as i declare in ViewAction.java 2)Is the Jsp sysntax is proper ? Request you to help on this. Thanks in advance.