MyFaces CODI和windowId请求参数问题

发布于 2024-12-10 04:50:45 字数 1071 浏览 0 评论 0原文

我一直在尝试对 Seam WeldMyFaces 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坚持沉默 2024-12-17 04:50:45

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

‘画卷フ 2024-12-17 04:50:45

在官方wiki上找到解决方案需要一些时间。 https://cwiki.apache.org/confluence/display/EXTCDI/Index

如果你不使用@WindowScoped,@ViewAccessScoped并且确定你不需要这个windowId参数,那么你可以在你的项目中创建这样的类:

@Specializes
@ApplicationScoped
public class CustomWindowContextConfig extends WindowContextConfig {

    @Override
    public boolean isAddWindowIdToActionUrlsEnabled() {
        return false;
    }

    @Override
    public boolean isUrlParameterSupported() {
        return false;
    }
}

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:

@Specializes
@ApplicationScoped
public class CustomWindowContextConfig extends WindowContextConfig {

    @Override
    public boolean isAddWindowIdToActionUrlsEnabled() {
        return false;
    }

    @Override
    public boolean isUrlParameterSupported() {
        return false;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文