0

このコードで従業員テーブルを更新するjsfページがあります....データを取得できますが、primefacesで更新できません。デバッグしても何もしません。データを更新するのに助けが必要です。ありがとう、これは私のページコントローラーです

@ManagedBean(name = "homebean")
@ViewScoped
public class HomeController implements Serializable {

    private Employee employee;
    private List<Employee> employees;
    private EmployeeeDAO employeeeDAO;

    public HomeController() {
        employeeeDAO = new EmployeeDAOImpl();
    }

    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    public List<Employee> getEmployees() {

        return employees;
    }

    public void setEmployees(List<Employee> employees) {
        this.employees = employees;
    }

    public void editEmployee() throws SQLException {
        Employee e = this.getEmployee();
        employeeeDAO.update(e);
    }

    @PostConstruct
    private void getListEmployees() {
        employees = employeeeDAO.employees(20, 10);
    }
}

これが私のDAOです

public class EmployeeDAOImpl implements EmployeeeDAO, Serializable {

    private PreparedStatement ps;
    private ResultSet rs;

    @Override
    public void add(Employee emp) {
        try (Connection c = ConnectionHelper.getConnection()) {
            String sql = "UPDATE EMPLOYEES"
                    + "   SET FIRST_NAME = ?,"
                    + "       LAST_NAME = ?,"
                    + "       EMAIL = ? WHERE EMPLOYEE_ID=?";


            ps = c.prepareStatement(sql);
            ps.setString(1, emp.getFirstname());
            ps.setString(2, emp.getLastname());
            ps.setString(3, emp.getEmail());
            ps.setInt(4, emp.getEmployeeId());
            ps.executeUpdate();
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        } catch (SQLException ex) {
            Logger.getLogger(EmployeeDAOImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void update(Employee emp) throws SQLException {
        try (Connection c = ConnectionHelper.getConnection()) {
            String sql = "UPDATE EMPLOYEES "
                    + "   SET FIRST_NAME = ?,"
                    + "       LAST_NAME = ?,"
                    + "       EMAIL = ? WHERE EMPLOYEE_ID=?";


            ps = c.prepareStatement(sql);
            ps.setString(1, emp.getFirstname());
            ps.setString(2, emp.getLastname());
            ps.setString(3, emp.getEmail());
            ps.setInt(4, emp.getEmployeeId());
            ps.execute();
        } catch (SQLException ex) {
            Logger.getLogger(EmployeeDAOImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public List<Employee> employees(int size, int lastRow) {
        List< Employee> list = null;
        try (Connection c = ConnectionHelper.getConnection()) {
            String sql = "SELECT ROWNUM NUM,EMP.* FROM EMPLOYEES EMP ORDER BY ROWNUM";

            ps = c.prepareStatement(sql);
            rs = ps.executeQuery();
            list = new ArrayList<Employee>();
            while (rs.next()) {
                Employee e = new Employee();
                e.setEmployeeId(rs.getInt("EMPLOYEE_ID"));
                e.setFirstname(rs.getString("FIRST_NAME"));
                e.setLastname(rs.getString("LAST_NAME"));
                e.setEmail(rs.getString("EMAIL"));
                e.setHireDate(rs.getDate("hire_date"));
                e.setSalary(rs.getBigDecimal("salary"));
                list.add(e);
            }
        } catch (Exception e) {
        }
        return list;
        // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Employee getById(String id) {

        return null;
        //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}

これはjsfページです..

            <p:dataTable id="employeetable" value="#{homebean.employees}" var="emp" rows="10" paginator="true"
                         selection="#{homebean.employee}">

                <p:column headerText="First Name">#{emp.firstname}</p:column>
                <p:column headerText="First Name">#{emp.lastname}</p:column>
                <p:column headerText="First Name"><h:outputText value="#{emp.salary}">
                        <f:convertNumber type="currency" currencySymbol="$ "/>
                    </h:outputText></p:column>
                <p:column headerText="First Name">#{emp.email}</p:column>
                <p:column width="50">
                    <p:commandButton value="Edit" oncomplete="editdialog.show();"
                                     partialSubmit="true" update="@([id$=display])">
                        <f:setPropertyActionListener value="#{emp}" target="#{homebean.employee}" />
                    </p:commandButton>
                </p:column>
            </p:dataTable> 

        </h:form>
        <h:form>
            <p:dialog widgetVar="editdialog" id="edit" modal="true" appendToBody="true" resizable="false">

                <h:panelGrid id="display" columns="2" cellspacing="4">
                    <h:outputText value="ID"/>
                    <p:inputText value="#{homebean.employee.employeeId}" disabled="true">
                        <f:convertNumber type="number"/></p:inputText>
                    <p:spacer/><p:spacer/>
                    <h:outputText value="First Name"/>
                    <h:outputText value="Last Name"/>
                    <p:inputText value="#{homebean.employee.firstname}"/>
                    <p:inputText value="#{homebean.employee.lastname}"/>
                    <h:outputText value="Email"/>
                    <h:outputText value="Salary"/>
                    <p:inputText value="#{homebean.employee.email}"/>

                </h:panelGrid>
                <p:separator/>
                <p:commandButton value="save" action="#{homebean.editEmployee()}" partialSubmit="true"
                                 update="@([id$=employeetable])" oncomplete="editdialog.hide();"/>
            </p:dialog>

        </h:form>
    </ui:define>
4

1 に答える 1

0

最後に答えが得られました....従業員のプロパティが正しいことを確認する必要があります。そして、データ型をデータベースと一致させます...すべてに感謝します

于 2013-05-15T16:50:28.860 に答える