简体   繁体   English

Struts-提交 <html:form> 内 <logic:iterate>

[英]Struts - Submit <html:form> within <logic:iterate>

I have jsp page where I iterate over a collection using logic:iterate and an html:form is displayed for each item. 我有一个jsp页面,在这里我使用logic:iterate一个集合,并为每个项目显示一个html:form This works but every time I submit one of these forms and the page gets reloaded, all the remaining forms are filled with the last inserted values. 这可行,但是每次我提交这些表单之一并且重新加载页面时,所有剩余的表单都将填充最后插入的值。 Probably something remains in session and since the forms are all of the same type they are all prepopulated. 会话中可能还剩下一些内容,并且由于表单都是相同的类型,因此它们都已预先填充。

This is my jsp: 这是我的jsp:

<%@ page language="java"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<html>
<body>
    <html:img action="/viewMedia.do?method=viewImageThumb" paramId="idImage"
        paramName="image" paramProperty="idImage" />
    <logic:iterate name="regions" id="region">
        <p>
            <html:img action="/viewMedia.do?method=viewRegion"      paramId="idRegion" paramName="region" paramProperty="idRegion" />
            <logic:notPresent name="region" property="person">
                <html:form action="/AssignRegion.do" >
                    <html:text property="name" />
                    <html:text property="surname"  />
                    <html:checkbox property="usedForTraining" />
                    <html:hidden property="idRegion" name="region" />
                    <html:hidden property="idImage" name="region"/>
                    <html:submit />
                    <html:cancel />
                </html:form>
            </logic:notPresent>
            <logic:present name="region" property="person">
                <bean:write name="region" property="person.name"/>
                <bean:write name="region" property="person.surname"/>
            </logic:present>
        </p>
    </logic:iterate>
</body>
</html>

How can I avoid this? 如何避免这种情况?

It doesn't look like an issue with logic:iterate . 看起来似乎不是logic:iterate问题logic:iterate Looking at your problem description it looks like you are using same form bean for all the mappings. 查看您的问题描述,似乎您对所有映射都使用相同的Form Bean。

Check struts-config.xml to see if the scope of the form bean used in the action mappings is "session". 检查struts-config.xml以查看动作映射中使用的form Bean的范围是否为“会话”。

If it is "session", then you need to reset those properties of the form bean that do not require to be pre-populated in other pages being forwarded to. 如果它是“会话”,那么您需要重置那些不需要在要转发到的其他页面中预先填充的form Bean的属性。

If a particular property in the form bean is not reset, the session cached value of the property will be used on the resulting page(s) since form bean is held in "session". 如果未重置Form Bean中的特定属性,则该属性的会话缓存值将在结果页面上使用,因为Form Bean被保存在“会话”中。

I guess the input fields name attribute is not correctly prefixed when using the logic and html taglibs. 我猜想在使用逻辑和html标签库时,输入字段的name属性未正确添加前缀。 Try using the nested taglib instead 尝试改用嵌套的taglib

<%@taglib uri="http://struts.apache.org/tags-nested" prefix="nested"%>
...
<nested:iterate ...
...
    <nested:form ...
        <nested:text ..

If you view the generated HTML, you will then typically see <input name="regions[0].name" ... rather than <input name="name" ... 如果查看生成的HTML,则通常会看到<input name="regions[0].name" ...而不是<input name="name" ...

I recommend always using the nested taglib as a replacement for the logic and html taglibs. 我建议始终使用嵌套taglib代替逻辑和html taglib。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM