Converting to JSTL (Specificlly on calling methods)
I'm in the process of going the full JSTL way, and I've got an issue with the following scriplet, I have already transformed the variable displaying and conditions to the expression language (EL) but I'm not so sure of how to do it with method calling : here's my JSP code its positioned before the html markup:
UserDTO user = (UserDTO) session.getAttribute("user");
OrderDAO lnkOrder = new OrderDAO();
OrderDTO order = new OrderDTO();
CoverDAO lnkCover = new CoverDAO();
CoverDTO cover = new CoverDTO();
UpgradesDAO lnkUpgrades = new UpgradesDAO();
UpgradesDTO upgrades = new UpgradesDTO();
OrderAccessorieDAO lnkOrderAcc = new OrderAccessorieDAO();
List<OrderAccessorieDTO> orderAccessories = new ArrayList<OrderAccessorieDTO>();
开发者_运维问答 GroupColorsDAO lnkColors = new GroupColorsDAO();
List<ColorDTO> ColorList = new ArrayList<ColorDTO>();
ColorList = lnkColors.getGroupColors(user.getGroup());
AccessoryDAO lnkAcc = new AccessoryDAO();
List<AccessoryDTO> groupAccessories = new ArrayList<AccessoryDTO>();
groupAccessories = lnkAcc.getGroupAccessories(user.getGroup());
ChangesDAO lnkChanges = new ChangesDAO();
List<ChangeDTO> orderChanges = new ArrayList<ChangeDTO>();
String CurrentOrder = request.getParameter("CurrentOrder");
if (lnkOrder.exists(CurrentOrder)) {
order = lnkOrder.find(CurrentOrder);
cover = lnkCover.find(order.getReferenceNumber());
upgrades = lnkUpgrades.find(order.getReferenceNumber());
orderAccessories = lnkOrderAcc.getOrderAccessories(order.getReferenceNumber());
orderChanges = lnkChanges.getOrderChanges(order.getReferenceNumber());
}
As yo can see it's pretty much DAO and DTO objects, I know that it can be done using static methods and making custom taglibs but that would mean writing a code for each method call, any other approach?, suggestions accepted. A brief description of the VIEW
(HTML markup) it displays the details of a given order, the order name is extracted from a get
request.
Also I have another small question, suppose I port everything to JSTL, would I have to import the corresponding myDTO
and myDAO
packages to access its getters and setters for each DTO?
Regards Tristian.
"JSTL way" doesn't make sense without full separation between view and logic, as in Model 2 approach.
In Model 2 approach you move this code to the servlet that acts as a controller for your JSTL page, and only use JSP for view markup. Otherwise using JSTL to enforce separation between logic and view with JSTL would be meaningless.
The only work around (dirty) that I know is to expose the methods as a fake map, that is have a method that has a sig like "Object getSomething(Object o)". In this way you can pass an argument, and it gets around the imposed rules. Fugly but it works.
Agree with axtavt though
精彩评论