简体   繁体   English

为什么我的f:ajax无法与h:selectOneMenu一起使用?

[英]Why doesn't my f:ajax work with h:selectOneMenu?

Using JSF 2.0, Glassfish 3.2, Primefaces 2.2.1 使用JSF 2.0,Glassfish 3.2,Primefaces 2.2.1

I have a page with several composite components. 我有一个包含几个复合组件的页面。 In one of these components, I have an h:selectOneMenu. 在这些组件之一中,我有一个h:selectOneMenu。 I am trying to add f:ajax to call a method when a new value is selected. 我试图添加f:ajax以在选择新值时调用方法。

Here is what the h:selectOneMenu component in the page looks like: 这是页面中的h:selectOneMenu组件的外观:

<h:selectOneMenu id="selectRmDD" styleClass="editSelectRmDD" value="#{scheduleEditSessionBean.selectedRoom}" >
    <f:selectItems id="roomList" value="#{scheduleEditSessionBean.roomList}"/>
    <f:ajax listener="#{scheduleEditSessionBean.selectRmDD_processValueChange}" event="valueChange" render="@form" />
 </h:selectOneMenu>

When I select a new item from the h:selectOneMenu, the listener function gets called, but the value in selectedRoom is null. 当我从h:selectOneMenu中选择一个新项目时,将调用侦听器函数,但selectedRoom中的值为null。 I have looked at this in the debugger as well and even the submittedValue for the component in the AjaxBehaviorEvent is also null. 我也在调试器中进行了查看,甚至AjaxBehaviorEvent中组件的SubmittedValue也为null。 Here is the method that is called when a new value is selected and the definition for selectedRoom: 这是在选择新值和selectedRoom的定义时调用的方法:

 public void selectRmDD_processValueChange( AjaxBehaviorEvent ae) {
    String s = getSelectedRoom();
    System.out.println( "Selected room = "+s );
    if( s != null )applyRoomBtn_action();
 }

private String selectedRoom = "1";
public String getSelectedRoom() { return this.selectedRoom; }
public void setSelectedRoom(String s) { this.selectedRoom = s; }

Any ideas why the value isn't being filled? 有什么想法为什么价值没有被填补?

Thanks. 谢谢。

That will happen when the SelectItem of the roomList has null or empty string as value at the point the form submit is been processed. roomListSelectItem在处理表单提交时将null或空字符串作为值时,将发生这种情况。 No other causes comes to mind, expect of maybe a Converter for String.class which is not doing its job properly, but that should have affected all inputs which are bound to a String property. 没有其他原因出现,可能是因为String.classConverter不能正常工作,但是应该影响到所有绑定到String属性的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM