使用将表单作为集合提交Struts1.3中的标签
使用Struts 1.3。
使用
标签将表单作为集合提交 我想格式化多个用户记录以编辑值。
当数据提交回Action时,它如何处理Action表单中的表单列表?有没有办法将结果作为表单集合提交?
例如,我有 List
并且我正在 jsp 页面上迭代这些记录,并且工作正常。但记录在 JSP 页面上是可编辑的,因此在修改记录并按下提交按钮后,我需要在操作类中包含更新记录的 List
来更新数据库中的记录。
更新,我的jsp页面如下:
<html:form action="modify.do" styleId="LogicIterateForm" method="post">
<table style="font-weight:bold">
<tr><td>Employee ID</td><td>Employee Name</td></tr>
<logic:iterate id="employee" name="LogicIterateForm" property="emp" indexId="i">
<tr>
在此处输入代码
</tr>
</logic:iterate>
<tr>
<html:submit onclick="submitForm()">Modify</html:submit>
</tr>
</table>
</html:form>
操作:单击修改
按钮即可执行
LogicIterateForm logicIterateForm=(LogicIterateForm)form;
List<Employee> empList=logicIterateForm.getEmp();
System.out.println("Size of emp:::::"+empList.size());
if(empList!=null && empList.size()>0)
{
for(Employee emp:empList)
{
if(emp!=null)
{
System.out.println("EmployeeID:::::::::::"+emp.getEmpId());
System.out.println("EmployeeName:::::::::::"+emp.getEmpName());
}
}
}
,在操作内发送员工列表工作正常,但不幸的是我无法在操作内获取更新的表单字段值。请帮助我,我在哪里做错了。
下面是我的 ActionForm
public class LogicIterateForm extends org.apache.struts.action.ActionForm {
private List<Employee> emp=new ArrayList<Employee>();
public List<Employee> getEmp() {
return emp;
}
public void setEmp(List<Employee> emp) {
this.emp = emp;
}
,Employee 类是一个计划 java 类,其中包含 empId 和 empName 的 setter 和 getter
Using Struts 1.3.
Submitting forms as a collection using the <logic:iterate>
tag I'd like to format multiple records of user to edit values.
When the data is submitted back to the Action
how can it handle a list of form in an Action form? Is there a way to submit the results as a collection of forms?
For example, I have List<EmployeeForm>
and I am iterating these records on my jsp page and it's working fine. But the records are editable on the JSP page, so after modifying the records and pressing the submit button I need the List<EmployeeForm>
with updated records inside my action class to update the records inside the DB.
update, my jsp page is below given:
<html:form action="modify.do" styleId="LogicIterateForm" method="post">
<table style="font-weight:bold">
<tr><td>Employee ID</td><td>Employee Name</td></tr>
<logic:iterate id="employee" name="LogicIterateForm" property="emp" indexId="i">
<tr>
enter code here
</tr>
</logic:iterate>
<tr>
<html:submit onclick="submitForm()">Modify</html:submit>
</tr>
</table>
</html:form>
action: to perform on clicking of Modify
button
LogicIterateForm logicIterateForm=(LogicIterateForm)form;
List<Employee> empList=logicIterateForm.getEmp();
System.out.println("Size of emp:::::"+empList.size());
if(empList!=null && empList.size()>0)
{
for(Employee emp:empList)
{
if(emp!=null)
{
System.out.println("EmployeeID:::::::::::"+emp.getEmpId());
System.out.println("EmployeeName:::::::::::"+emp.getEmpName());
}
}
}
and it is working fine to send the list of employees inside the action but unfortunately i am unable to get the updated form fields value inside my action. please help me where i am doing mistake.
and below is my ActionForm
public class LogicIterateForm extends org.apache.struts.action.ActionForm {
private List<Employee> emp=new ArrayList<Employee>();
public List<Employee> getEmp() {
return emp;
}
public void setEmp(List<Employee> emp) {
this.emp = emp;
}
and Employee class is a plan java class with setter and getter of empId and empName
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之,生成的 HTML 将具有不正确的
name
属性。ActionForm
列表属性名为emp
,但您将其称为employee
。较长的版本包括一些其他杂项,从长远来看,这些内容应该会让您的事情变得更容易一些。
首先,这是我用来显示表单的
Action
。请注意,我没有明确地将任何内容纳入范围 - 框架为我们做了这件事。看起来好像您明确地将表单设置为
使用的范围,但这是多余的。其次,由于上述原因,JSP页面可以变得更简单。请注意,输入元素的名称必须与表单中的名称
emp
匹配,否则Struts 将不知道如何处理输入值,并且将被忽略。然后,在提交到的操作内,所有数据都将采用预期的形式。
应该可以做到这一点。
The nutshell version is that the generated HTML will have an incorrect
name
attribute. TheActionForm
list property is namedemp
but you're calling itemployee
.The longer version includes some other miscellaneous stuff that should make things a little easier for you in the long run.
First, here's the
Action
I used to display the form. Note that I am not putting anything into scope explicitly--the framework does this for us. It appears as though you're explicitly setting a form into scope for use by<logic:iterator>
, but that's redundant.Second, the JSP page can be made simpler because of the above. Note that the name of the input element must match the name in the form,
emp
, otherwise Struts won't know what to do with the input value, and it will be ignored.Then inside the action that's being submitted to all the data will be in the form as expected.
That should do it.