Bonjour,
pour mieux expliquer on probleme cité en haut.je veux faire la mise a jour d'un formulaire.
le code de la view:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
<h:form>
<h:messages layout="table" styleClass="erreur" warnClass="error"/>
<h:panelGrid columns="2">
<h:outputText value="#{messages.label_IdEmployee}" />
<h:selectOneMenu id="id" value="#{employeeBean.id}" title= "select"
valueChangeListener="#{employeeBean.onSelectId}" immediate ="true" onchange="submit()" >
<f:selectItems value="#{employeeBean.listIdEmployee}"/>
</h:selectOneMenu>
<h:outputText value="#{messages.label_NameEmployee}" />
<h:inputText id="name" required="true" value="#{employeeBean.name}"/>
<h:outputText value="#{messages.label_AgeEmployee}" />
<h:inputText id="age" required="true" value="#{employeeBean.age}"/>
<h:outputText value="#{messages.label_SalaryEmployee}" />
<h:inputText id="salary" required="true" value="#{employeeBean.salary}"/>
</h:panelGrid>
<h:commandButton action="#{employeeBean.doEdit}" value="#{messages.label_validate}" />
</h:form> |
le code du bean :EmployeeBean
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
|
public class EmployeeBean {
public static final String OUTCOME_SUCCESS="success";
// injection du bean
private EmployeeServiceImpl employeeService ;
/**
* logger
*/
private static Log log = LogFactory.getLog(EmployeeBean.class);
private Employee employee= new Employee();
// properties
private String id;
private String name;
private String age;
private String salary;
private List<SelectItem> listIdEmployee;
public EmployeeBean(){}
getter & setter
public List<SelectItem> getListIdEmployee() {
List<SelectItem> listItems = new ArrayList<SelectItem>();
List listObjects = new ArrayList();
try {
listObjects = employeeService.getEmployees();
} catch (Exception e) {
MessageSupport.addMessage(FacesMessage.SEVERITY_ERROR,"", "");
log.error("Erreur Hibernate lors de la r�cup�ration de l'objet Employee",e);
}
if (listObjects.isEmpty() == false){
listItems.add(new SelectItem(""));
for (int i = 0; i < listObjects.size(); i++){
Employee emp = (Employee) listObjects.get(i);
listItems.add(new SelectItem(emp.getId()));
}
}else{
listItems.add(new SelectItem(""));
}
return listItems;
}
public void onSelectId(final ValueChangeEvent event) throws AbortProcessingException{
log.info(" Chargement du l'employee :" );
if (event.getNewValue().toString() != "") {
this.id = event.getNewValue().toString();
// Get the employee values and add in the form
try {
this.employee = (Employee) employeeService.getEmployee(id);
this.setName(employee.getName());
this.setAge(employee.getAge());
this.setSalary(employee.getSalary());
FacesContext.getCurrentInstance().renderResponse();
log.info("*********** age client :" +employee.getAge());
}
catch (Exception e) {
MessageSupport.addMessage(FacesMessage.SEVERITY_ERROR, "erreur ", "");
log.error("Erreur Hibernate lors de la récupération de l'objet Employee", e);
}
}
else{
MessageSupport.addMessage(FacesMessage.SEVERITY_ERROR,
"", "Enregistrement requis");
throw new AbortProcessingException();
}
} |
le resultat: c'est que la liste des id de l'employee est chargé dans le select mais en selectionnant l'id ,les autres attribut ne sont pas affichés dans le formulaire.voici le message figuré dans la console:
juil. 2008 17:24:35 javabeat.bean.EmployeeBean onSelectId
INFO: Chargement du l'employee :
Hibernate: select employee0_.id as id0_0_, employee0_.Name as Name0_0_, employee0_.Age as Age0_0_, employee0_.Salary as Salary0_0_ from Employee employee0_ where employee0_.id=?
4 juil. 2008 17:24:35 javabeat.bean.EmployeeBean onSelectId
INFO: *********** age client :23
4 juil. 2008 17:24:35 javabeat.bean.EmployeeBean getListIdEmployee
INFO: *********** id client :
Hibernate: select this_.id as id0_0_, this_.Name as Name0_0_, this_.Age as Age0_0_, this_.Salary as Salary0_0_ from Employee this_
4 juil. 2008 17:24:35 javabeat.bean.EmployeeBean getListIdEmployee
INFO: *********** id client :
Hibernate: select this_.id as id0_0_, this_.Name as Name0_0_, this_.Age as Age0_0_, this_.Salary as Salary0_0_ from Employee this_
j'attends tjs vos suggestions.
merci.
Partager