e.g. Calendar Search Help
You must enter a value before pressing Search
xplanner

Class: com.technoetic.xplanner.forms.PersonTimesheetForm   ©

 OK to copy?
001 package com.technoetic.xplanner.forms;
002 
003 import com.technoetic.xplanner.domain.virtual.Timesheet;
004 import org.apache.struts.Globals;
005 import org.apache.struts.action.ActionError;
006 import org.apache.struts.action.ActionErrors;
007 import org.apache.struts.action.ActionMapping;
008 
009 import java.text.ParseException;
010 import java.text.SimpleDateFormat;
011 import java.util.Calendar;
012 import java.util.Date;
013 import javax.servlet.http.HttpServletRequest;
014 
015 public class PersonTimesheetForm extends AbstractEditorForm {
016 
017     private java.util.Date startDate;
018     private String startDateString;
019     private java.util.Date endDate;
020     private String endDateString;
021     private SimpleDateFormat dateFormat;
022     private Timesheet timesheet;
023 
024     public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
025         ActionErrors errors = new ActionErrors();
026 
027         if (this.dateFormat == null) {
028             String format = getResources(request).getMessage(request.getLocale(), "format.date");
029             dateFormat = new SimpleDateFormat(format);
030         }
031 
032         Date startDate = null;
033         if (isPresent(this.startDateString)) {
034             try {
035                 startDate = dateFormat.parse(this.startDateString);
036                 this.setStartDate(startDate);
037             } catch (ParseException ex) {
038                 errors.add(ActionErrors.GLOBAL_ERROR,
039                            new ActionError("timesheet.error.unparsable_date"));
040                 request.setAttribute(Globals.ERROR_KEY, errors);
041                 return errors;
042             }
043         }
044 
045         Date endDate = null;
046         if (isPresent(this.endDateString)) {
047             try {
048                 endDate = dateFormat.parse(this.endDateString);
049                 this.setEndDate(endDate);
050             } catch (ParseException ex) {
051                 errors.add(ActionErrors.GLOBAL_ERROR,
052                            new ActionError("timesheet.error.unparsable_date"));
053                 request.setAttribute(Globals.ERROR_KEY, errors);
054                 return errors;
055             }
056         }
057         return errors;
058     }
059 
060     public void reset(ActionMapping mapping, HttpServletRequest request) {
061         super.reset(mapping, request);
062         this.endDate = this.getWeekEndDate();
063         this.startDate = this.getWeekStartDate();
064         this.timesheet = new Timesheet(this.startDate, this.endDate);
065     }
066 
067     public java.util.Date getStartDate() {
068         return startDate;
069     }
070 
071     public void setStartDate(java.util.Date startDate) {
072         this.startDate = startDate;
073     }
074 
075     public String getStartDateString() {
076         if (dateFormat == null) {
Rate077             return this.getStartDate().toString();
078         }
079         return dateFormat.format(this.getStartDate());
080     }
081 
082     public void setStartDateString(String start) {
083         this.startDateString = start;
084     }
085 
086     public Date getEndDate() {
087         return endDate;
088     }
089 
090     public void setEndDate(Date endDate) {
091         this.endDate = endDate;
092     }
093 
094     public String getEndDateString() {
095         if (dateFormat == null) {
Rate096             return this.getEndDate().toString();
097         }
098         return dateFormat.format(this.getEndDate());
099     }
100 
101     public void setEndDateString(String end) {
102         this.endDateString = end;
103     }
104 
105     public Timesheet getTimesheet() {
106         return timesheet;
107     }
108 
109     public void setTimesheet(Timesheet timesheet) {
110         this.timesheet = timesheet;
111     }
112 
113     private Date getWeekEndDate() {
114         Calendar cal = Calendar.getInstance();
115         cal.set(Calendar.HOUR_OF_DAY, 0);
116         cal.set(Calendar.MINUTE, 0);
117         cal.set(Calendar.SECOND, 0);
118         cal.set(Calendar.MILLISECOND, 0);
119         int weekday = cal.get(Calendar.DAY_OF_WEEK);
120         cal.add(Calendar.DATE, 7 - weekday);
121         return cal.getTime();
122     }
123 
124     private Date getWeekStartDate() {
125         Calendar cal = Calendar.getInstance();
126         cal.set(Calendar.HOUR_OF_DAY, 0);
127         cal.set(Calendar.MINUTE, 0);
128         cal.set(Calendar.SECOND, 0);
129         cal.set(Calendar.MILLISECOND, 0);
130         int weekday = cal.get(Calendar.DAY_OF_WEEK);
131         cal.add(Calendar.DATE, -weekday + 1);
132         return cal.getTime();
133     }
134 
135     private boolean isPresent(String value) {
136         return value != null && !value.equals("") && !value.equals("null");
137     }
138 
139     public void setDateFormat(SimpleDateFormat format) {
140         this.dateFormat = format;
141     }
142 
143     public SimpleDateFormat getDateFormat() {
144         return this.dateFormat;
145     }
146 
147     public int getPersonId() {
148         return Integer.parseInt(super.getOid());
149     }
150 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
77 0% of 0
96 0% of 0