我正在用 EJB3.0 + JPA(休眠)学习 JSF
我正在从表中获取所有数据,但在屏幕上它没有显示任何内容。这是代码。
托管豆
package retail.web.mbean;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import javax.faces.bean.ManagedBean;
import javax.faces.event.AjaxBehaviorEvent;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import retail.ejb.service.OrderSessionBeanRemote;
import retail.model.vo.Customer;
import retail.model.vo.Order;
import retail.model.vo.Products;
@ManagedBean
public class OrdersMB {
private Order order = new Order();
private HashMap<Integer,String> customerMap = new HashMap<Integer,String>();
private HashMap<Integer,String> productsMap = new HashMap<Integer,String>();
private String customerName;
private String productName;
private List<Order> orderList;
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public HashMap<Integer, String> getCustomerMap() {
return customerMap;
}
public void setCustomerMap(HashMap<Integer, String> customerMap) {
this.customerMap = customerMap;
}
public HashMap<Integer,String> getProductsMap() {
return productsMap;
}
public void setProductsMap(HashMap<Integer, String> productsMap) {
this.productsMap = productsMap;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public List<Order> getOrderList() {
return orderList;
}
public void setOrderList(List<Order> orderList) {
this.orderList = orderList;
}
public void getOrderLists() throws NamingException{
Properties p = new Properties();
//p.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");
p.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
p.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
p.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
p.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); //any configured port different from 3700 - 34513
InitialContext c = new InitialContext(p);
OrderSessionBeanRemote remote = (OrderSessionBeanRemote) c.lookup("java:global/RetailProducts/OrderSessionBeanImpl!retail.ejb.service.OrderSessionBeanRemote");
List<Order> orderList = remote.getOrderLists();
setOrderList(orderList);
}
public void deleteOrder(Order order) throws NamingException{
Properties p = new Properties();
//p.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");
p.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
p.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
p.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
p.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); //any configured port different from 3700 - 34513
InitialContext c = new InitialContext(p);
OrderSessionBeanRemote remote = (OrderSessionBeanRemote) c.lookup("java:global/RetailProducts/OrderSessionBeanImpl!retail.ejb.service.OrderSessionBeanRemote");
remote.deleteOrder(order);
}
}
xhtml页面
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>List of Orders</title>
<script>
window.onload = function() {
document.getElementById('hidden:link').onclick();
}
</script>
<h:outputStylesheet library="css" name="table-style.css" />
</h:head>
<h:body>
<h:form id="hidden" style="display:none">
<h:commandLink id="link">
<f:ajax event="click" listener="#{order.getOrderLists}"/>
</h:commandLink>
</h:form>
<h1 style="background-color:#4863A0;color:white;">List of Orders</h1>
<f:view>
<h:form>
<table class="order-table">
<tr>
<th class="order-table-header">Order #</th>
<th class="order-table-header">Customer</th>
<th class="order-table-header">Item</th>
<th class="order-table-header">Action</th>
</tr>
<tbody>
<ui:repeat var="o" value="#{order.orderList}" >
<tr>
<td class="order-table-even-row">#{o.orderID}</td>
<td class="order-table-even-row">#{o.customerName}</td>
<td class="order-table-even-row">#{o.productTile}</td>
<td class="order-table-even-row"><h:commandLink value="Delete" action="#{order.deleteOrder(o)}" /></td>
</tr>
</ui:repeat>
</tbody>
</table>
</h:form>
<table >
<tr><td>Total Customers: 1</td>
</tr>
</table>
<div style=" border-bottom: 5px ridge blue;"> </div>
<table>
<tr>
<td><h:outputLink value="createbook.xhtml">Create a new Order</h:outputLink>|</td><td><h:outputLink value="eBusiness.jsp">Main Page</h:outputLink></td>
</tr>
</table>
</f:view>
</h:body>
</html>