- 浏览: 99588 次
文章分类
最新评论
-
jXee:
lgs0626 写道求源码,兄弟给共享下吧 "jee ...
jee6 学习笔记 4 - CRUD 2: View Details, Primefaces row selection -
lgs0626:
求源码,兄弟给共享下吧
jee6 学习笔记 4 - CRUD 2: View Details, Primefaces row selection
javax.faces.bean.ViewScoped said as long as you stay on the same view/page, the backing bean should be the same. This is useful if you want to retain some state of the backing bean, whilst avoid caching too much stuff in the session. I think it's quite useful in the searching/pagination screens.
However, my previous testing showed that it's not as expected in that it created new instances for different request for the searchStudent screen.
A recent reading solved this myth.
The problem is that although the search method "findByName" returned the same page "student/studentSearch.xhtml", JSF treated it as different view. To make it "stays on the same view", the search method in the backing bean should return null or nothing. Here's how it should look like:
@ManagedBean(name="ss") @ViewScoped public class StudentSearch implements Serializable { ... public void findByName() { log.debug("searching student for name: " + this.nameFilter); searchResultList = dao.find(this.nameFilter, maxRows); } or public String findByName() { log.debug("searching student for name: " + this.nameFilter); searchResultList = dao.find(this.nameFilter, maxRows); return null; } ... }
If we code the search method like this, JSF would think it stays on the same view and javax.faces.bean.ViewScoped should be working as expected. This would enbable you replace the @SessionScoped backing bean, if you are concerned about caching too many objects in session.
This is working, but if you take a look at the server log, JSF2 actually still creates a new instance for you if you click column header to sort, or a page number to goto etc. But it manges to maintain the state for you, transparently.
If you really want to stick to the "same" instance, it looks like that you can configure one of these JSF properties in "web.xml". Use of "javax.faces.FULL_STATE_SAVING_VIEW_IDS" is recommended and you can define a comma separated list of pages/view for it.
<!-- it's said that this would incur performance cost <context-param> <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name> <param-value>false</param-value> </context-param> --> <context-param> <param-name>javax.faces.FULL_STATE_SAVING_VIEW_IDS</param-name> <param-value>/student/studentSearch.xhtml,/student/studentDetails.xhtml</param-value> </context-param>
So lets sum it up here:
-- from: http://balusc.blogspot.co.nz/2010/06/benefits-and-pitfalls-of-viewscoped.html
发表评论
-
ActiveMQ and Spring JMS Framework Message Loss
2019-06-28 07:15 29Java Message Service (JMS) prov ... -
how to proxy to k8s web console
2018-06-28 07:16 564### how to access k8s web conso ... -
Call Stored Procedure with JPA 2.1
2018-06-27 10:57 657JPA 2.1 introduces APIs to call ... -
Send response and then process - async processing
2017-10-12 09:35 555If your request processing take ... -
java 8 time api test
2017-08-29 05:40 477public class ParseUtcDateTime ... -
Setup ApiKey in header with Swagger generated client code
2017-08-23 06:41 472@Value("${api.base.path} ... -
Simple tool to monitor jvm memory usage and garbage collection
2016-10-13 06:06 359JDK has built-in tool to moni ... -
Externalize Application Config properties with JBoss 7.1
2017-06-02 12:09 335If you have configuration pro ... -
JPA native query does not support setting list parameters
2014-03-27 06:45 1009you might want to do the ... -
Owning Side and Inverse Side of JPA entity relationships
2013-09-10 07:08 804Entity relationships may be b ... -
avoid setParameter for "order by" in JPQL
2013-03-07 05:55 777you might want to create a JP ... -
JPA Path Expression, operator IN and Collection properties
2013-01-23 16:25 1393If we want to select the Orde ... -
与JEE6/EJB3.1相比, Spring framework 丧失了几乎所有的优势
2013-01-19 13:13 1035The Spring framework was a ma ... -
Simple EasyMock tutorial
2012-12-20 11:57 671http://veerasundar.com/blog/20 ... -
Servlet 3.0 @WebFilter and @WebServlet
2012-12-04 07:09 2677Servlet 3.0 provides new annota ... -
When to configure an XA datasource?
2012-11-16 12:58 1264If you ever came across this wa ... -
java ee transaction and datasource concepts
2012-11-10 13:48 10441. What is a transaction? A tra ... -
pass params to primefaces confirmation dialog box
2012-09-28 19:30 1335<p:dataTable id="idStuD ... -
Handle Big Dataset with Real Pagination with Primefaces 3.3 LazyDataModel
2012-09-21 13:41 5619If you have millions of record ... -
why Oracle sequence not working with JPA entity ID?
2012-09-19 08:08 968Suppose you have an Oracle seq ...
相关推荐
`@ViewScoped`是JavaServer Faces(JSF)框架中的一个注解,用于管理bean的作用域,它在处理这些操作时扮演着重要角色。本项目"AulaJava-ExercicioCRUDAlunos"就是一个使用@ViewScoped进行简单CRUD操作的实践示例。 ...
5. **Managed Bean注解支持**:JSF2支持使用`@ManagedBean`和`@ViewScoped`等注解来声明和管理Bean,简化了代码并增强了可读性。 6. **CDI集成**:JSF2与Java EE的Contexts and Dependency Injection (CDI)框架集成...
2. `@SessionScoped`、`@ApplicationScoped`、`@ViewScoped`和`@RequestScoped`:这些注解定义了Bean的作用域。`@SessionScoped`表示Bean在用户会话期间有效,`@ApplicationScoped`在整个应用程序中只有一个实例,`@...
5. **注解驱动**:JSF 2大量引入了注解,如`@ManagedBean`、`@ViewScoped`和`@Inject`,使得配置更加简洁,降低了XML配置文件的依赖。 6. **CDI集成**:JSF 2与Contexts and Dependency Injection (CDI)框架紧密...
在JSF2中,可以通过注解如`@ManagedBean` 和 `@ViewScoped` 来轻松创建和配置bean。例如,我们可以定义一个名为`UserBean` 的bean,用于处理用户的登录信息。 4. **EL表达式** Expression Language (EL) 是JSF中的...
`@ManagedBean`注解标记一个类作为JSF管理Bean,而`@ViewScoped`则定义了Bean的作用范围,使得Bean的生命周期与特定视图(页面)关联。此外,还可以使用`@FacesConverter`和`@FacesValidator`注解来自定义转换器和...
在JSF2中,我们可以通过在`@ManagedBean`注解上使用`@ViewScoped`或`@SessionScoped`等来控制bean的生命周期,进而影响导航。例如,如果一个bean是视图作用域,那么当导航发生时,该bean会被销毁;如果是会话作用域...
《JSF2》是关于JSF的第二版,相比第一版,JSF2引入了许多新特性,如Facelets作为默认视图层技术,使得视图更易于维护;引入了Partial State Saving,降低了服务器内存消耗;支持CDI(Contexts and Dependency ...
**JSF 2.0(JavaServer Faces 2.0)详解** JavaServer Faces (JSF) 是一种用于构建Web应用程序的Java EE框架,它专注于视图层的开发。JSF 2.0是该框架的一个重要版本更新,带来了许多改进和新特性,极大地提升了...
**JSF分页组件2详解** JavaServer Faces (JSF) 是Java平台上的一个用于构建Web应用程序的MVC(Model-View-Controller)框架。在处理大量数据时,分页功能是必不可少的,它能够帮助用户更有效地浏览和管理信息。在...
**JSF2 入门指南** JavaServer Faces (JSF) 是一个用于构建Web应用程序的MVC(模型-视图-控制器)框架,由Java Community Process(JCP)开发并维护。JSF 2.0是该框架的一个重要版本,引入了许多改进和新特性,使得...
《JSF2和RichFaces4使用指南》这本书可能涵盖了如何配置JSF环境,创建和使用Managed Beans,理解JSF生命周期,以及如何利用RichFaces 4的组件进行高效开发。通过阅读这本书,开发者可以深入理解JSF2和RichFaces4的...
JSF的学习入门知识教程,里面有例子还有各个标签的使用及属性介绍
这些bean可以被JSF组件直接引用,通过`@ManagedBean`和`@ViewScoped`等注解进行管理。 **EL(Expression Language)** 是JSF的一部分,它是一种强大的表达式语言,用于在视图层获取和设置Managed Bean的属性。EL...
JSF的`@ManagedBean`注解用于标记一个类为JSF管理的Bean,而`@ViewScoped`或`@RequestScoped`则定义Bean的作用域。在JSF页面中,可以通过EL(Expression Language)和Primefaces组件来访问和展示数据。 例如,一个...
- Managed Beans是JSF中的业务逻辑组件,可以使用注解定义bean及其作用域,如`@ManagedBean(name="helloBean")`和`@ViewScoped`。 - 通过EL(Expression Language)在视图和bean之间传递数据,如`#{helloBean....
在JavaServer Faces (JSF)框架中,文件上传和下载是常见的功能,广泛应用于Web应用程序中,例如用户需要上传个人照片、下载文档等。本文将详细介绍如何在JSF环境中实现文件上传和下载,并提供一个可直接在Eclipse下...
**JSF(JavaServer Faces)规范详解** JSF(JavaServer Faces)是Java平台上用于构建Web应用程序的一种组件模型。它提供了丰富的用户界面组件、事件处理和数据管理功能,旨在简化开发人员的工作流程,提高Web应用的...
**JSF 2 + Spring 3 集成示例** JavaServer Faces (JSF) 是一个用于构建 Web 应用程序的 Java EE 框架,它专注于视图层的构建,而 Spring 框架则是一个全面的后端开发框架,包括依赖注入、事务管理、AOP(面向切面...