由于预先标记的出勤率(值),Liferay无法更新数据库 [英] Not able to update database due to pre-marked attendance(values) Liferay

查看:89
本文介绍了由于预先标记的出勤率(值),Liferay无法更新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下标记员工出勤的功能:

I have the following functions to mark attendance of an employee:

            public void updateDailyAttendance(ActionRequest areq, ActionResponse aRes) throws Exception {
                int totalEmployees = EmployeeLocalServiceUtil.getEmployeesCount();
                List<Employee> employeeAttendanceDetails = MISPortalActionUtil.getEmployeeData();

                String datt = areq.getParameter("datt");
                String Imatt = areq.getParameter("matt");
                String yatt = areq.getParameter("yatt");

                int Lmatt = Integer.parseInt(Imatt);
                String matt = Integer.toString(Lmatt +1);


                String dateOfAttendance = datt +"/"+ matt +"/"+ yatt;


                SimpleDateFormat dateOfAttendanceFormat = new SimpleDateFormat("dd/MM/yyyy"); 
                java.util.Date date_Of_Attendance = dateOfAttendanceFormat.parse(dateOfAttendance);

                System.out.println("Today's attendance date is: " + date_Of_Attendance);

                ArrayList<String> attNames = new ArrayList<String>();

                for (Employee emp: employeeAttendanceDetails) {

                    long empId = emp.getEmpId();
                    String name = "updateattendance" + " " +Long.toString(emp.getEmpId());
                    System.out.println("updateattendance name :  " + name);
                    String value = getAttendanceValue(areq,name);
                    System.out.println("updateattendance value :  " + value);
                    long attPKey = CounterLocalServiceUtil.increment(Employee.class.getName());


                    Attendance newAttendanceInstance = new AttendanceImpl();

                    String checkAttMarkStatus = newAttendanceInstance.getAttStatus();
                    System.out.println("checkAttMarkStatus: " + checkAttMarkStatus);


                    //loop to mark the attendance if it has not been pre marked
                    if(checkAttMarkStatus != "Absent" || checkAttMarkStatus != "Half Day" ) {
                    newAttendanceInstance.setAttId(attPKey);
                    newAttendanceInstance.setAttDate(date_Of_Attendance);
                    newAttendanceInstance.setAttStatus(value);
                    newAttendanceInstance.setAttANStatus(value);
                    newAttendanceInstance.setAttFNStatus(value);
                    newAttendanceInstance.setEmpId(empId);
                    AttendanceLocalServiceUtil.addAttendance(newAttendanceInstance);
                    }//loop to mark the attendance if it has not been pre marked



                }
            }
            /**
             * The getAttendanceValue() is used to fetch parameter values and pass the values to updateDailyAttendance function
             * @param areq
             * @return
             * @throws SystemException 
             */

            private String getAttendanceValue(ActionRequest areq, String paramName) {
                 Enumeration parameters = areq.getParameterNames();
                 System.out.println("updateattendance paramName :  " + paramName);
                 while (parameters.hasMoreElements()) {
                     System.out.println("updateattendance paramName inside while :  " + paramName);
                     String parameterName = parameters.nextElement().toString();
                     System.out.println("updateattendance paramName new :  " + paramName);
                     System.out.println("the paramName " + paramName + " parameterName " + parameterName);

                     if (paramName.equals(parameterName)) {

                         return areq.getParameter(parameterName);

                     }




                 }
                 throw new IllegalStateException("Parameter updateattendance is not found");
                }

在我的jsp中,填充了员工列表,并且允许用户通过单选按钮标记出勤.当我标记所有员工的出勤率时,此方法效果很好. 但是问题出在我有预先标记的出勤状态时. 每当用户申请休假时,都会标记出他的出勤状态,并且标记此雇员出勤的出勤表会显示为已标记和已禁用.因此,当我尝试标记出勤时,如果存在预先标记出勤,则不会标记其他雇员的出勤.前任.假设如果第四个条目被预先标记为不存在,并且我将其他员工标记为出勤,则仅在数据库中添加前三个条目,然后它找不到第四个条目并抛出非法异常: 找不到参数updateattendance

In my jsp the list of employees is populated and user is allowed to mark attendance through radio button. This approach works well when I am marking attendance for all the employees. But problem comes when I have pre marked attendance status. Whenever a user applies for leave his attendance status is premarked and the attendance form for marking attendance for this employee is shown as marked and disabled.. So when I try to mark attendance when pre marked attendance exists, it doesnt mark attendance for other employees. ex. Suppose if the 4th entry is pre marked as absent, and I mark attendance for other employees, then only first three entries are added in the database and then it doesnt find the fourth entry and throws the illegal exception: Parameter updateattendance is not found

如何更改我的getAttendanceValue()函数以适合我的目的?

How should I change my getAttendanceValue() function to suit my purpose?

我在其中获取值的JSP部分:

The JSP part where I am fetching the values:

 <label>Present</label><input type = "radio" name ='updateattendance <%=((Object[])search)[5]%>' value = "Present" />
        <label>Absent</label><input type = "radio" name= 'updateattendance <%=((Object[])search)[5]%>' value = "Absent"  />

在上面的代码中,我检查了一下是否已预先标记.我将上面的代码片段放在if-else块中,以进行预先标记的出勤检查

IN the above code I have kept a check to see if it is pre marked. I have put the above code fragment in if-else block for pre marked attendance check

推荐答案

您正在执行此操作:

  Attendance newAttendanceInstance = new AttendanceImpl();
  String checkAttMarkStatus = newAttendanceInstance.getAttStatus(); // most likely null or ""
  System.out.println("checkAttMarkStatus: " + checkAttMarkStatus);

因此,我不希望您刚刚创建的对象保留正确的状态,而没有任何对先前状态的引用.我的期望是checkAddMarkStatus现在为"(空字符串)或null

So I don't expect the correct status to be held by the object that you just created without any reference to previous state. My expectation is that checkAddMarkStatus is now "" (empty string) or null

进一步检查字符串的身份,而不是相等性(这是java中的巨大区别:

Further you check for identity of strings, not equality (this is a huge difference in java:

  if(checkAttMarkStatus != "Absent" || checkAttMarkStatus != "Half Day" ) {

您应该宁愿使用String.equal(并且要注意null值),但是由于上述问题,如果不解决这两个问题,这将无济于事.可能还有更多,但这是我一见钟情的结果.

You should rather use String.equal (and be aware of null values), but due to the issue described above, this will not help you without sorting out both issues. There might be more, but this is what I found on first sight.

在评论和您的问题更新之后,我仍然缺少看到代码中的实际意图的信息.但是,我建议不要在看起来不太特殊的情况下使用像您一样的异常-而是使用正确的返回值并检查这些值-例如如果有人从未参加过,则有一个值可以表明这一点并做出相应的反应.如果您引发了异常但没有捕获到异常,则必须期待您提到的事情(例如,半执行方法)

Following the comments and your question update, I'm still missing to see the actual intent in the code. However, I'd advise to not use an exception like you do for a case that doesn't seem exceptional - rather use proper return values and check for these values - e.g. if someone never attended, have a value to signal this and react accordingly. If you throw an exception and don't catch it, you must expect things like you mention (e.g. half-executed methods)

这篇关于由于预先标记的出勤率(值),Liferay无法更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆