Hi All,
I am new to struts2,Hibernate.
we are working on"Timesheet management system". whenever we try to save data we got error
I try to resolve this error but failed to do...
ERROR:-
org.apache.jasper.JasperException: tag 'select', field 'list', name 'timesheettasks[0].actstarthours': The requested list key 'names' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:164)
org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
root cause
tag 'select', field 'list', name 'timesheettasks[0].actstarthours': The requested list key 'names' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
org.apache.struts2.components.Component.fieldError(Component.java:240)
org.apache.struts2.components.Component.findValue(Component.java:361)
org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:80)
org.apache.struts2.components.Select.evaluateExtraParams(Select.java:105)
org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:864)
org.apache.struts2.components.UIBean.end(UIBean.java:516)
org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
org.apache.jsp.newtimesheet_jsp._jspx_meth_s_005fselect_005f1(newtimesheet_jsp.java:561)
org.apache.jsp.newtimesheet_jsp._jspx_meth_s_005fiterator_005f0(newtimesheet_jsp.java:420)
org.apache.jsp.newtimesheet_jsp._jspx_meth_s_005fform_005f0(newtimesheet_jsp.java:312)
org.apache.jsp.newtimesheet_jsp._jspService(newtimesheet_jsp.java:130)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:164)
org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:236)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
newtimesheet.jsp:-
<%@ taglib prefix="s" uri="/struts-tags"%>
<script language="javaScript" type="text/javascript"
src="js/calendar.js"></script>
<script language="javaScript" type="text/javascript" >
function submitpage(name){
//alert(name);
var timesheetform = document.getElementById("formTimesheet");
if(name=="btnSaverelease"){
//alert("inside if block");
//alert("timesheetform="+timesheetform);
//alert("document.form="+document.form);
timesheetform.action="/TimesheetManagement/saverelease";
timesheetform.submit();
}else if(name=="btnSave"){
//alert("inside else if");
var operation = document.getElementById("hdOperation");
//alert(operation);
operation.value= "Save";
//alert("operation.value="+operation.value);
timesheetform.action="/TimesheetManagement/save";
timesheetform.submit();
}else if(name=="btnaddTask"){
//alert("inside else if");
timesheetform.action="/TimesheetManagement/save";
timesheetform.submit();
}
}
</script>
<link href="css/calendar.css" rel="stylesheet" type="text/css">
<head>
<title>TimeSheet Management</title>
</head>
<body>
<h1>
TimeSheet Management
</h1>
<s:form action="save">
<s:textfield value="%{#timesheet.empname}" label="EMPLOYEE NAME:"
labelposition="left top" />
<table>
<tr>
<td>
CALENDER :
</td>
<td>
<a href="#"
onClick="setYears(2012, 2014);
showCalender(this, 'datum1');">
<input type="text" name="datum1" id="datum1"> <img
src="images/calender.jpg" style="vertical-align: middle;"> </a>
</td>
</tr>
<tr>
<td>
<table id="calenderTable">
<tr>
<td style="background-color: #D9E2EB;">
<table id="calenderTableHead">
<tr>
<td width="5px"></td>
<td align="center">
<select
onChange="showCalenderBody(
createCalender(document.getElementById('selectYear').value,
this.selectedIndex, false));"
id="selectMonth">
<option value="0">
Jan
</option>
<option value="1">
Feb
</option>
<option value="2">
Mar
</option>
<option value="3">
Apr
</option>
<option value="4">
May
</option>
<option value="5">
Jun
</option>
<option value="6">
Jul
</option>
<option value="7">
Aug
</option>
<option value="8">
Sep
</option>
<option value="9">
Oct
</option>
<option value="10">
Nov
</option>
<option value="11">
Dec
</option>
</select>
</td>
<td align="center">
<select
onChange="showCalenderBody(createCalender(this.value,
document.getElementById('selectMonth').selectedIndex, false));"
id="selectYear">
</select>
</td>
<td style="vertical-align: middle;">
<a href="#" onClick="closeCalender();"><img
src="images/hide_btn.gif" /> </a>
</td>
</tr>
</table>
</td>
</tr>
<tr id="calenderTableDays">
<td colspan="7">
<span style="padding: 8px;">S</span>
<span style="padding: 5px;">M</span><span style="padding: 11px;">T</span><span
style="padding: 6px;">W</span><span style="padding: 8px;">T</span><span
style="padding: 10px;">F</span><span style="padding: 5px;">S</span>
</td>
</tr>
<tr>
<td>
<table>
<tbody id="calender"></tbody>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="1">
<tr>
<th>
Project
</th>
<th>
Task
</th>
<th>
Description
</th>
<th colspan="2">
Activity Start Time(HH:MM)
</th>
<th colspan="2">
Activity End Time(HH:MM)
</th>
<th>
Hours
</th>
</tr>
<s:iterator value="timesheettasks" var="timesheet" status="stat">
<tr>
<td>
<s:select list="projectlist" listValue="projectname" name="projectname" id="projectname"
headerKey="-1" headerValue="------SELECT------" theme="simple" onchange="abcd();"/>
</td>
<td>
<s:textfield value="%{#timesheet.task}"
name="timesheettasks[%{#stat.index}].task" theme="simple" />
</td>
<td>
<s:textfield value="%{#timesheet.description}"
name="timesheettasks[%{#stat.index}].description" theme="simple" />
</td>
<td>
<s:select list="names"
name="timesheettasks[%{#stat.index}].actstarthours"
theme="simple"></s:select>
</td>
<td>
<s:select list="names1"
name="timesheettasks[%{#stat.index}].actstartminutes"
theme="simple"></s:select>
</td>
<td>
<s:select list="names"
name="timesheettasks[%{#stat.index}].actendhours" theme="simple"></s:select>
</td>
<td>
<s:select list="names1"
name="timesheettasks[%{#stat.index}].actendminutes"
theme="simple"></s:select>
</td>
<td>
<s:textfield readonly="true" value="%{#timesheet.hours}"
name="timesheettasks[%{#stat.index}].hours" theme="simple"
size="5" />
</td>
</tr>
</s:iterator>
</table>
<table>
<tr>
<td><s:submit value="Add Task" align="left" name="btnaddTask" onclick="submitpage(name)" theme="simple"></s:submit></td>
<TD><s:submit value="Save" name="btnSave" theme="simple" id="hdOperation" onclick="submitpage(name)"></s:submit></TD>
<TD><s:submit value="SaveRelease" theme="simple"></s:submit></TD>
<TD><s:submit value="Reset" theme="simple"></s:submit></TD>
</tr>
</table>
</s:form>
</body>
<script type="text/javascript">
function abcd(){
var a = document.getElementById("projectname");
var strUser = a.options[a.selectedIndex].value;
}
</script>
NewTimesheetAction:
/**
*
*/
package com.pinwheel.action;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.pinwheel.dao.ManageTimesheetDAOImp;
import com.pinwheel.dto.TimesheetTask;
import com.pinwheel.listener.saveDataService;
import com.pinwheel.pojo.Project;
import com.pinwheel.util.PWConstants;
/**
* @author:
* Date:
*
*/
public class NewTimesheetAction extends ActionSupport implements Preparable{
String operation;
String Project_value;
private String empname;
private List<Project> projectlist;
private String task;
private String description;
private String projectname;
private Date datum1;
private String actstarthours;
private String actstartminutes;
private String actendhours;
private String actendminutes;
private String hours;
private String date;
private List<String> names;
private List<String> names1;
private String name;
private List<TimesheetTask> timesheettasks;
public List<TimesheetTask> getTimesheettasks() {
return timesheettasks;
}
public void setTimesheettasks(List<TimesheetTask> timesheettasks) {
this.timesheettasks = timesheettasks;
}
public List<String> getNames() {
return names;
}
public void setNames(List<String> names) {
this.names = names;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void prepare() throws Exception {
System.out.println("NewTimesheetAction.prepare()");
names = new ArrayList<String>();
for (int i = 0; i <= 23; i++) {
names.add(PWConstants.BLANK+i);
}
System.out.println("NewTimesheetAction.prepare().names="+names);
names1 = new ArrayList<String>();
for (int i = 0; i <=59; i++) {
names1.add(PWConstants.BLANK+i);
}
System.out.println("NewTimesheetAction.prepare().names1="+names1);
}
@Override
public String execute() throws Exception {
System.out.println("NewTimesheetAction.execute()");
TimesheetTask task1 = new TimesheetTask();
TimesheetTask task2 = new TimesheetTask();
TimesheetTask task3 = new TimesheetTask();
TimesheetTask task4 = new TimesheetTask();
timesheettasks = new ArrayList<TimesheetTask>();
timesheettasks.add(task1);
timesheettasks.add(task2);
timesheettasks.add(task3);
timesheettasks.add(task4);
ManageTimesheetDAOImp timesheetDAOImp=new ManageTimesheetDAOImp();
HttpServletRequest request=ServletActionContext.getRequest();
HttpSession session = request.getSession();
projectlist=timesheetDAOImp.getProjects();
session.setAttribute("projectlist", projectlist);
//request.setAttribute("projectlist", projectlist);
return "success";
/* timesheettasks.size();*/
/*return "success";*/
}
public NewTimesheetAction( ){
}
public List<String> getNames1() {
return names1;
}
public void setNames1(List<String> names1) {
this.names1 = names1;
}
public String getEmpname() {
return empname;
}
public void setEmpname(String empname) {
this.empname = empname;
}
public List<Project> getProjectlist() {
return projectlist;
}
public void setProjectlist(List<Project> projectlist) {
this.projectlist = projectlist;
}
public String getActstarthours() {
return actstarthours;
}
public void setActstarthours(String actstarthours) {
this.actstarthours = actstarthours;
}
public String getActstartminute() {
return actstartminutes;
}
public void setActstartminute(String actstartminute) {
this.actstartminutes = actstartminute;
}
public String getActendhours() {
return actendhours;
}
public void setActendhours(String actendhours) {
this.actendhours = actendhours;
}
public String getActendminute() {
return actendminutes;
}
public void setActendminute(String actendminute) {
this.actendminutes = actendminute;
}
public String getHour() {
return hours;
}
public void setHour(String hour) {
this.hours = hour;
}
public String add() throws Exception{
System.out.println("NewTimesheetAction.add().<empname="+empname+">,<datum1="+datum1+">,<projectname="+projectname+">,<task="+task+">,<description="+description+">,<actstarthours="+actstarthours+">,<actstartminutes="+actstartminutes+">,<actendhours="+actendhours+">,<actendminutes="+actendminutes+">,,<hours="+hours+">");
return "success";
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTask() {
return task;
}
public void setTask(String task) {
this.task = task;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getProjectname() {
return projectname;
}
public void setProjectname(String projectname) {
this.projectname = projectname;
}
public String getActstartminutes() {
return actstartminutes;
}
public void setActstartminutes(String actstartminutes) {
this.actstartminutes = actstartminutes;
}
public String getActendminutes() {
return actendminutes;
}
public void setActendminutes(String actendminutes) {
this.actendminutes = actendminutes;
}
public String getProject_value() {
return Project_value;
}
public void setProject_value(String project_value) {
Project_value = project_value;
}
public Date getDatum1() {
return datum1;
}
public void setDatum1(Date datum1) {
this.datum1 = datum1;
}
public String getHours() {
return hours;
}
public void setHours(String hours) {
this.hours = hours;
}
}
SAVEACTION:
package com.pinwheel.action;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.pinwheel.dao.ManageTimesheetDAOImp;
import com.pinwheel.dto.TimesheetTask;
import com.pinwheel.listener.saveDataService;
import com.pinwheel.pojo.Project;
public class SaveAction extends ActionSupport {
String operation;
String Project_value;
private String empname;
private List<Project> projectlist;
private String task;
private String description;
private String projectname;
private String datum1;
private String actstarthours;
private String actstartminutes;
private String actendhours;
private String actendminutes;
private String hours;
private List<TimesheetTask> timesheettasks;
public List<TimesheetTask> getTimesheettasks() {
return timesheettasks;
}
public void setTimesheettasks(List<TimesheetTask> timesheettasks) {
this.timesheettasks = timesheettasks;
}
public String getEmpname() {
return empname;
}
public void setEmpname(String empname) {
this.empname = empname;
}
public List<Project> getProjectlist() {
return projectlist;
}
public void setProjectlist(List<Project> projectlist) {
this.projectlist = projectlist;
}
public String getTask() {
return task;
}
public void setTask(String task) {
this.task = task;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getProjectname() {
return projectname;
}
public void setProjectname(String projectname) {
this.projectname = projectname;
}
public String getDatum1() {
return datum1;
}
public void setDatum1(String datum1) {
this.datum1 = datum1;
}
public String getActstarthours() {
return actstarthours;
}
public void setActstarthours(String actstarthours) {
this.actstarthours = actstarthours;
}
public String getActstartminutes() {
return actstartminutes;
}
public void setActstartminutes(String actstartminutes) {
this.actstartminutes = actstartminutes;
}
public String getActendhours() {
return actendhours;
}
public void setActendhours(String actendhours) {
this.actendhours = actendhours;
}
public String getActendminutes() {
return actendminutes;
}
public void setActendminutes(String actendminutes) {
this.actendminutes = actendminutes;
}
public String getHours() {
return hours;
}
public void setHours(String hours) {
this.hours = hours;
}
public List<Project> add() throws Exception {
System.out.println("NewTimesheetAction.add().<empname=" + empname
+ ">,<datum1=" + datum1 + ">,<projectname=" + projectname
+ ">,<task=" + task + ">,<description=" + description
+ ">,<actstarthours=" + actstarthours + ">,<actstartminutes="
+ actstartminutes + ">,<actendhours=" + actendhours
+ ">,<actendminutes=" + actendminutes + ">,,<hours=" + hours
+ ">");
ManageTimesheetDAOImp timesheetDAOImp = new ManageTimesheetDAOImp();
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
projectlist = timesheetDAOImp.getProjects();
// System.out.println("SaveAction.add().projectlist:"+projectlist);
session.setAttribute("projectlist", projectlist);
return projectlist;
}
@Override
public String execute() throws Exception {
System.out.println("SaveAction.execute().operation :: " + operation);
System.out.println("NewTimesheetAction.execute().<empname=" + empname
+ ">,<datum1=" + datum1 + ">,<projectname=" + projectname
+ ">,<task=" + task + ">,<description=" + description
+ ">,<actstarthours=" + actstarthours + ">,<actstartminutes="
+ actstartminutes + ">,<actendhours=" + actendhours
+ ">,<actendminutes=" + actendminutes + ">,,<hours=" + hours
+ ">");
List<Project> projectlist = this.add();
HttpServletRequest request=ServletActionContext.getRequest();
String operation = request.getParameter("hdOperation");
System.out.println("SaveAction.execute().operation=" + operation);
if ("save".equalsIgnoreCase(operation)) {
TimesheetTask timesheetTask=new TimesheetTask();
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
Date fDate = (Date)formatter.parse(datum1);
timesheetTask.setEmpname(empname);
timesheetTask.setProject_value(projectname);
timesheetTask.setTask(task);
timesheetTask.setDescription(description);
timesheetTask.setActstarthours(actstarthours);
timesheetTask.setActstartminutes(actstartminutes);
timesheetTask.setActendminutes(actendminutes);
timesheetTask.setActendhours(actendhours);
saveDataService service = new saveDataService();
service.saveData(timesheetTask);
}
System.out.println("SaveAction.execute().projectlist :: " + projectlist);
return SUCCESS;
}
}