ONJava.com -- JBoss Seam --> page 3
2007-01-29 10:00
459 查看
第 1, 2, 3, 4, 5 页
我们需要确保后退按钮和多标签或窗口不会破坏应用程序,并且能够正常工作。 为此,将引入一个“交谈”,它在执行搜索时开始,在用户为定单付款时结束。 让我们从一个会话 Bean 入手,它将负责处理搜索操作并在结果之间导航:
这个有态会话 Bean 被存储在交谈的上下文中,它将存活于交谈中,并在交谈结束时消亡。 购物车是由 Seam 管理的另一会话 Bean 组件,并被注入到
我们需要确保后退按钮和多标签或窗口不会破坏应用程序,并且能够正常工作。 为此,将引入一个“交谈”,它在执行搜索时开始,在用户为定单付款时结束。 让我们从一个会话 Bean 入手,它将负责处理搜索操作并在结果之间导航:
package com.jboss.dvd.seam; import [...] @Stateful @Name("search") @Conversational(ifNotBegunOutcome="main") @Scope(ScopeType.CONVERSATION) @Interceptors(SeamInterceptor.class) public class SearchAction implements Search, Serializable { @In(create=true) ShoppingCart cart; @PersistenceContext(unitName="dvd") EntityManager em; private int pageSize = 20; private int currentPage = 0; private boolean hasMore = false; private Category category = null; private String title = null; private String actor = null; @Out(scope=CONVERSATION,required=false) List <Product> searchResults; @Out(scope=CONVERSATION,required=false) Map <Product, Boolean> searchSelections; // Getters and setters for // category, title and actor @Begin(join=true, processDefinition="shopping") public String doSearch() { currentPage=0; updateResults(); return "browse"; } public String nextPage() { if (!isLastPage()) { currentPage++; updateResults(); } return null; } public String prevPage() { if (!isFirstPage()) { currentPage--; updateResults(); } return null; } public boolean isLastPage() { return (searchResults != null) && !hasMore; } public boolean isFirstPage() { return (searchResults != null) && (currentPage == 0); } private void updateResults() { [...] searchResults = [...] searchSelections = [...] } private Query searchQuery(String title, String actor, Category category) { title = (title == null) ? "%" : "%" + title.toLowerCase() + "%"; actor = (actor == null) ? "%" : "%" + actor.toLowerCase() + "%"; if (category == null) { return em.createQuery( "from Product p where lower(p.title) like " + ":title and lower(p.actor) LIKE :actor") .setParameter("title", title) .setParameter("actor", actor); } else { return em.createQuery( "from Product p where lower(p.title) like " + ":title and lower(p.actor) like :actor " + "and p.category = :category") .setParameter("title", title) .setParameter("actor", actor) .setParameter("category", category); } } public String addToCart() { for (Product item: searchResults) { Boolean selected = searchSelections.get(item); if ( selected!=null && selected ) { searchSelections.put(item, false); cart.addProduct(item, 1); } } return "browse"; } @Destroy @Remove public void destroy() {} }
这个有态会话 Bean 被存储在交谈的上下文中,它将存活于交谈中,并在交谈结束时消亡。 购物车是由 Seam 管理的另一会话 Bean 组件,并被注入到
SearchAction会话 Bean,这样便不会在在建立多个搜索时丢失它。
searchResults和
searchSelections对象将存活于当前交谈中;它们占用的内存将在交谈结束时释放。
第 1, 2, 3, 4, 5 页 | 下一页 |
相关文章推荐
- ONJava.com -- JBoss Seam --> page 4
- ONJava.com -- JBoss Seam --> page 5
- ONJava.com -- JBoss Seam --> page 1
- ONJava.com -- Web 服务实现中的概念分离 --> page 3
- ONJava.com -- Web 服务实现中的概念分离 --> page 1
- ONJava.com -- Web 服务实现中的概念分离 --> page 2
- ONJava.com -- Jboss-seam --> page 2
- at com.android.xiong.aysnctasktest.MainActivity$PageTask.onPostExecute(MainActivity.java:116)
- com.android.xiong.aysnctasktest.MainActivity$PageTask.onPostExecute(MainActivity.java:116)
- java.lang.NoSuchMethodException: com.onion.po.UserInfo.<init>()
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>报错
- How to sort a Map<Key, Value> on the values in Java?
- 解决报错:java.lang.NoSuchMethodException: com.tangyuan.entity.RicherProduct.<init>()
- c# 和 java <转载>http://www.cnblogs.com/zhucai/archive/2011/02/16/csharp-compare-java.html
- com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK.
- Java网络爬虫crawler4j学习笔记<21> Page 类
- Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.bui
- java链接MongoDB:com.mongodb.MongoException$CursorNotFound: cursor 0 not found on server /127.0.0.1:270
- java.lang.NoSuchMethodException: com.asia.pojo.User.<init>()
- java.lang.NoSuchMethodException: com.xxx.xxx.xxx<init>()