免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1546 | 回复: 6
打印 上一主题 下一主题

高手请进,关于struts中的iterate [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-02-24 17:32 |只看该作者 |倒序浏览
图片中的iterate部分代码为:
<logic:iterate id = "t" indexId = "i" name = "tForm" property = "alist" type = "trfc.struts.tools.Temp">;
<tr>;
<td >;
<html:submit>;
<bean:message key = "button.delete"/>;
</html:submit>;
</td>;
<td>;
<html:text name = "t" property="os" size="15" maxlength="50" />;
</td>;
<td>;
<html:text name = "t" property="toPos" size="15" maxlength="50"/>;
</td>;
</logic:iterate>;
=====================================
Temp类大致如下;
package trfc.struts.tools;
public class Temp{
         .
         .
    public String getPos(){
       return this.pos;
    }
    public void setPos(String value){
       this pos = value;
    }
}
从程序显示到网页上的值是正确的,但是从网页上的值读到FormBean里就不调用get函数,为什么。
用什么方法可以得到我按的是第几个删除按钮。
谢谢 :em11:      

1.jpg (5.56 KB, 下载次数: 63)

1.jpg

论坛徽章:
0
2 [报告]
发表于 2004-02-25 11:41 |只看该作者

高手请进,关于struts中的iterate

我没看见html页面里的form,你如何提交去FormBean??以目前的代码一定不会调用FormBean的get方法。


另外在这里
<html:submit>;
<bean:message key = "button.delete"/>;
</html:submit>;
利用logic:iterate tag生成的按钮全都叫一个名字,他当然不认得你按的是哪个按钮。我建议你把上面的代码改为<html:link>;然后在link的page属性里映射一个删除的action,将你从bean中得到的项目编号传递给这个action作相应的正确的删除动作。

论坛徽章:
0
3 [报告]
发表于 2004-02-25 12:41 |只看该作者

高手请进,关于struts中的iterate

form的提交方法是
<html:form action="/actonGo">;
在formBean里只有
public ArrayList getAList()
public void setAList()
关于把button改成link的问题,这是式样书上规定用button,我也没办法,能不能用button来实现。
请详细解释一下。谢谢

论坛徽章:
0
4 [报告]
发表于 2004-02-25 13:49 |只看该作者

高手请进,关于struts中的iterate

你贴多一点代码

论坛徽章:
0
5 [报告]
发表于 2004-02-25 16:09 |只看该作者

高手请进,关于struts中的iterate

=======================数据类===================
package trfc.struts.tools;
public class Test{
  String strTest;
  public Test(){
    strTest = "test";
  }
  public String getStrTest(){
    this.strTest;
  }
  public void setStrTest(String value){
    this.strTest = value;
  }
}
=======================formBean类===================
package trfc.struts.form;
public class AForm extends ActionForm {
  private ArrayList al_test;

  public void setAlTest(ArrayList value) {
    this.al_test = value;
  }
  public ArrayList getAlTest() {
    return this.al_test;
  }
  public void reset(ActionMapping mapping, HttpServletRequest request) {
    HttpSession session = request.getSession();
    if (session.getAttribute("altest" != null) {
        this.al_test = (ArrayList) session.getAttribute("altest";
        session.removeAttribute("altest";
    }
  }
}
=========================Action类=======================
package trfc.struts.action;

public class AAction extends Action {
  public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws Exception {
    return mapping.getInputForward();
  }
}
=========================jsp文件=======================
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>;
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>;
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>;
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">;
<html>;
<head>;
<title>;test</title>;
</head>;
<body>;
<html:form action="/ok">;
  <table align=center width = "100%">;
    <tr>;
      <th valign=middle align=center bgcolor=#90ee90>;
        <html:submit>;新建</html:submit>;
      </th>;
      <th bgcolor=#add8e6 height=30>;test字符串的值</th>;
    </tr>;
    <logic:iterate id = "atest" indexId = "testIndex" name = "AForm" property = "alTest" type = "trfc.struts.tools.Test">;
    <tr>;
      <td>;<html:submit>;删除</html:submit>;</td>;
      <td>;<html:text name = "tempSeisansho" property="fromPos" size="15" maxlength="50" />;</td>;
    </tr>;
  </logic:iterate>;               
  </table>;
  <html:submit>;保存</html:submit>;
</html:form>;
</body>;
</html>;
===============================================================================================
主要的基本就这些了,在formBean类里的al_Test是从上一个页面保存到session中的al_test值。
al_Test里保存了两个以上的,不确定几个的Test类的对象。
在此画面上对所有的test对象进行新建,删除,或修改操作,最后修改完毕按保存退出。

论坛徽章:
0
6 [报告]
发表于 2004-02-26 10:01 |只看该作者

高手请进,关于struts中的iterate

你把jsp改成这样试一试:
=========================jsp文件=======================
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>;
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>;
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>;
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">;
<html>;
<head>;
<title>;test</title>;
</head>;
<body>;
<html:form action="/ok">;
<table align=center width = "100%">;
<tr>;
<th valign=middle align=center bgcolor=#90ee90>;
<html:submit>;新建</html:submit>;
</th>;
<th bgcolor=#add8e6 height=30>;test字符串的值</th>;
</tr>;
<logic:iterate id = "atest" indexId = "testIndex" name = "AForm" property = "alTest" type = "trfc.struts.tools.Test">;
<tr>;
<td>;<html:button onclick=window.navigate("/deleteAction.do?itemID=<bean:write name=testIndex/>;">;删除</html:button>;</td>;
<td>;<html:text name = "<bean:write name=testIndex/>;" value="<bean:write name=atest property=strTest />;" size="15" maxlength="50" />;</td>;
</tr>;
</logic:iterate>;
</table>;
<html:submit>;保存</html:submit>;
</html:form>;
</body>;
</html>;

button我用的不多,其实在图片上加link和button是一样效果,而且也免去了javascript所带来的兼容性问题。

论坛徽章:
0
7 [报告]
发表于 2004-02-26 13:47 |只看该作者

高手请进,关于struts中的iterate

谢谢了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP