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

你说的曾经没有我的故事 提交于 2020-01-06 12:42:38

问题


Using 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. I am trying to add f:ajax to call a method when a new value is selected.

Here is what the h:selectOneMenu component in the page looks like:

<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. I have looked at this in the debugger as well and even the submittedValue for the component in the AjaxBehaviorEvent is also null. Here is the method that is called when a new value is selected and the definition for 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.


回答1:


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. 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.



来源:https://stackoverflow.com/questions/7757571/why-doesnt-my-fajax-work-with-hselectonemenu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!