1 | <evaluate expression="productService.getProducts()" result="flowScope.products" /> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package samples.webflow; import java.io.Serializable; public class Product implements Serializable { private static final long serialVersionUID = 1951520003958305899L; private int id; private String description; private int price; public Product(int id, String description, int price) { this.id = id; this.description = description; this.price = price; } /*省略getter和setter*/ } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package samples.webflow; /*省略import语句*/ @Service("productService") public class ProductService { /*products 用于存放多个商品 */ private Map<Integer, Product> products = new HashMap<Integer, Product>(); public ProductService() { products.put(1, new Product(1, "Bulldog", 1000)); products.put(2, new Product(2, "Chihuahua", 1500)); products.put(3, new Product(3, "Labrador", 2000)); } public List<Product> getProducts() { return new ArrayList<Product>(products.values()); } public Product getProduct(int productId) { return products.get(productId); } } |
1 2 3 4 5 6 | <view-state id="viewCart" view="viewCart" > <on-render> <evaluate expression="productService.getProducts()" result="viewScope.products"/> </on-render> <transition on="submit" to="viewOrder"> </transition> </view-state> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>View Cart</title> </head> <body> <h1>View Cart</h1> <h2>Items in Your Cart</h2> <a href="${flowExecutionUrl}&_eventId=submit">Submit</a> <h2>Products for Your Choice</h2> <table> <c:forEach var="product" items="${products}"> <tr> <td>${product.description}</td> <td>${product.price}</td> </tr> </c:forEach> </table> </body> </html> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |