wood burning stoves 2.0*
The moose likes Struts and the fly likes Unable to get the modified value from Struts 1.2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Unable to get the modified value from Struts 1.2" Watch "Unable to get the modified value from Struts 1.2" New topic
Author

Unable to get the modified value from Struts 1.2

dhaya nidhi
Greenhorn

Joined: Nov 05, 2009
Posts: 4
Hello,

I've a problem in reading the value modified in Text box in Struts1.2.

Action Form:
==============

public class ResellerForm extends ActionForm{

private String name;
List<ResellerBeanByVendor> byVendorList;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<ResellerBeanByVendor> getByVendorList() {
return byVendorList;
}

public void setByVendorList(List<ResellerBeanByVendor> byVendorList) {
this.byVendorList = byVendorList;
}

}


public class ResellerBeanByVendor implements Serializable{

String vendorName;
List<ResellerBean> resellerBeanList;
public String getVendorName() {
return vendorName;
}
public void setVendorName(String vendorName) {
this.vendorName = vendorName;
}
public List<ResellerBean> getResellerBeanList() {
return resellerBeanList;
}
public void setResellerBeanList(List<ResellerBean> resellerBeanList) {
this.resellerBeanList = resellerBeanList;
}

}

public class ResellerBean implements Serializable{

private String email;

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}
}

Action Class
==================
public class ResellerAction extends Action{


@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

String action = request.getParameter("action");
ResellerForm resellerForm = (ResellerForm)form;
System.out.println("action="+action);
if("view".equalsIgnoreCase(action) || action == null){
ResellerBeanByVendor byVendor = new ResellerBeanByVendor();
byVendor.setVendorName("v1");
ResellerBean resellerBean = new ResellerBean();
resellerBean.setEmail("email1");
List<ResellerBean> resellerBeanList = new ArrayList<ResellerBean>();
resellerBeanList.add(resellerBean);
byVendor.setResellerBeanList(resellerBeanList);
List<ResellerBeanByVendor> byVendorList = new ArrayList<ResellerBeanByVendor>();
byVendorList.add(byVendor);
resellerForm.setByVendorList(byVendorList);
}else if("edit".equalsIgnoreCase(action)){
List<ResellerBeanByVendor> byVendorList =resellerForm.getByVendorList();
for(ResellerBeanByVendor byVendor:byVendorList){
System.out.println("Name="+byVendor.getVendorName());
List<ResellerBean> resellerBeanList = byVendor.getResellerBeanList();
for(ResellerBean resellerBean:resellerBeanList){
System.out.println("resellerBean="+resellerBean.getEmail());
}
}
}
return mapping.findForward("success");
}

}


Jsp
====
<%@page import="java.util.ArrayList"%>
<%@page import="com.reseller.ResellerForm"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page import="com.reseller.ResellerForm" %>
<%@ page import="java.util.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Reseller Page</title>
</head>
<body>
<logic:present name="ResellerForm" property="byVendorList">
<html:form action="/reseller?action=edit">

<logic:iterate id="byVendorList" name="ResellerForm" property="byVendorList" indexId="j">
<bean:write name="byVendorList" property="vendorName" />
<logic:iterate id="resellerBeanList" name="byVendorList" property="resellerBeanList" indexId="i">
<html:text name="resellerBeanList" value="${byVendorList.resellerBeanList[i].email}" property="email" indexed="true"/>
</logic:iterate>
</logic:iterate>
<html:submit >SAVE</html:submit>
</html:form>
</logic:present>
</body>
</html>


Url to access:
==========
http://localhost:8080/StrutsLoginApp/reseller.do?action=view

WHen my action is view, i'm displaying the value in text box but when action is edit i.e. if i click the button
what ever the value i'm entering in the text box is not able to retreive in the action class.

Reason for having this complex structure of action form is the business requirement which is already implemented for view.So now i have to implement it for edit.
So i can't modify the bean struture.Kindly help me.

I'm in deep trouble.Please suggest the solution.

Thanks well in advance.

 
Consider Paul's rocket mass heater.
 
subject: Unable to get the modified value from Struts 1.2