h:selectOneMenu with s:selectItems not binding to anything
cdiggins Jan 15, 2008 3:15 PMI have an h:selectOneMenu that contains an s:selectItems and an ec:convertEntity. With or without the convertEntity, I can not get the property the selectOneMenu is bound to be anything other than null.
<h:selectOneMenu value="#{employee.siEmpType}">
<s:selectItems value="#{employeeTypeList}"
var="empType" label="#{empType.siEmployeeTypeName}"
noSelectionLabel="Select Type" />
<ec:convertEntity />
</h:selectOneMenu>
package com.savageservices.dobi.shared.entity;
import java.sql.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;
import org.jboss.seam.annotations.Name;
import com.savageservices.dobi.payroll.entity.SiClassification;
import com.savageservices.dobi.payroll.entity.SiEmployeeType;
import com.savageservices.dobi.payroll.entity.SiPayGroup;
@Entity
@Name("employee")
public class SiEmployee {
private Integer ADPID;
private String ADPEmpStatus;
private Date siCdlExpire;
@ManyToOne
@JoinColumn(name="siClassificationID")
private SiClassification siClassification;
@Transient
private Integer siClassificationID;
@ManyToOne
@JoinColumn(name="siEmployeeTypeID")
private SiEmployeeType siEmpType;
@Transient
private Integer siEmployeeTypeID;
@Id
@GeneratedValue
private Integer siEmployeeID;
@Column(length=255,name="ADPEmpName")
private String siEmployeeName;
@Column(length=2,name="ADPIncomeState")
private String siIncomeState;
private Date siMvrExpire;
@ManyToOne
@JoinColumn(name="siPayGroupID")
private SiPayGroup siPayGroup;
@Transient
private Integer siPayGroupID;
private Date siPayrollProcessInputDate;
private Date siPhysicalExpire;
@Column(length=2,name="ADPUnemploymentState")
private String siUnemploymentState;
@ManyToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@JoinTable(name="SiEmployeeWorkingDepartment",
joinColumns=@JoinColumn(name="psDeptID"),
inverseJoinColumns=@JoinColumn(name="siEmployeeID"))
private List<PsDepartment> siWorkingDepts;
private Integer psDeptIDHome;
private Boolean siSetup;
private Double siDefaultPayRate;
@Transient
private String selectedDepartment;
//GETTERS AND SETTERS
...
}
package com.savageservices.dobi.shared.session.impl;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.faces.model.SelectItem;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.Conversational;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.End;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.annotations.datamodel.DataModelSelection;
import com.savageservices.dobi.payroll.entity.SiEmployeeType;
import com.savageservices.dobi.payroll.entity.SiPayGroup;
import com.savageservices.dobi.shared.converter.EmployeeConverter;
import com.savageservices.dobi.shared.entity.PsDepartment;
import com.savageservices.dobi.shared.entity.SiEmployee;
import com.savageservices.dobi.shared.entity.SiUser;
import com.savageservices.dobi.shared.session.Employee;
@Stateful
@Name("employeeBean")
@Conversational
public class EmployeeBean implements Employee {
@DataModelSelection
@Out(required=false)
@In(required=false)
private SiEmployee employee;
@DataModel
private List <SiEmployee> employeeList = new ArrayList<SiEmployee>();
@PersistenceContext(type=PersistenceContextType.EXTENDED)
EntityManager em;
@In(required=false)
SiUser user;
@Destroy @Remove
public void destroy() {
// TODO Auto-generated method stub
}
@Begin(join=true)
public String newEmployee() {
employee = new SiEmployee();
return "newEmployee";
}
@End
public String saveEmployee() {
if(validate()){
//employee.setSiPayGroup(em.find(SiPayGroup.class, employee.getSiPayGroupID()));
//employee.setSiEmpType(em.find(SiEmployeeType.class, employee.getSiEmployeeTypeID()));
em.merge(employee);
}
setup();
return "employeeList";
}
public String selectEmployee() {
return "editEmployee";
}
@Factory("employeeList")
@SuppressWarnings("unchecked")
@Begin(join=true)
public void setup() {
employeeList.clear();
String sql = "FROM SiEmployee order by ADPEmpName";
employeeList = em.createQuery(sql).getResultList();
}
private Boolean validate(){
return true;
}
/** Adds a department to the employee as a working department */
@Begin(join=true)
public String addWorkingDepartment(){
//add the working department to the employee working department list
employee.getSiWorkingDepts().add((PsDepartment)em.createQuery("FROM PsDepartment where DEPTID='" + employee.getSelectedDepartment() + "' AND EFF_STATUS = 'A'").getResultList().get(0));
return "editEmployee";
}
/**Returns a list of all employees for the current department for use in dropdowns */
@Begin(join=true)
public List<SiEmployee> getLoadEmployeesForCurrentDepartment(){
setup();
List<SiEmployee> employeeDropdown = employeeList;
return employeeDropdown;
}
}
My objective is to get the siEmpType property on the SiEmployee to reflect the object selected in the dropdown menu. Any help would be appreciated, thanks.