Struts:使用Logic Iterate但没有在Action中获取更新的列表值

时间:2011-09-02 11:34:44

标签: java struts

我正在开发一个读取XML的应用程序,这些XML的值在“Object”(consumerXML)中设置,该对象在列表中设置,列表将在session中设置,Key为“results”< / p>

request.setAttribute("results", list)  

Flow就像这样

  1. Welcome.JSP,其actionform为consumerxmlActionForm - &gt;这里没有问题
  2. editxml.jsp即使在这里,actionform也是consumerxmlActionForm - &gt;这里列表已填充,但没有传递回来。
  3. 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正确显示列表,当我点击“更改”按钮时,我在会话中没有得到“结果”。有没有其他方法来获取该列表??

    谢谢和问候 Raaghu.K

1 个答案:

答案 0 :(得分:0)

您应该使用表单将值恢复为操作并使用id并在那里提供VO。然后表格将在行动中提供。你不需要这个会议。

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