[英]Value set by h:selectOneMenu is null in f:ajax listener method
I'm trying to use AJAX in my JSF 2.0 web application and have a problem with getting current value from selectOneMenu. 我试图在我的JSF 2.0 Web应用程序中使用AJAX,但是从selectOneMenu获取当前值时遇到问题。
Part of my JSF page. 我的JSF页面的一部分。
<h:panelGrid columns="2">
<h:outputLabel value="Appendix number" for="appendix" />
<h:selectOneMenu id="appendix" value="#{indexMBean.appendix}">
<f:selectItem itemLabel="Point 1" itemValue="1" />
<f:selectItem itemLabel="Point 2" itemValue="2" />
<f:ajax event="change" listener="#{indexMBean.setHazardsByAppendix}" />
</h:selectOneMenu>
</h:panelGrid>
setHazardsByAppendix is a procedure in indexMBean. setHazardsByAppendix是indexMBean中的一个过程。 Then the procedure fires I try to get the current value of h:selectOneMenu for passing it on another procedure. 然后触发该过程,我尝试获取h:selectOneMenu的当前值以将其传递给另一个过程。
public void setHazardsByAppendix() {
Logger logger = Logger.getAnonymousLogger();
logger.warning(this.appendix);
this.setHazards(this.hazardSessionBean.getHazardByAppendix(this.appendix));
}
But the current value of field appendix is always null. 但是字段附录的当前值始终为空。 How is this caused and how can I solve it? 这是怎么引起的,我该如何解决?
Solved in a very strange way. 以一种非常奇怪的方式解决了。 I created a new netbeans project with the same sources. 我用相同的资源创建了一个新的netbeans项目。 And amazingly it works fine. 令人惊讶的是,它工作正常。 It's a really strange but it works. 这真的很奇怪,但是可以。
`<f:ajax execute="@this" listener="#{templateSearchHandler.OnDefNameSelect}">
void setHazardsByAppendix(AjaxBehaviorEvent event) {
Logger logger = Logger.getAnonymousLogger();
logger.warning(this.appendix);
this.setHazards(this.hazardSessionBean.getHazardByAppendix(this.appendix));
}`
This code calls AjaxBehaviour event and pass value to controller through Ajax. 该代码调用AjaxBehaviour事件,并通过Ajax将值传递给控制器。
<h:panelGrid columns="2">
<h:outputLabel value="Appendix number" for="appendix" />
<h:selectOneMenu id="appendix" value="#{indexMBean.appendix}">
<f:selectItem itemLabel="Point 1" itemValue="1" />
<f:selectItem itemLabel="Point 2" itemValue="2" />
<f:ajax execute="@this"listener="#{indexMBean.setHazardsByAppendix}" />
</h:selectOneMenu>
</h:panelGrid>
//Controller
public void setHazardsByAppendix(AjaxBehaviorEvent event) {
Logger logger = Logger.getAnonymousLogger();
logger.warning(this.appendix);
this.setHazards(this.hazardSessionBean.getHazardByAppendix(this.appendix));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.