i'm using primefaces schedule, when the dialog form pop up, i need to select data from SelectOneMenu and pass them to the add function in order to insert them into database the problem is that sometimes it works great and i can insert them, but when i try to add another second insert i doesn't work again can you check it out please? i need to know if i'm doing this the wrong way because i can't find the problem.
Managedbean constructor:
@PostConstruct
public void init() {
Chauffeurs = new ArrayList<Chauffeur>();
ChauffeurDispo = new dao.gsVoyage().getChauffeursDesponible(Chauffeurs);
model = new DefaultScheduleModel();
vDao=new dao.gsVoyage();
voyage=new Voyage();
try {
listVoyage=vDao.getListVoyages();
}catch(Exception ex) {
ex.printStackTrace();
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,"erreur","erreur no sql"));
}
for(Voyage v:listVoyage) {
DefaultScheduleEvent evt=new DefaultScheduleEvent();
evt.setEndDate(v.getDateV());
evt.setStartDate(v.getDateV());
evt.setDescription(v.getChauffeurBean().getMatricule());
evt.setData(v.getIdVoyage());
model.addEvent(evt);
}
}
the add function:
public void ajouter() {
try {
new dao.gsVoyage().addVoyage(dateV, autocar, chauffeur,chauffeur2,0);
DefaultScheduleEvent evt=new DefaultScheduleEvent();
evt.setEndDate(dateV);
evt.setStartDate(dateV);
evt.setDescription(chauffeur);
model.addEvent(evt);
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", e.getMessage()));
}
voyage = new Voyage();
}
xhtml of SelectOneMenu:
<label>Chauffeur :</label><br/>
<h:selectOneMenu
value="#{scheduleJava8View.chauffeur}">
<f:selectItems
value="#{scheduleJava8View.chauffeurDispo}"
var="chauffeur" itemValue="#{chauffeur.matricule}"
itemLabel="#{chauffeur.nom}" />
</h:selectOneMenu>
this is how i display inserted data in xhtml
<label>Chauffeur:</label><br/>
<p:inputText value="#{scheduleJava8View.voyage.chauffeurBean.matricule}" />
Try changing your code to this
<h:selectOneMenu
onchange="submit()"
value="#{scheduleJava8View.chauffeur}">
This will make a call to
setChauffeur(Chauffeur c)
on your backed bean. Notice that in this case, you will need to define a converter since it is not a Java basic type (int, String,...).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.