栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

通过单选按钮将值传递给动作类

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过单选按钮将值传递给动作类

考虑到你的jsp是正确的,代码

<input type = "radio" name ='updateattendance +     <%=String.valueOf(search.getEmpId())%>' value = "present" />

将创建一个名为updateattendance101,updateattendance102,updateattendance201,updateattendance301等属性的数组

编码

if (parameterName.startsWith("updateattendance")) { return areq.getParameter(parameterName);

获取第一个匹配属性,因此您始终获得相同的值。因此,您需要做的是使用与馈送搜索容器相同的数组(数组’EmployeeAttendanceDetails’),遍历所有对象,并使用’getEmpId’id来完全匹配该属性。

其次,我看到一些使用ServiceBuilder的不良做法。

  1. 您确定要创建一个新的Employee,而不是更新现有的Employee吗?
  2. 即使您要创建/更新员工条目,也应该在AttendanceLocalServiceImpl中创建包装函数,而不是在客户端代码中手动编辑所有属性/增加持久性计数器等。

编辑:您可以用此替换您发布的Java代码,希望您能理解

public void updateDailyAttendance(ActionRequest areq, ActionResponse aRes) throws Exception{    List<Employee> employeeAttendanceDetails = MISPortalActionUtil.getEmployeeData();    for (Employee emp: employeeAttendanceDetails) {    String name = "updateattendance" + Long.toString(emp.getEmpId());         String value = getAttendancevalue(areq, name);         // You don't really need to call call getAttendancevalue, except if you're going to handle the IllegalStateException.          //If this is the case, you can just call :         //String value = areq.getParameter(name);        // Do your stuff with the employee object    }}private String getAttendancevalue(ActionRequest areq, String paramName) { Enumeration parameters = areq.getParameterNames(); while (parameters.hasMoreElements()) {     String parameterName = parameters.nextElement().toString();     if (parameterName.equals(paramName)) {         return areq.getParameter(parameterName);     } } throw new IllegalStateException("Parameter updateattendance is not found");}

编辑2:替换

name ='updateattendance +     <%=String.valueOf(search.getEmpId())%>'

name ='updateattendance<%=String.valueOf(search.getEmpId())%>'


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379355.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号