jsf - 为什么单独的 RequestScoped bean 没有注入到 JSF commandButton 动作调用的 bean 中?
问题描述
出于什么原因,使用相同范围的注入辅助 bean 不包含来自提交的表单数据?使用来自(JSF)commandButton 动作的参数的显式方法调用..
我已经求助于在调用 bean 中包含相同的参数,然后它就可以正常工作了。但这很烦人,因为我宁愿 A. 不要像疯了一样传递东西, B. 在几个地方重用一组特定的设置。
运行我的应用程序的环境是 Wildfly 11,以下问题发生在 Windows 机器上,但将在 Linux 上的生产环境中运行。
我的网页和相关 bean 的相关代码:
<ui:composition template="/WEB-INF/template.xhtml" ...
xmlns:h="http://xmlns.jcp.org/jsf/html">
...
<h:form>
<h:selectBooleanCheckbox id="box1" value="#{mainBean.someBoolean}"/>
<h:selectBooleanCheckbox id="box2" value="#{secondBean.someBoolean}"/>
<h:commandButton id="cmdButton" value="Btn Text" action="#{mainBean.actionMethod(sessionBean.value)}"/>
</h:form>
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
...
@Named
@RequestScoped
public class MainBean implements Serializable {
@Inject
private SecondBean secondBean;
private boolean someBoolean;
// with getter and setter
public void actionMethod(Object value) {
// In here, someBoolean and value are properly set, while secondBean.isSomeBoolean() always returns default/false regardless of the checkbox on the page.
}
...
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import java.io.Serializable;
...
@Named
@RequestScoped
public class SecondBean implements Serializable {
private boolean someBoolean;
// with getter and setter
...
为什么一个 bean 正确地填充了表单数据而不是另一个?
解决方案
推荐阅读
- jboss - 使用 JBoss 7.3 部署 GeoServer 2.17.2 时出错
- reactjs - 在进行 Jest 测试时处理内部 Promise
- html - 如何申请:关注多个相同的选择器?
- python - Maya Python .batchRender 说“文件无效”
- kubernetes - Splunk Kubernetes 示例
- reactjs - 使用 react-table 从其他外部组件获取 state.filters 数组
- ios - 启动 facebook 事件 URL 导致“Safari 无法打开页面,因为地址无效”
- javascript - python中的jQuery
- jenkins - 管道中凭证的 Jenkins Groovy 错误
- material-ui - 有没有办法混淆 material-ui 类名?