Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form>
- <div id="eTable">
- <p:dataTable value="#{feeding.updateData()}" var="avv">
- <p:column headerText="No.">
- <h:outputText value="#{avv.ID}" />
- </p:column>
- <p:column headerText="Utterance">
- <h:outputText value="#{avv.editUtterance}" />
- </p:column>
- <p:column headerText="Device response">
- <h:outputText value="#{avv.editDeviceResponse}" />
- </p:column>
- <p:column headerText="Comments">
- <h:outputText value="#{avv.editComments}" />
- </p:column>
- <p:column>
- <center> <p:commandButton value="Delete" action="#{feeding.delete(avv.ID)}"/> </center>
- </p:column>
- </p:dataTable>
- </div>
- List<feeding> editboard;
- public List<feeding> getEditBoard() {
- return editboard;
- }
- public List<feeding> updateData() {
- editboard = new ArrayList<feeding>();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/combi", "root", "#doubleinfinity7");
- ResultSet rs = null;
- conn.setAutoCommit(false);
- String str = "select * from device_assessment";
- PreparedStatement pst = conn.prepareStatement(str);
- rs = pst.executeQuery(str);
- while (rs.next()) {
- feeding usrr = new feeding();
- usrr.setEditUtterance(rs.getString("utterance"));
- usrr.setEditDeviceResponse(rs.getString("response"));
- usrr.setEditComments(rs.getString("comments"));
- usrr.setID(rs.getLong("ID"));
- editboard.add(usrr);
- Map<Long, Boolean> checked = new HashMap<Long, Boolean>();
- List<feeding> checkedItems = new ArrayList<feeding>();
- for (feeding item : editboard) {
- if (checked.get(item.getID()) != null) {
- checkedItems.add(item);
- usrr.delete(usrr.getID());
- }
- }
- }
- } catch (ClassNotFoundException | SQLException e) {
- throw new FacesException(e);
- }
- return editboard;
- }
- public void delete(long ID) {
- if (ID != 0) {
- System.out.println(" current ID : " + ID);
- FacesContext context = FacesContext.getCurrentInstance();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/combi", "root", "#doubleinfinity7");
- conn.setAutoCommit(false);
- String sql = "delete from device_assessment where ID=" + ID;
- PreparedStatement pst = conn.prepareStatement(sql);
- int i = pst.executeUpdate();
- if (i > 0) {
- System.out.println("Row deleted successfully");
- }
- conn.commit();
- context.addMessage(null, new FacesMessage("Successfully", "Deleted"));
- } catch (ClassNotFoundException | SQLException e) {
- throw new FacesException(e);
- }
- }
- }
Add Comment
Please, Sign In to add comment