Hi,
I am having a problem using the display tag. The table fields which i am editing on the jsp are not reflecting in the action class.But if i edit a form field which is not in the table its reflecting in the action class. I think i am missing something some where. All the values are being correctly displayed in the text boxes. But any editing is not having any effect on the actual form variables. Since i have no data base connection i am populating the values for the table in the action class.If i use an logic:iterate tag instead of display tag for the table everything is working fine.The fields i edit get reflected in the actual form variables. Please go through the code. And i would be gratefull if u could tell me where i am goin wrong.
regards
rahul
This is My Form:
public
class DisplayForm extends ActionForm{
private String nameForm;
private ArrayList tabList = new ArrayList(3);
private ArrayList tabRow = new ArrayList();
public void reset(ActionMapping mapping, HttpServletRequest request) {
for(int i =0 ; i < 3; i++)
{
DisplayBean x = (DisplayBean)getTabRow(i);
x.setCheck(false);
}
// Reset field values here.
}
/**
* @return
*/
public String getNameForm() {
return nameForm;
}
/**
* @return
*/
public ArrayList getTabList() {
return tabList;
}
/**
* @param string
*/
public void setNameForm(String string) {
nameForm = string;
}
/**
* @param list
*/
public void setTabList(ArrayList list) {
tabList = list;
}
public DisplayBean getTabRow(final int index) {
//If an instance corresponding to the index is not present
//then expand the list to create the bean instance
while (index >= tabList.size()) {
tabList.add(tabList.size(),
new DisplayBean());
}
return ( DisplayBean ) tabList.get(index);
}
/**
* @param string
*/
public void setTabRow(final int index, final Object object) {
DisplayBean displayBean =
( DisplayBean ) object;
//If an instance corresponding to the index is not present
//then expand the list to create the bean instance
while (index >= tabList.size()) {
tabList.add(tabList.size(),
new DisplayBean());
}
tabList.set(index, displayBean);
}
}
This Is my class for tne table:
public class DisplayBean implements Serializable{
private String name;
private String age;
private String email;
private boolean check;
/**
* @return
*/
public String getAge() {
return age;
}
/**
* @return
*/
public String getEmail() {
return email;
}
/**
* @return
*/
public String getName() {
return name;
}
/**
* @param string
*/
public void setAge(String string) {
age =
string;
}
/**
* @param string
*/
public void setEmail(String string) {
email = string;
}
/**
* @param string
*/
public void setName(String string) {
name = string;
}
/**
* @return
*/
public boolean isCheck() {
return check;
}
/**
* @param b
*/
public void setCheck(boolean b) {
check = b;
}
}
This is my Action Class
public class DisplayAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
DisplayForm Form = (DisplayForm)form;
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
DisplayBean displayBean = null;
ArrayList rowTab = new ArrayList();
for(int count=0;count<3;count++)
{
displayBean = new DisplayBean();
displayBean.setName("rahul"+count);
displayBean.setAge("1"+count);
displayBean.setEmail("gsgaf@"+count);
rowTab.add(count,displayBean);
}
Form.setTabList(rowTab);
request.setAttribute("id",Form);
forward = mapping.findForward("success");
// return value
try {
// do something here
} catch (Exception e) {
// Report the error using the appropriate name and ID.
errors.add("name", new ActionError("id"));
}
// If a message is required, save the specified key(s)
// into the request for use by the <struts:errors> tag.
if (!errors.isEmpty()) {
saveErrors(request, errors);
// Forward control to the appropriate 'failure' URI (change name as desired)
// forward = mapping.findForward("failure");
} else {
// Forward control to the appropriate 'success' URI (change name as desired)
// forward = mapping.findForward("success");
}
// Finish with
return (forward);
}
}
This is the body of my Jsp Page:
<BODY>
<html:form action="">
<html:text property="nameForm"></html:text>
<%request.getAttribute("id");%>
<display:table id="tabRow" property="tabList" name="id" class="list">
<display:column>
<html:text name="tabRow" property="name" ></html:text>
</display:column>
<display:column>
<html:text name="tabRow" property="age" ></html:text>
</display:column>
<display:column>
<html:text name="tabRow" property="email" ></html:text>
</display:column>
<display:column>
<html:checkbox name="tabRow" property="check" ></html:checkbox>
</display:column>
</display:table>
<html:submit/>
</html:form>
</BODY>
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1¢/min.

