Skip to content

Commit

Permalink
DynamicNavBar
Browse files Browse the repository at this point in the history
  • Loading branch information
jskno committed Aug 24, 2015
1 parent f3fbc5c commit 6b0c074
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 28 deletions.
7 changes: 7 additions & 0 deletions WebContent/jsp/newCompany.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
</div>
<form class="form-horizontal" role="form" action="notes/addElement" method="POST">
<input type="hidden" name="action" value="addCompany"/>
<div class="form-group">
<label class="control-label col-sm-2" for="taxID">Tax ID:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="taxID" id="taxID"
placeholder="Enter the tax ID">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="companyName">Company Name:</label>
<div class="col-sm-10">
Expand Down
2 changes: 1 addition & 1 deletion WebContent/jsp/newCustomer.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

<!-- Modal content-->
<div class="modal-content">
<form id="newCompanyModalForm" class="form-horizontal" role="form" action="notes" method="POST">
<form id="newCompanyModalForm" class="form-horizontal" role="form" action="notes/addElement" method="POST">
<input type="hidden" name="action" value="addCompany"/>
<input type="hidden" name="originScreen" value="newCustomerForm"/>
<div class="modal-header">
Expand Down
4 changes: 2 additions & 2 deletions WebContent/jsp/newNoteForm.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<jsp:include page="navBar.jsp" flush="true" />
<%@ include file="navBar.jsp" %>
<jsp:include page="dynamicNavBar.jsp" flush="true" />
<%@ include file="dynamicNavBar.jsp" %>
</div>
</div>
<div class="well">
Expand Down
Binary file modified build/classes/controller/BusinessNotesController.class
Binary file not shown.
5 changes: 5 additions & 0 deletions src/controller/BusinessLookUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import service.GetSuppliersListService;
import service.ImportTableService;
import service.NewCompanyFormService;
import service.NewCustomer2Service;
import service.NewCustomerService;
import service.NewNoteFormService;
import service.GetProductsListService;
Expand All @@ -25,6 +26,7 @@ public class BusinessLookUp {
private final String NEW_NOTE = "newNote";
private final String NOTE_LIST = "notesList";
private final String NEW_CUSTOMER = "newCustomer";
private final String NEW_CUSTOMER_2 = "newCustomer2";
private final String CUSTOMER_LIST = "customersList";
private final String NEW_SUPPLIER = "newSupplier";
private final String SUPPLIERS_LIST = "suppliersList";
Expand Down Expand Up @@ -56,6 +58,9 @@ public Service getBusinessService(String serviceType) {
case NEW_CUSTOMER:
serviceClass = new NewCustomerService();
break;
case NEW_CUSTOMER_2:
serviceClass = new NewCustomer2Service();
break;
case CUSTOMER_LIST:
serviceClass = new GetCustomerListService();
break;
Expand Down
12 changes: 7 additions & 5 deletions src/controller/BusinessNotesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import javax.servlet.http.HttpServletResponse;

import service.Service;
import utils.DBUtil;
import model.Company;
import model.Customer;
import model.Menu;
import model.Note;
import model.Product;
import model.Supplier;
Expand All @@ -27,8 +29,8 @@
import dao.NoteDAOImpl;
import dao.ProductDAO;
import dao.ProductDAOImpl;
import dao.SubMenuDAO;
import dao.SubMenuDAOImpl;
import dao.MenuDAO;
import dao.MenuDAOImpl;
import dao.SupplierDAO;
import dao.SupplierDAOImpl;
import excelUtils.ExportTable;
Expand All @@ -44,10 +46,10 @@ public class BusinessNotesController extends HttpServlet {
public void init(ServletConfig config) throws ServletException {

super.init(config);
SubMenuDAO subMenuDao = new SubMenuDAOImpl(null, null);
Map<String, List<String>> subMenusList = subMenuDao.getSubMenus();
MenuDAO menuDao = new MenuDAOImpl(DBUtil.getConnection(), null);
Map<Integer, Menu> theMenu = menuDao.getMenu();
ServletContext context = config.getServletContext();
context.setAttribute("subMenusList", subMenusList);
context.setAttribute("theMenu", theMenu);
}

protected void doGet(HttpServletRequest request,
Expand Down
14 changes: 7 additions & 7 deletions src/controller/BusinessNotesControllerRedirect.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import javax.servlet.http.HttpServletResponse;

import service.Service;
import dao.SubMenuDAO;
import dao.SubMenuDAOImpl;
import dao.MenuDAO;
import dao.MenuDAOImpl;

public class BusinessNotesControllerRedirect extends HttpServlet {

Expand All @@ -24,11 +24,11 @@ public class BusinessNotesControllerRedirect extends HttpServlet {

public void init(ServletConfig config) throws ServletException {

super.init(config);
SubMenuDAO subMenuDao = new SubMenuDAOImpl(null, null);
Map<String, List<String>> subMenusList = subMenuDao.getSubMenus();
ServletContext context = config.getServletContext();
context.setAttribute("subMenusList", subMenusList);
// super.init(config);
// MenuDAO subMenuDao = new MenuDAOImpl(null, null);
// Map<String, List<String>> subMenusList = subMenuDao.getSubMenus();
// ServletContext context = config.getServletContext();
// context.setAttribute("subMenusList", subMenusList);
}

protected void doGet(HttpServletRequest request,
Expand Down
13 changes: 13 additions & 0 deletions src/dao/MenuDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dao;

import java.util.List;
import java.util.Map;

import model.Menu;
import model.SubMenu;

public interface MenuDAO extends Dao{

Map<Integer, Menu> getMenu();

}
80 changes: 80 additions & 0 deletions src/dao/MenuDAOImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import java.util.TreeMap;

import javax.servlet.http.HttpSession;

import persistence.DDBBMenu;
import persistence.DDBBSubMenu;
import model.Menu;
import model.Product;
import model.SubMenu;

public class MenuDAOImpl extends DaoImpl implements MenuDAO {

private static final String SQL_MENU = "SELECT * FROM MENU ORDER BY ID_MENU";
private static final String SQL_SUBMENU = "SELECT * FROM SUBMENU "
+ "WHERE ID_MENU = ? ORDER BY ID_SUBMENU";

public MenuDAOImpl(Connection connection, HttpSession session) {
super(connection, session);
// TODO Auto-generated constructor stub
}

@Override
public Map<Integer, Menu> getMenu() {

Map<Integer, Menu> theMenu = new TreeMap<Integer, Menu>();

PreparedStatement statement = null;
ResultSet resultSet = null;

PreparedStatement stmt = null;
ResultSet rs = null;

//Product product = new Product();
try {
DDBBMenu ddbbMenu = new DDBBMenu();
Menu menu = new Menu();
statement = connection.prepareStatement(SQL_MENU);
resultSet = statement.executeQuery();

while (resultSet.next()) {
ddbbMenu.loadResult(resultSet);
menu.setFromPersistence(ddbbMenu);
try {
DDBBSubMenu ddbbSubMenu = new DDBBSubMenu();
SubMenu subMenu = new SubMenu();

stmt = connection.prepareStatement(SQL_SUBMENU);
stmt.setInt(1, ddbbMenu.getIdMenu());
rs = stmt.executeQuery();

while(rs.next()) {
ddbbSubMenu.loadResult(rs);
subMenu.setFromPersistence(ddbbSubMenu);
menu.getSubMenus().add(subMenu);
}
} catch(SQLException e) {
e.printStackTrace();
}


}
theMenu.put(menu.getOrder(), menu);
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
closeStmtAndRs(stmt, rs);
closeStmtAndRs(statement, resultSet);

}
return theMenu;
}

}
4 changes: 3 additions & 1 deletion src/dao/SubMenuDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.util.List;
import java.util.Map;

import model.Menu;
import model.SubMenu;

public interface SubMenuDAO extends Dao{

Map<String, List<String>> getSubMenus();

}
6 changes: 4 additions & 2 deletions src/dao/SubMenuDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

import javax.servlet.http.HttpSession;

public class SubMenuDAOImpl extends DaoImpl implements SubMenuDAO {
import model.Menu;

public class SubMenuDAOImpl extends DaoImpl implements MenuDAO {

public SubMenuDAOImpl(Connection connection, HttpSession session) {
super(connection, session);
// TODO Auto-generated constructor stub
}

@Override
public Map<String, List<String>> getSubMenus() {
public Map<Integer, Menu> getMenu() {
// TODO Auto-generated method stub
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/service/AddCompanyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public class AddCompanyService extends ServiceImpl implements Service {
protected void execute() {

createCompany();
String originScreen = request.getParameter("origin");
String originScreen = request.getParameter("originScreen");
switch (originScreen) {
case "newCustomer":
case "newCustomerForm":
request.setAttribute("newAction", "newCustomer");
break;
case "newSupplier":
case "newSupplierForm":
request.setAttribute("newAction", "newSupplier");
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/service/NewCustomerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private void getNoCustomerCompanies(HttpServletRequest request,
HttpServletResponse response) {

try {
CompanyDAO companyDao = new CompanyDAOImpl(null, null);
CompanyDAO companyDao = new CompanyDAOImpl(getConnection(), getSession());
List<Company> companiesList = companyDao.getNoCustomerCompanies();
request.setAttribute("companiesList", companiesList);
} catch (Exception e) {
Expand Down
4 changes: 0 additions & 4 deletions src/service/NewNoteFormService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,5 @@ private void getSuppliersList() {
} catch (Exception e) {
System.out.println(e);
}

}



}
20 changes: 18 additions & 2 deletions src/service/ServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public abstract class ServiceImpl implements Service{
public void execute(HttpServletRequest request, HttpServletResponse response) //throws BusinessRuleException,SQLException
{
//Pool pool = null;
request = request;
response = response;
setRequest(request);
setResponse(response);
connection = null;
session = request.getSession();

Expand Down Expand Up @@ -165,6 +165,22 @@ public void closeTwoConnection(Connection connection, PreparedStatement ps) {
}

}

public HttpServletRequest getRequest() {
return request;
}

public void setRequest(HttpServletRequest request) {
this.request = request;
}

public HttpServletResponse getResponse() {
return response;
}

public void setResponse(HttpServletResponse response) {
this.response = response;
}



Expand Down

0 comments on commit 6b0c074

Please sign in to comment.