Struts : Using Logic Iterate but not getting the updated list value in Action
I am developing a application which reads a XML , The values of these XML are set in a "Object" (consumerXML) and that object is set in a list and list will be set in session , Key being "results"
request.setAttribute("results", list)
The Flow is like this
- Welcome.JSP whose actionform is consumerxmlActionForm --> No Issues here
- editxml.jsp Even here the actionform is consumerxmlActionForm --> here list gets populated but doesnt pass the same, back.
editxml.jsp :
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<html:html locale="true">
<head>
<title>Middleware UI</title>
<script language="JavaScript">
function submitFormEdit(frm,cmd) {
frm.operation.value = cmd;
frm.submit();
}
</script>
<html:base />
</head>
<body bgcolor="white">
<html:form action="/consumerxmlActionForm">
<html:hidden property="operation" />
<html:errors />
<table>
<tr>
<td align="center">beanID</td>
<td align="center">dayStartTime</td>
<td align="center">dayEndTime</td>
<td align="center">dayThreshold</td>
<td align="center">nightThreshold</td>
</tr>
<logic:iterate id="consumerXML" name="results" >
<tr>
<td align="center"><html:text name="consumerXML"
property="beanID" /></td>
<td align="center"><html:text name="consumerXML"
property="dayTime" /></td>
<td align="center"><html:text name="consumerXML"
property="nightTime" /></td>
<td align="center"><html:text name="consumerXML"
property="dayThreshold" /></td>
<td align="center"><html:text name="consumerXML"
property="nightThreshold" /></td>
</tr>
</logic:iterate>
<tr>
<td align="right"><html:submit onclick="submitFormEdit(consumerxmlActionForm, 'edit')">Change</html:submit></td>
</tr>
</table>
</html:form>
</body>
</html:html>
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
impor开发者_JAVA技巧t org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.unicel.vo.ConsumerXML;
import com.unicel.xml.ParseXML;
public class ConsumerXMLAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
String operation = request.getParameter("operation");
ConsumerXMLActionForm actionForm = (ConsumerXMLActionForm) form;
if(operation != null && operation.equals("edit")) {
System.out.println("*** Operation is **** " + operation);
System.out.println("*** actionForm.getOtherGWList() ****" + actionForm.getOtherGWList());
System.out.println("*** From Session *** " + request.getAttribute("results"));
if(actionForm.getOtherGWList() != null) {
for(ConsumerXML consumerXML : actionForm.getOtherGWList()) {
System.out.println("*** Current XML *** " + consumerXML);
}
}
} else {
ParseXML parseXML = new ParseXML();
parseXML.parse();
actionForm.setOtherGWList(parseXML.otherGatewayConsumerList);
request.setAttribute("results", parseXML.otherGatewayConsumerList);
}
return mapping.findForward("success");
}
}
import java.util.ArrayList;
import org.apache.struts.action.ActionForm;
import com.unicel.vo.ConsumerXML;
public class ConsumerXMLActionForm extends ActionForm {
private static final long serialVersionUID = 1L;
private ArrayList<ConsumerXML> otherGWList;
private String operation;
private String beanID;
private String dayTime;
private String nightTime;
private String dayThreshold;
private String nightThreshold;
public String getBeanID() {
return beanID;
}
public void setBeanID(String beanID) {
this.beanID = beanID;
}
public String getDayTime() {
return dayTime;
}
public void setDayTime(String dayTime) {
this.dayTime = dayTime;
}
public String getNightTime() {
return nightTime;
}
public void setNightTime(String nightTime) {
this.nightTime = nightTime;
}
public String getDayThreshold() {
return dayThreshold;
}
public void setDayThreshold(String dayThreshold) {
this.dayThreshold = dayThreshold;
}
public String getNightThreshold() {
return nightThreshold;
}
public void setNightThreshold(String nightThreshold) {
this.nightThreshold = nightThreshold;
}
public ArrayList<ConsumerXML> getOtherGWList() {
return otherGWList;
}
public void setOtherGWList(ArrayList<ConsumerXML> otherGWList) {
this.otherGWList = otherGWList;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
}
editxml.jsp displays the list properly, when I click on the "change" button I dont get the "results" in session. Is there any other way to fetch that list??
Thanks and Regards Raaghu.K
You should use the form to get values back to action and use the id and give VO there. Then Form will be available in action. You dont need session for this.
<logic:iterate name="monthlyGainLossForm" property="ptcList" id="productTaxCat">
精彩评论