问题描述
我一直在尝试对 Seam Weld 和 MyFaces CODI 进行一些简单的测试.将CODI jar文件添加到我的项目后,我发现即使bean作用域是 RequestScoped ,它也会向每个请求添加 windowId 请求值.当Bean位于 RequestScoped 中时,是否真的有必要在每个请求中添加 windowId 请求参数?在这种情况下,是否有实际可行的方案?如果没有必要,可以将其删除吗?例如:
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:
这是bean类的代码:
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;
}
}
这是页面的正文:
<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>
推荐答案
在官方Wiki中找到解决方案需要花费一些时间. https://cwiki.apache.org/confluence/display/EXTCDI/Index
It takes some time to find solution in official wiki. https://cwiki.apache.org/confluence/display/EXTCDI/Index
如果您不使用@ WindowScoped,@ ViewAccessScoped并确保不需要此windowId参数,则可以在项目中创建类似这样的类:
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;
}
}
这篇关于MyFaces CODI和windowId请求参数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!