Primefaces Components and the @ConversationScoped Beans
来源:互联网 发布:css 实战手册 知乎 编辑:程序博客网 时间:2024/06/18 07:34
http://forum.primefaces.org/viewtopic.php?f=3&t=23679
关于 jsf2.2的一个问题。
I build a short page with JSF-Compnents which displays and increments a value from a @ConversationScoped Bean. This page is able to end the Conversation and is getting a new Bean after ending the old Conversation. Here is what it looks like:
Code: Select all
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head />
<h:body>
<h:form>
<h:outputText id="i" value="#{test.i}" />
<h:commandButton value="increment" actionListener="#{test.increment}" update="i cid" />
<h:outputText id="cid" value="#{javax.enterprise.context.conversation.id}" />
<h:commandButton value="end" actionListener="#{test.endConversation}" update="i cid" />
</h:form>
</h:body>
</html>
The code for the Bean is quite simple:
Code: Select all
package de.burghard.britzke.test.beans;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;
@Named
@ConversationScoped
public class Test implements Serializable {
@Inject Conversation conversation;
private int i;
@PostConstruct
public void init() { conversation.begin();
System.out.println("init conversation"+conversation.getId());
}
public int getI() { return i; }
public void setI(int i) { this.i = i; }
public void increment() { i++;System.out.println(i); }
public void endConversation() {
System.out.println("ending conversation "+conversation.getId());
conversation.end();
}
}
Everything works well, when using the standard <h:commandButton> Components. But using the Primefaces Components <p:commandButton> then every click on the 'increment' Button grabs a new Bean instance because the cid-Parameter is not passed to the Server. It has been stated that this is not a primefaces issue. But why is it working with the standard components and not with the primefaces ones?
I have been able to pass the cid-Parameter by explicitely embedding a <f:param> component into the commandButton Components but after destroying the Conversation the parameter is sent with no value producing an error.
Is there a short tutorial how to work with Primefaces and Conversation scoped beans (without explicitely passing the cid-Parameter)?
The problem with the <f:param> in case of ended conversation has been that the param should not be passed with invalid values (null) for the parameter 'cid'. Changing the Parameter name to a different one if no conversation is present is a workaround:
Code: Select all
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head />
<h:body>
<h:form id="form">
<h:outputText value="#{test.i}" />
<p:commandButton value="increment"
actionListener="#{test.increment}"
update="@parent">
<f:param
name="#{not empty javax.enterprise.context.conversation.id?'cid':''}"
value="#{javax.enterprise.context.conversation.id}" />
</p:commandButton>
<h:outputText
value="#{javax.enterprise.context.conversation.id}" />
<p:commandButton value="end" actionListener="#{test.endConversation}"
update="@parent">
<f:param name="cid" value="#{javax.enterprise.context.conversation.id}" />
</p:commandButton>
</h:form>
</h:body>
</html>
Unfortunally the <f:param> tag is not supported within <p:ajax> components. This leads to a new conversation for every ajax request. Thus @ConversationScoped beans are not possible with ajax-enabled Primefaces applications today - right?
0 0
- Primefaces Components and the @ConversationScoped Beans
- Integrating Smarty and ez Components with the Zend Framework
- Testing Commercial-off-the-Shelf Components and Systems
- Qes_20170801_Two components with the same name and precedence
- Introduction to the Spring IoC container and beans
- primefaces
- PrimeFaces
- Components and Props
- MySQL Architecture and Components
- Presentational and Container Components
- Spilling the Spanish Beans
- The Building Blocks-Components of EA part 1- Information and Strategy
- The Building Blocks- Components of EA Part 2- Process, People, Network and Time
- BOM API - uses the BOM_BO_PUB.PROCESS_BOM API to create bill header and add components to the bill
- Joomla components and execution path
- Big Data Ecosystem and Components
- ReactNative基础---Components and Props
- sentry简介--architecture and Components
- UIButton 设置 imageView frame
- 错误: 在类 com.zs.container.CollectionData 中找不到主方法, 请将主方法定义为: public static void main(String[] args)
- 数据挖掘十大算法之一C4.5(详细版终结版)
- 算法导论:快速找出无序数组中第k小的数
- 随感——2015年3月小结
- Primefaces Components and the @ConversationScoped Beans
- android实用代码片段(二)
- IOS越狱开发好demo
- GITBash 使用 给新手的一些经验
- java同步中wait 与 notify
- ZOJ 3329 — One Person Game
- hdu2082 找单词 母函数+完全背包两种算法AC。。数据较水
- Android中shape的使用
- Linux 连续执行多条命令的方法