MyFaces CODI和windowId请求参数问题
我一直在尝试对 Seam Weld 和 MyFaces CODI 进行一些简单的测试。将 CODI jar 文件添加到我的项目后,我发现它会为每个请求添加一个 windowId 请求值,即使 bean 范围是 RequestScoped 也是如此。当bean位于RequestScoped中时,是否真的有必要向每个请求添加windowId请求参数?这个案例有什么实际的现实场景吗?如果不需要的话可以删除吗?例如:
这是bean类的代码:
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
@Named("myBean")
@RequestScoped
public class MyBean{
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
这是页面的主体:
<body>
<h:form>
<h:inputText value="#{myBean.firstName}"></h:inputText>
<br/>
<h:inputText value="#{myBean.lastName}"></h:inputText>
<br/>
<h:commandButton value="submit"></h:commandButton>
</h:form>
</body>
I have been trying to conduct some simple tests on Seam Weld and MyFaces CODI. After adding CODI jar files to my projects, I found that it adds a windowId request value to every request even if the bean scope is RequestScoped. Is it really necessary to add windowId request parameter to every request while the bean is in RequestScoped? Is there any practical real-world scenario for this case? Is is possible to remove it if it is not necessary? For example:
This is the code of bean class:
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
@Named("myBean")
@RequestScoped
public class MyBean{
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
This is the body of the page:
<body>
<h:form>
<h:inputText value="#{myBean.firstName}"></h:inputText>
<br/>
<h:inputText value="#{myBean.lastName}"></h:inputText>
<br/>
<h:commandButton value="submit"></h:commandButton>
</h:form>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apache MyFaces CODI 添加了 windowId 以支持浏览器选项卡分隔的 bean。
如果您使用一些 CODI 范围,例如 @WindowScoped、@ViewAccessScoped、CODI @ConversationScoped,那么您将为每个浏览器选项卡获得一个单独的上下文实例。
假设您有一个客户关系管理应用程序。使用 CODI @WindowScoped,您可以在不同的浏览器选项卡/窗口中打开不同的客户。如果您使用 @SessionScoped,那么您每次都会覆盖这些值(对于 @SessionScoped beans,每个会话只有 1 个上下文实例)。
当然,您可以很容易地禁用此功能。请查看我们的官方WIKI:
https://cwiki.apache.org/confluence/display/EXTCDI/Index
Apache MyFaces CODI adds the windowId to support browser tab seperated beans.
If you use some CODI scopes like @WindowScoped, @ViewAccessScoped, CODIs @ConversationScoped, then you will get a separate contextual instance for each browser tab.
Assume you have a customer relation management app. With CODI @WindowScoped you can open different Customers in different browser tabs/windows. Would you use @SessionScoped, then you would overwrite the values each time (For @SessionScoped beans there is only 1 contextual instance for each session).
And of course you can disabled this feature pretty easily. Please check our official WIKI:
https://cwiki.apache.org/confluence/display/EXTCDI/Index
在官方wiki上找到解决方案需要一些时间。 https://cwiki.apache.org/confluence/display/EXTCDI/Index
如果你不使用@WindowScoped,@ViewAccessScoped并且确定你不需要这个windowId参数,那么你可以在你的项目中创建这样的类:
It takes some time to find solution in official wiki. https://cwiki.apache.org/confluence/display/EXTCDI/Index
If you do not use @WindowScoped, @ViewAccessScoped and sure you don't need this windowId parameter, then you can create class like this in your project: