为什么我的 f:ajax 不能与 h:selectOneMenu 一起使用?
使用 JSF 2.0、Glassfish 3.2、Primefaces 2.2.1
我有一个包含多个复合组件的页面。在这些组件之一中,我有一个 h:selectOneMenu。我正在尝试添加 f:ajax 以在选择新值时调用方法。
页面中的 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>
当我从 h:selectOneMenu 中选择一个新项目时,将调用侦听器函数,但 selectedRoom 中的值为 null。我也在调试器中查看了这一点,甚至 AjaxBehaviorEvent 中组件的 SubmittedValue 也为 null。以下是选择新值时调用的方法以及 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; }
有什么想法为什么该值没有被填充吗?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当处理表单提交时,
roomList
的SelectItem
具有null
或空字符串作为值时,就会发生这种情况。没有想到其他原因,除了String.class
的Converter
可能无法正常工作,但这应该会影响绑定到 a 的所有输入String
属性。That will happen when the
SelectItem
of theroomList
hasnull
or empty string as value at the point the form submit is been processed. No other causes comes to mind, expect of maybe aConverter
forString.class
which is not doing its job properly, but that should have affected all inputs which are bound to aString
property.