1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| package view;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.inject.Produces;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import entities.*;
import service.ServiceProvider;;
@ConversationScoped
@Named("editService")
public class ServiceBean implements Serializable
{
private static final long serialVersionUID = -1089153575165747678L;
@Inject private FacesContext facesContext;
@Inject private ServiceProvider sp;
private String dateDebChoix;
private String dateFinChoisi;
private Service Service;
public String getDateFinChoisi()
{
return dateFinChoisi;
}
public void setDateFinChoisi(String dateFinChoisi)
{
this.dateFinChoisi = dateFinChoisi;
}
public String getDateDebChoix()
{
return dateDebChoix;
}
public void setDateDebChoix(String dateDebChoix)
{
this.dateDebChoix = dateDebChoix;
}
@PostConstruct
public void init()
{
if (Service == null) {
String ServiceId = (String) facesContext.getExternalContext()
.getRequestParameterMap().get("id");
if (ServiceId != null)
{
try
{
Service = sp.getService(Integer.parseInt(ServiceId));
}
catch (NumberFormatException e)
{
facesContext.addMessage(null, new FacesMessage(ServiceId
+ " n'est pas un n° de service valide"));
}
/*catch (AgentNotFoundExcsption e)
{
facesContext.addMessage(null, new FacesMessage("service "
+ ServiceId + " non trouvé"));
}*/
}
}
}
@Produces @Named
public Service getCurrentService()
{
return Service;
}
public static Date stringToDate(String sDate, String sFormat) throws Exception
{
SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
return sdf.parse(sDate);
}
public void save()
{
try
{
System.out.println("Date Début=="+this.getDateDebChoix());
System.out.println("Date Fin=="+this.getDateFinChoisi());
Date dateChoisidebut = stringToDate(dateDebChoix,"full");
Date dateChoisifin = stringToDate(dateFinChoisi,"full");
Service.setDateDeb_se(dateChoisidebut);
Service.setDateFin_se(dateChoisifin);
sp.saveService(Service);
sp.flush();
}
catch (Exception e)
{
facesContext.addMessage(null, new FacesMessage(e.getMessage()));
}
finally
{
sp.clear();
}
}
} |