gpt4 book ai didi

java - 支柱 : Using Logic Iterate but not getting the updated list value in Action

转载 作者:行者123 更新时间:2023-12-01 05:40:36 26 4
gpt4 key购买 nike

我正在开发一个读取 XML 的应用程序,这些 XML 的值设置在“对象”(consumerXML)中,该对象设置在列表中,列表将设置在 session 中,键是“结果”

request.setAttribute("results", list)  

流程是这样的

  1. Welcome.JSP,其操作表单为consumerxmlActionForm --> 这里没有问题
  2. editxml.jsp 即使在这里,actionform 是consumerxmlActionForm --> 这里列表被填充,但不会传递相同的内容。

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;
import 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 正确显示列表,当我单击“更改”按钮时,我在 session 中没有得到“结果”。还有其他方法可以获取该列表吗?

感谢和问候拉古.K

最佳答案

您应该使用表单将值返回到操作并使用 id 并在那里给出 VO。然后表格就可以使用了。您不需要为此进行 session 。

        <logic:iterate name="monthlyGainLossForm" property="ptcList" id="productTaxCat">

关于java - 支柱 : Using Logic Iterate but not getting the updated list value in Action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7282812/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com