Skip to content

Instantly share code, notes, and snippets.

@thiwanka-wickramage
Created June 9, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiwanka-wickramage/f65123299fb6a66436aa to your computer and use it in GitHub Desktop.
Save thiwanka-wickramage/f65123299fb6a66436aa to your computer and use it in GitHub Desktop.
Application
package com.max.Actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.max.ActionForms.LeaveApplyActionForm;
import com.max.Domain.LeaveDetails;
import com.max.Services.LeaveService;
public class LeaveApplyAction extends Action{
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {
LeaveApplyActionForm actionForm = (LeaveApplyActionForm)form;
LeaveDetails leaveDetails = new LeaveDetails();
leaveDetails.setFirstName(actionForm.getFirstName());
leaveDetails.setDivision(actionForm.getDivision());
leaveDetails.setLeaveType(actionForm.getLeaveType());
leaveDetails.setStartDate(actionForm.getStartDate());;
leaveDetails.setEndDate(actionForm.getEndDate());
leaveDetails.setTotDays(actionForm.getTotDays());
leaveDetails.setContactNo(actionForm.getContactNo());
leaveDetails.setLeaveReason(actionForm.getLeaveReason());
if (LeaveService.saveLeave(leaveDetails)) {
return mapping.findForward("success");
}
return mapping.findForward("fail");
}
}
package com.max.ActionForms;
import java.util.Date;
import org.apache.struts.validator.ValidatorActionForm;
import com.max.AppUtil.StringToDate;
public class LeaveApplyActionForm extends ValidatorActionForm{
private String firstName;
private String division;
private String leaveType;
private Date startDate;
private Date endDate;
private int totDays;
private int contactNo;
private String leaveReason;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getDivision() {
return division;
}
public void setDivision(String division) {
this.division = division;
}
public String getLeaveType() {
return leaveType;
}
public void setLeaveType(String leaveType) {
this.leaveType = leaveType;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = StringToDate.dateConvert(startDate);
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = StringToDate.dateConvert(endDate);
}
public int getTotDays() {
return totDays;
}
public void setTotDays(int totDays) {
this.totDays = totDays;
}
public int getContactNo() {
return contactNo;
}
public void setContactNo(int contactNo) {
this.contactNo = contactNo;
}
public String getLeaveReason() {
return leaveReason;
}
public void setLeaveReason(String leaveReason) {
this.leaveReason = leaveReason;
}
}
package com.max.Domain;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="leave_details")
public class LeaveDetails {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
private String firstName;
private String division;
private String leaveType;
private Date startDate;
private Date endDate;
private int totDays;
private int contactNo;
private String leaveReason;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getDivision() {
return division;
}
public void setDivision(String division) {
this.division = division;
}
public String getLeaveType() {
return leaveType;
}
public void setLeaveType(String leaveType) {
this.leaveType = leaveType;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date stratDate) {
this.startDate = stratDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public int getTotDays() {
return totDays;
}
public void setTotDays(int totDays) {
this.totDays = totDays;
}
public int getContactNo() {
return contactNo;
}
public void setContactNo(int contactNo) {
this.contactNo = contactNo;
}
public String getLeaveReason() {
return leaveReason;
}
public void setLeaveReason(String leaveReason) {
this.leaveReason = leaveReason;
}
}
package com.max.AppUtil;
public class StringToDate {
public static java.sql.Date dateConvert(String stringDate){
return java.sql.Date.valueOf(stringDate);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment